7.5. Rational Numbers

A rational number is defined as a fraction (a/b) where a and b are both integers. In contrast, an irrational number cannot be defined that way. The classic example of an irrational number is the square root of two. Technically, a binary computer can only represent a subset of the rational numbers. But for some purposes, it is handy to actually model them as (numerator, denominator) pairs. For example, Vadim Tropashko uses rational numbers in the nested interval model for hierarchies in SQL (see Joe Celko’s Trees and Hierarchies in SQL for Smarties). This means that you need a set of user-defined functions to do basic four-function math and to reduce the fractions.

Elementary school students, when questioned what the sum ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.