Chapter 5. Performing Numerical Calculations
Numeric data is the original data type, the native language of the computer. We would be hard-pressed to find areas of our experience where numbers are not applicable. It doesn't matter whether you're an accountant or an aeronautical engineer; you can't survive without numbers. We present in this chapter a few ways to process, manipulate, convert, and analyze numeric data. Like all modern languages, Ruby works well with both integers and floating point numbers. It has the full range of standard mathematical operators and functions that you would expect, but it also has a few pleasant surprises such as the Bignum, BigDecimal, and Rational classes. Besides covering all of the numeric features in the core and standard libraries, a little domain-specific material has been added (in such areas as trigonometry, calculus, and statistics). These examples serve not only as informative examples in math, but as examples of Ruby code that illustrates principles from the rest of this book. |