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
121 stars 44 forks source link

Loading decimals from localStorage #112

Closed alemaninc closed 2 years ago

alemaninc commented 2 years ago

Is there a function which can check if new Decimal(x) is a valid number? I'd like to be able to automate loading from localStorage without having to make a list of around 100 variables that need to be converted into a Decimal.

Examples: Decimal.valid("3.141592653589793" ) = true Decimal.valid("(e^8)15") = true Decimal.valid(true) = false Decimal.valid([1,1,2,3,5,8]) = false Decimal.valid("Mixed scientific") = false

jakub791 commented 2 years ago

No, no such method exsists. But can't you use Decimal's static methods which will automatically convert strings to Decimals for you (obviously only do it on values thst are actually meant to be Decimals)?

alemaninc commented 2 years ago

I store all my variables in an object, so that I can load everything at once without having to add more code to the load() function for each variable that I add (the load function uses a loop so that new variables added by updates don't get removed), and having to store a list of Decimals defeats the point of having this loop. I'll probably just create this method myself in my local version.

jakub791 commented 2 years ago

Can't you use Decimal's static methods everywhere where you do math on Decimals? This way, all the variables can be loaded as strings and they will be converted to Decimals by break eternity itself when you pass them to the static methods.