5.12. Using mathn
For math-intensive programs, you will want to know about the excellent mathn library created by Keiju Ishitsuka. It provides a few convenience methods and classes, and in general helps to unify all of Ruby’s numeric classes so that they “play well” together.
The easiest way to “use” this library is simply to require it and forget it. Because it requires the complex, rational, and matrix libraries (in that order), there is no need to do separate requires of those if you are using them.
In general, the mathn library tries to produce “sensible” results from computations—for example, the square root of a Rational will be returned when possible as another Rational rather than a Float. Table 5.1 shows some typical effects of loading ...
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