Converting Between Degrees and Radians : Utility Method « Method « Ruby






Converting Between Degrees and Radians



class Numeric
  def degrees
    self * Math::PI / 180
  end
end

puts 90.degrees
puts Math::tan(45.degrees)                             # => 1.0
puts Math::cos(90.degrees)                             # => 6.12303176911189e-17
puts Math::sin(90.degrees)                             # => 1.0
puts Math::sin(89.9.degrees)                           # => 0.999998476913288

puts Math::sin(45.degrees)                             # => 0.707106781186547
puts Math::cos(45.degrees)                             # => 0.707106781186548

 








Related examples in the same category

1.Taking Mean
2.Track Median
3.Track Mode
4.mean without float conversion
5.mean and standard deviation