The Math Object : Math « Development « Ruby






The Math Object


puts(Math::PI)
puts(Math::E)
puts(Math.cos(Math::PI/3))
puts(Math.tan(Math::PI/4))
puts(Math.log(Math::E**2))
puts((1 + Math.sqrt(5))/2)

# 3.14159265358979
# 2.71828182845905
# 0.5
# 1.0
# 2.0
# 1.61803398874989

 








Related examples in the same category

1.Math functions from the Math module
2.The Math.exp function returns Euler to the power of x.
3.Call to the class method sqrt from the Math module
4.do natural logarithms (base E or Euler) and base-10 logarithms.
5.Taking Logarithms
6.Random number
7.Random seeds
8.Convert the Cartesian point (x,y) to polar (magnitude, angle) coordinates
9.Convert polar coordinates to Cartesian coordinates