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.
ssqrt now uses linear_sroot rather than the other way around
Added a linear hyper4 parameter to fromString
Static versions of layeradd and slog now use DecimalSource for base instead of number, like their non-static versions. Also, added static trig functions
Added JSDocs documentation for most functions
Explanations:
I noticed that when calling, say, iteratedexp with a height of Infinity, it would return {1, Infinity, 1} rather than {1, Infinity, Infinity} (the latter being how break_eternity actually represents +Infinity). {1, Infinity, 1} is not a valid infinity representation because functions like gt, gte, lt, lte, and so on consider {1, Infinity, 1} to be less than layer >=2 numbers. To fix this, I added handling for infinities (and NaNs) to normalize, so now all infinities have both mag and layer of infinity, and all NaNs are totally NaN. Still no handling for non-integer layers though.
lambertw is poorly implemented, it seems - given #152, I don't trust it. More pressingly, ssqrt(1) was returning NaN. Values near 1 were fine, but ssqrt(1) specifically was NaN. I don't know how to fix lambertw because I don't understand lambertw, but I know how super-roots work, so I'm making ssqrt just use linear_sroot instead, since linear_sroot's process has no problems with 1. I'm not sure if there are any other problematic values, but having ssqrt fail on 1, of all numbers, is ridiculous - and since I'm not sure if there are other problematic values, I'd rather not just add a special case for 1 and hope that's enough. (I did add a unit test to check that this change in ssqrt isn't a problem, and it looks like linear_sroot and the lambert-w solution agree as long as both return a valid answer)
Now that all the hyper-4 functions have a parameter to force the linear approximation, I realized that fromString should also have such a parameter, so if you enter "10^^8.5" and you're using the linear approximation everywhere else, you have the option to have that string evaluate to the linear 10^^8.5 instead of the analytic 10^^8.5. Like the rest of the linear hyper-4 parameters, this is false by default, so the default behavior of toString is unchanged but there's an option for those (like myself) who prefer to avoid the inconsistency of having analytic approximation for only bases <= 10 and just stick to the linear approximation.
I think it was a little weird that the static versions of layeradd and slog only allowed number bases but the non-static versions allowed Decimal bases, so I fixed the static versions. Also, the trig functions didn't have static versions before, so I added those.
Yes, adding JSDocs to the functions adds a lot of lines of code, but I think it'll make the library easier to use - especially since index.d.ts is now a more comprehensive list of functions and what they do. There were a few functions that I didn't add documentation to since I'm not sure what they do (like toExponential and toPrecision), but I'll add documentation to those too if you tell me what they do.
I'm not sure if any of these changes break anything (especially normalization of infinities - for all I know, that might break something that I'm unaware of), so if you're opposed to any of these changes, Patashu, just let me know so we can figure out which of these should be implemented (or changed - for example, if there's a better way to fix ssqrt than just falling back on linear_sroot, since sqrt has its own implementation separate from pow).
Changes made:
Explanations:
I'm not sure if any of these changes break anything (especially normalization of infinities - for all I know, that might break something that I'm unaware of), so if you're opposed to any of these changes, Patashu, just let me know so we can figure out which of these should be implemented (or changed - for example, if there's a better way to fix ssqrt than just falling back on linear_sroot, since sqrt has its own implementation separate from pow).