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 Comment A ankita_saini Follow Improve A ankita_saini Follow Improve Article Tags : Ruby Ruby-Built-in-Modules Explore Ruby Programming Language 4 min read OverviewRuby For Beginners 3 min read Ruby Programming Language (Introduction) 4 min read Comparison of Java with Other Programming Languages 4 min read Similarities and Differences between Ruby and C language 3 min read Similarities and Differences between Ruby and C++ 3 min read Environment Setup in Ruby 3 min read How to install Ruby on Linux? 2 min read How to install Ruby on Windows? 2 min read Interesting facts about Ruby Programming Language 2 min read BasicsRuby | Keywords 4 min read Ruby | Data Types 3 min read Ruby Basic Syntax 3 min read Hello World in Ruby 2 min read Ruby | Types of Variables 4 min read Global Variable in Ruby 2 min read Comments in Ruby 2 min read Ruby | Ranges 4 min read Ruby Literals 4 min read Ruby Directories 5 min read Ruby | Operators 11 min read Operator Precedence in Ruby 2 min read Operator Overloading in Ruby 5 min read Ruby | Pre-define Variables & Constants 5 min read Ruby | unless Statement and unless Modifier 2 min read Control StatementsRuby | Decision Making (if, if-else, if-else-if, ternary) | Set - 1 3 min read Ruby | Loops (for, while, do..while, until) 5 min read Ruby | Case Statement 3 min read Ruby | Control Flow Alteration 7 min read Ruby Break and Next Statement 2 min read Ruby redo and retry Statement 2 min read BEGIN and END Blocks In Ruby 2 min read File Handling in Ruby 4 min read MethodsRuby | Methods 3 min read Method Visibility in Ruby 3 min read Recursion in Ruby 4 min read Ruby Hook Methods 5 min read Ruby | Range Class Methods 5 min read The Initialize Method in Ruby 2 min read Ruby | Method overriding 2 min read Ruby Date and Time 3 min read OOP ConceptsObject-Oriented Programming in Ruby | Set 1 9 min read Object Oriented Programming in Ruby | Set-2 8 min read Ruby | Class & Object 4 min read Private Classes in Ruby 3 min read Freezing Objects | Ruby 2 min read Ruby | Inheritance 4 min read Polymorphism in Ruby 3 min read Ruby | Constructors 2 min read Ruby | Access Control 8 min read Ruby | Encapsulation 2 min read Ruby Mixins 3 min read Instance Variables in Ruby 3 min read Data Abstraction in Ruby 3 min read Ruby Static Members 3 min read ExceptionsRuby | Exceptions 4 min read Ruby | Exception handling 6 min read Catch and Throw Exception In Ruby 3 min read Raising Exceptions in Ruby 4 min read Ruby | Exception Handling in Threads | Set - 1 2 min read Ruby | Exception Class and its Methods 3 min read Ruby RegexRuby | Regular Expressions 3 min read Ruby Search and Replace 2 min read Ruby ClassesRuby | Float Class 7 min read Ruby | Integer Class 3 min read Ruby | Symbol Class 5 min read Ruby | Struct Class 5 min read Ruby | Dir Class and its methods 3 min read Ruby | MatchData Class 4 min read Ruby ModuleRuby | Module 4 min read Ruby | Comparable Module 3 min read Ruby | Math Module 4 min read Include v/s Extend in Ruby 2 min read Like