Hacker News new | ask | show | jobs
by lokedhs 1467 days ago
Common Lisp does by default. Calling (/ 1 3) gives 1/3 which is a rational. The individual components of a rational number are bignums, so the size of the fraction is only limited to available RAM.

However, this is not enough in many cases. For example, how would you store pi? In the case of Lisp, pi is stored as a floating point number, and the conversion rules say that a mathematical operation between a rational and a floating point number yields a floating point number. This means that even though you have rational numbers, you still have to be aware of floating point.

3 comments

You could store pi as a symbol.

Of course, ultimately this is going to be a compromise and I understand the choice of not storing common constants that way. In the end you'd end up just replicating common mathematical notation and computing with that is not going to be fast.

As soon as you want to do something with π, you have no choice but an approximation, so floating-point is completely appropriate.

  how would you store pi?
same way we do now I guess? Approximate it. My vote is on 22 / 7
That’a a terrible approximation. Also requires memorising about the same amount of information as just memorising the digits.