Hacker News new | ask | show | jobs
by mamcx 3079 days ago
And another dumb questions:

Is possible to convert to rationals in calculations?

So if I do:

1/3 + 4 + sum / total it record values properly?

1 comments

Yes. Common Lisp is an example of a language that can represent rationals exactly and do arithmetic on them. You can avoid floating-point precision loss by using this method. But there are drawbacks: 1) The numerator and denominator will often turn into bignums as a calculation progresses, consuming ever-larger amounts of space and time, and 2) This won't help you with any calculation involving irrationals, except to prevent your initial imprecision from growing larger.