# Day6 : Ruby - Math Function

## Math functions

The ** Math** module contains module “methods/functions” for basic trigonometric and transcendental functions. See class

**for a list of constants that define Ruby’s floating point accuracy.**

*float*In Ruby, we invoke built-in ** Math** functions, such as -

**returns a square root. The**

*sqrt***,**

*sin***and**

*cos***methods relate parts of a triangle. There are two constants:**

*tan***and**

*PI***.**

*E***sqrt(x)**

Returns the non-negative square root of x.

**cbrt(x)**

Returns the cube root of x.

**log10(x)**

Returns the base 10 logarithm of x.

**log(x, base)**

Returns the logarithm of x. If additional second argument is given, it will be the base of logarithm. Otherwise it is e (for the natural logarithm).

**Example:**

```
Path => /koresol.com-math_function.rb
```

```
print "Square root of number : "
puts Math.sqrt(64)
print "Cube root of number : "
puts Math.cbrt(8)
print "Logarithm value of number : "
puts Math.log(1)
print "Logarithm value to the base 10 : "
puts Math.log10(10)
print "Give value of PI Constant : "
puts Math::PI
print "Give value of E Constant : "
puts Math::E
print "Trigonometric functions: "
puts Math::sin(0)
puts Math::cos(0)
puts Math::tan(0)
```

**Output :** Type following command on command prompt and view output

```
$ ruby koresol.com-math_function.rb
Square root of number: 8.0
Cube root of number: 2.0
Logarithm value of number: 0.0
Logarithm value to the base 10: 1.0
Give value of PI Constant: 3.141592653589793
Give value of E Constant: 2.718281828459045
Trigonometric functions: 0.0
1.0
0.0
```

# Day6 : Ruby - Math Function

## Math functions

The ** Math** module contains module “methods/functions” for basic trigonometric and transcendental functions. See class

**for a list of constants that define Ruby’s floating point accuracy.**

*float*In Ruby, we invoke built-in ** Math** functions, such as -

**returns a square root. The**

*sqrt***,**

*sin***and**

*cos***methods relate parts of a triangle. There are two constants:**

*tan***and**

*PI***.**

*E***sqrt(x)**

Returns the non-negative square root of x.

**cbrt(x)**

Returns the cube root of x.

**log10(x)**

Returns the base 10 logarithm of x.

**log(x, base)**

Returns the logarithm of x. If additional second argument is given, it will be the base of logarithm. Otherwise it is e (for the natural logarithm).

**Example:**

```
Path => /koresol.com-math_function.rb
```

```
print "Square root of number : "
puts Math.sqrt(64)
print "Cube root of number : "
puts Math.cbrt(8)
print "Logarithm value of number : "
puts Math.log(1)
print "Logarithm value to the base 10 : "
puts Math.log10(10)
print "Give value of PI Constant : "
puts Math::PI
print "Give value of E Constant : "
puts Math::E
print "Trigonometric functions: "
puts Math::sin(0)
puts Math::cos(0)
puts Math::tan(0)
```

**Output :** Type following command on command prompt and view output

```
$ ruby koresol.com-math_function.rb
Square root of number: 8.0
Cube root of number: 2.0
Logarithm value of number: 0.0
Logarithm value to the base 10: 1.0
Give value of PI Constant: 3.141592653589793
Give value of E Constant: 2.718281828459045
Trigonometric functions: 0.0
1.0
0.0
```