Ruby | Math Module Last Updated : 13 Sep, 2022 Comments Improve Suggest changes Like Article Like Report In Ruby, Modules are defined as a collection of methods, classes, and constants together. Math module consists of the module methods for basic trigonometric and transcendental functions. Module ConstantsNameDescriptionEDefine the value of base of natural logarithm e.PIDefine the value of π. Example: Ruby # Ruby code to illustrate the # Math Module constants puts Math::E puts Math::PI Output: 2.718281828459045 3.141592653589793Module Methodsacos : This method calculate the arc cosine of given value a. It return in the range[0..PI]. The return type of this method is float.Math.acos(a)Example: Ruby # Ruby code to illustrate the # acos method puts Math.acos(0) # checking its range puts Math.acos(0) == Math::PI/2 Output:1.5707963267948966 trueacosh : This method calculate the inverse hyperbolic cosine of given value a. The return type of this method is float.Math.acosh(a)asin : This method calculate the arc sine of given value a. It return in the range[-PI/2..PI/2]. The return type of this method is float.Math.asin(a)asinh : This method calculate the inverse hyperbolic sine of given value a. The return type of this method is float.Math.asinh(a)Example: Ruby # Ruby code to illustrate the # asinh method puts Math.asinh(2) Output:1.4436354751788103atan : This method calculate the arc of tangent of given of given value a. It returns in the range[-PI..PI]. The return type of this method is the float.Math.atan(a)atanh : This method calculate the inverse hyperbolic tangent of given value a. The return type of this method is float.Math.atanh(a)Example: Ruby # Ruby code to illustrate the # atanh method puts Math.atanh(0.5) Output:0.5493061443340548atan2 : This method calculate the arc of tangent of given value a and b. It returns in the range[-PI..PI]. The return type of this method is float.Math.atan2(a, b)cos : This method calculate the cosine of given value a, expressed in radians and return in the range[-1.0..1.0]. The return type of this method is float.Math.cos(a)Example: Ruby # Ruby code to illustrate the # cos method puts Math.cos(1) Output:0.5403023058681398cosh : This method calculate the hyperbolic cosine of given value a and expressed in radians. The return type of this method is float.Math.cosh(a)erf : This method returns the error function of given value a. The return type of this method is float.Math.erf(a)erfc : This method returns the complementary error function of given value a. The return type of this method is float.Math.erfc(a)exp : This method returns the value of ea. The return type of this method is float.Math.exp(a)Example: Ruby # Ruby code to illustrate the # exp method puts Math.exp(2) Output:7.38905609893065frexp : This method returns a two-element array that consisting the normalized fraction and exponent of numeric.Math.frexp(numeric)hypot :This method returns √a2+b2. Or in other words it returns the hypotenuse of right-angle triangle with sides a and b. The return type of this method is float.Math.hypot(a, b)Example: Ruby # Ruby code to illustrate the # hypot method puts Math.hypot(4,5) Output: 6.4031242374328485Idexp : This method returns the value of float * 2 integer. The return type of this method is float.Math.Idexp(float, integer)log : This method returns the natural logarithm of numeric. The return type of this method is float.Math.log(numeric)log10 : This method return the base 10 of the logarithm of numeric. The return type of this method is float.Math.log10(numeric)sin : This method calculate the sine of numeric and expressed in radians. It return in the range[-1.0..1.0 ]. The return type of this method is float.Math.sin(numeric)Example: Ruby # Ruby code to illustrate the # sin method puts Math.sin(0) Output:0.0sinh : This method calculate the hyperbolic sine of numeric and expressed in radians. The return type of this method is float.Math.sinh(numeric)sqrt : This method return the non-negative square root of numeric and raise ArgError if numeric is less than zero. The return type of this method is float.Math.sqrt(numeric)tan : This method return the tangent of numeric and expressed in radians. The return type of this method is float.Math.tan(numeric)tanh : This method calculate the hyperbolic tangent of numeric and expressed in radians. The return type of this method is float.Math.tanh(numeric)Example: Ruby # Ruby code to illustrate the # tanh method puts Math.tanh(1) Output:0.7615941559557649 Reference: https://ruby-doc.org/core-2.2.0/Math.html Create Quiz Comment A ankita_saini Follow 0 Improve A ankita_saini Follow 0 Improve Article Tags : Ruby Ruby-Built-in-Modules Explore OverviewRuby For Beginners3 min readRuby Programming Language (Introduction)4 min readComparison of Java with Other Programming Languages4 min readSimilarities and Differences between Ruby and C language3 min readSimilarities and Differences between Ruby and C++3 min readEnvironment Setup in Ruby3 min readHow to install Ruby on Linux?2 min readHow to install Ruby on Windows?2 min readInteresting facts about Ruby Programming Language2 min readBasicsRuby | Keywords4 min readRuby | Data Types3 min readRuby Basic Syntax3 min readHello World in Ruby2 min readRuby | Types of Variables4 min readGlobal Variable in Ruby2 min readComments in Ruby2 min readRuby | Ranges4 min readRuby Literals4 min readRuby Directories5 min readRuby | Operators11 min readOperator Precedence in Ruby2 min readOperator Overloading in Ruby5 min readRuby | Pre-define Variables & Constants5 min readRuby | unless Statement and unless Modifier2 min readControl StatementsRuby | Decision Making (if, if-else, if-else-if, ternary) | Set - 13 min readRuby | Loops (for, while, do..while, until)5 min readRuby | Case Statement3 min readRuby | Control Flow Alteration7 min readRuby Break and Next Statement2 min readRuby redo and retry Statement2 min readBEGIN and END Blocks In Ruby2 min readFile Handling in Ruby4 min readMethodsRuby | Methods3 min readMethod Visibility in Ruby3 min readRecursion in Ruby4 min readRuby Hook Methods5 min readRuby | Range Class Methods5 min readThe Initialize Method in Ruby2 min readRuby | Method overriding2 min readRuby Date and Time3 min readOOP ConceptsObject-Oriented Programming in Ruby | Set 19 min readObject Oriented Programming in Ruby | Set-28 min readRuby | Class & Object4 min readPrivate Classes in Ruby3 min readFreezing Objects | Ruby2 min readRuby | Inheritance4 min readPolymorphism in Ruby3 min readRuby | Constructors2 min readRuby | Access Control8 min readRuby | Encapsulation2 min readRuby Mixins3 min readInstance Variables in Ruby3 min readData Abstraction in Ruby3 min readRuby Static Members3 min readExceptionsRuby | Exceptions4 min readRuby | Exception handling6 min readCatch and Throw Exception In Ruby3 min readRaising Exceptions in Ruby4 min readRuby | Exception Handling in Threads | Set - 12 min readRuby | Exception Class and its Methods3 min readRuby RegexRuby | Regular Expressions3 min readRuby Search and Replace2 min readRuby ClassesRuby | Float Class7 min readRuby | Integer Class3 min readRuby | Symbol Class5 min readRuby | Struct Class5 min readRuby | Dir Class and its methods3 min readRuby | MatchData Class4 min readRuby ModuleRuby | Module4 min readRuby | Comparable Module3 min readRuby | Math Module4 min readInclude v/s Extend in Ruby2 min readCollectionsRuby | Arrays4 min readRuby | String Basics5 min readRuby | String Interpolation3 min readRuby | Hashes Basics4 min readRuby | Hash Class12 min readRuby | Blocks6 min read Like