Patashu / break_eternity.js

A Javascript numerical library to represent numbers as large as 10^^1e308 and as small as 10^-10^^1e308. Sequel to break_infinity.js, designed for incremental games.
MIT License
120 stars 43 forks source link

Max Value constant #170

Closed JamesCarlyleClarke closed 1 month ago

JamesCarlyleClarke commented 1 month ago

The library would benefit from a max value constant. Is there any reason not to use Number.MAX_VALUE for the layer and mag?

// Define a high value using MAX_VALUE (possible issues?)
Decimal.dMaxValue = FC(1, Number.MAX_VALUE, Number.MAX_VALUE);

// or

// Define a safe high value using MAX_SAFE_INTEGER
Decimal.dMaxSafeValue = FC(1, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
MathCookie17 commented 1 month ago

For maxValue, I don't see much reason to make the mag be something other than 1, since at that point the magnitude is meaningless anyway. As for maxSafeValue, since the transition point for layers is at a magnitude of 9e15, I'd make the magnitude there (9e15 - 1) rather than MAX_SAFE_INTEGER (which is slightly larger than 9e15).

I'll consider these for the next update.

JamesCarlyleClarke commented 1 month ago

Ah, interesting, I hadn't known about the 9e15 in the code, got it. Surely, since the relevant code is 'While abs(mag) > EXP_LIMIT (9e15)' then for the absolute maximum, it could be 9e15 not 9e15-1? Or did I miss a >= somewhere? Decimal.dMaxSafeValue = FC(1, Number.MAX_SAFE_INTEGER, 9e15);

For maxValue, are you saying it's meaningless in a metaphorical way (ie the number is so big that it's not worth worrying about the extra), or that it is meaningless because it is ignored in the code when the layer is that high, because the numbers are too big to calculate correctly and would overflow?

MathCookie17 commented 1 month ago

image

That's the >= you're looking for (it's in normalize).

As for maxValue, I guess it's a mix of both. Beyond 2^53 layers, the layer can no longer be incremented by 1, and since the mag's whole range is a single layer, the mag is effectively worthless.

JamesCarlyleClarke commented 1 month ago

Ah OK. Thanks for explaining, that's great! Still, for the absolute absolute maximum, if you simply had to have the highest valid number, does that mean it would be:

Decimal.dMaxValue = FC(1, Number.MAX_VALUE, Number.MAX_VALUE);
or
Decimal.dMaxValue = FC(1, Number.MAX_VALUE, 9e15-1);
or
Decimal.dMaxValue = FC(1, 2 ** 53, Number.MAX_VALUE);
or
Decimal.dMaxValue = FC(1, 2 ** 53, 9e15-1);

?

MathCookie17 commented 1 month ago

Decimal.dMaxValue would be FC(1, Number.MAX_VALUE, 9e15-1), and Decimal.dMaxSafeValue would be FC(1, 2 ** 53 - 1, 9e15-1).

JamesCarlyleClarke commented 1 month ago

Wonderful, that's extremely helpful, many thanks! (and while I'm chatting, thanks for the Eternal Notations library, just getting into that!)

MathCookie17 commented 1 month ago

These constants (Decimal.dLayerMax is the true maximum value, Decimal.dLayerSafeMax is the safe version) have been added in v2.1.0.

JamesCarlyleClarke commented 1 month ago

Many thanks, you're awesome!