Math
The Numeric class and its subclasses handle a lot of the basic arithmetic in Ruby. (For more see Numbers.) But sometimes you need to do more advanced math. The Math module provides a couple dozen math functions, largely trigonometry, but it also handles other branches of advanced math. The BigMath model recreates a subset of those methods for BigDecimal arguments and values.
All of these methods are module methods, so they are all called with module syntax, as in Math.cos(value).
The Math module contains multitudes, especially if you like trigonometry. Specifically, it contains:
-
The constant values Math::Pi and Math::E.
-
Math.sqrt(x) and Math.cbrt(x), which return the square and cube roots of the argument, respectively.
-
Logarithm functions, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access