problem-solving icon indicating copy to clipboard operation
problem-solving copied to clipboard

Rats from calculations and from Rat.new have different limits

Open doomvox opened this issue 1 year ago • 3 comments

At present, Rats created from calculations are limited to 1 / (2⁶⁴ - 1), and yet a Rat created via Rat.new can exceed that precision. This oddity seems very peculiar, and I suggest that we consider adding bounds checking to Rat.new so that both approaches have an identical limit.

The current behavior is documented, but the rationale for it isn't: my presumption is that it's intended to improve efficiency by avoiding doing a check that will be redundant in many cases.

The difficulty here is that it makes the definition of a Rat a little fuzzy, which makes it difficult to talk about it clearly: this issue is addressed in a few places in the "language/numerics" page, but it requires a code example to make the behavior clear:

https://docs.raku.org/language/numerics

If you don't see what I mean, try describing what a Rat is informally, perhaps speaking out loud. "Though actually, you can have Rats fatter than normal Rats but which are not FatRats..."

(Thanks to Rob Ramsbottom for calling this to our attention at the SF Perl Raku Study Group.)

doomvox avatar Nov 28 '24 08:11 doomvox