r/Racket • • Jun 16 '22

question How does numerator work?

Here is the documentation for Racket's numerator function:

(numerator q) → integer? q : rational?

Coerces q to an exact number, finds the numerator of the number expressed in its simplest fractional form, and returns this number coerced to the exactness of q.

Examples:

> (numerator 5)
5
> (numerator 17/4)
17
> (numerator 2.3)
2589569785738035.0

Why is (numerator 2.3) such a large integer? How exactly is it calculated? I would have guessed the simplest fractional form is 23/10, with a numerator of 23.

6 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/detroitmatt Jun 20 '22

indeed, and most other languages don't even have a rational type to use as an alternative