On 5/10/26 4:06 PM, Rob Meijer wrote:
>
> On Sun, May 10, 2026 at 6:13 PM Chris Hibbert <
hib...@mydruthers.com wrote:
>
> On 5/9/26 5:29 AM, Douglas Crockford wrote:
> > The problem is with the int class of types. Overflow is inevitable,
> > signed or unsigned, and the consequences can be devastating. The
> > solution is to eliminate int in all of its forms. Instead, have a
> single
> > floating point type that has excellemt performance on integers.
> You get
> > the performance and eliminate the danger. That is what DEC64 does.
>
> My problem with going straight to floats is that you end up having to
> carry around 5.0001, and decide whether to tell the user it might as
> well have been 5. And similarly, dividing by 3 and then
> multiplying by
> 3 loses precision.
>
> By choosing floats you gain range by giving up on exact results. I think
> it should be a last resort when either you run out of bits and have no
> other option, or when you need fundamantaly limited fidelity
> representations of irrationals that bind any results to a non-perfect
> accuracy level.
> And once that happens, I believe that you end up with a split. Once you
> go float, mixing types converges to the lowest fidelity. As long as you
> can avoid it, muxing types converges to bigger and bigger representation
> types.
Yeah, I mostly think it's a mistake in javascript to only offer floats
natively. At Agoric we used Amounts, which pair a BigInt with a unit to
represent financial values. This works well in cryptocurrencies.
> I built a ratio package when I was at Agoric so that we could multiply
> and divide financial numbers and manage the rounding. (If you worry
> about sensitivity analysis, it often makes sense to put off the
> divisions as long as possible.) The other thing we did was attach units
> to all ratios so you could tell when you accidentally multiplied when
> you should have divided or used the wrong exchange rate.
>
>
> Puting of division as long as possible is I think done most natural by
> having rational types. But these come with their own specific
> considerations. You can limit overflow issues with narrow rationals by
> doing canonical divisions early, but these are not a computational free
> ride.
> In my own pet project I am currently choosing to not do any intermediate
> canonical divisions in my rational expressions, not because it isn't a
> good idea, but because it's not high priority for now.
>
> Did you delay all divisions, or just non-canonical divisions? And what
> considerations led to that choice?
I'm not sure what you mean by "canonical" divisions. Could you say more?
We put it off as long as possible by carrying the ratios for most
intermediate representations. You don't even have to reduce the
representation when comparing values - it's only when a value has to be
stored or displayed that you have to reduce it to decimal.
We were doing financial calculations with multiple currencies. We needed
to multiply our Amounts (unlimited precision integer, plus a Unit) by
interest rates, percentage fees, and currency conversions. We found that
it was a hassle to write generic code that was agnostic about the
particular currency, and to write code that made it apparent that we
were keeping the units straight.
When working with numbers that could be very large and very small, we
had to be clear about the order of operations (AKA sensitivity
analysis). When we switched to ratios, the analysis got simpler and we
had fewer issues with surprising outcomes.
https://github.com/Agoric/agoric-sdk/blob/master/packages/ERTP/src/ratio.js
One thing it took me a little while to figure out was that it was
expensive to store ratios that were the result of continuing
calculations. The ratios used bigInts, and the numerator and denominator
would grow over time. We had to identify places where we were
accumulating values over time, and reduce the fraction regularly, or the
storage and computation costs grew over time.
> I thought it worked pretty well.
>
> Chris
> --
Chris
--
Change is not linear. Our expectations are linear, but new
technologies come in "S" curves, so we routinely overestimate
short-term change and underestimate long-term change.
--Paul Saffo