CodingTrain / Suggestion-Box

A repo to track ideas for topics
568 stars 86 forks source link

Creating a Javascript to do math on huge numbers. #1801

Open Denmarks opened 1 year ago

Denmarks commented 1 year ago

The largest number that JavaScript can handle is 9007199254740991. Years ago I had a personal website and created a script to do addition, subtraction, multiplication, and division on practically unlimited size positive integers. I do one column at a time like someone doing it on paper. I still have the script and wonder if it would be a good challenge. Details on request.

Vanshika-Dargan commented 9 months ago

Aren't their existing libraries available like bigint

JohnyDL commented 9 months ago

There are libraries but there are for a lot of things Coding Train covers, it's not about doing it better but rather about showing how such things work so people understand them.

There's a weird but kinda awesome algorithm to double the precision of floating point numbers that could be coded up in JS

https://www.youtube.com/watch?v=6OuqnaHHUG8

it's kind of better than going column by column and I'm sure it could be extended to arbitrary precision (possibly by recursion)

Doing it as part of a series like 'build your own calculator' would be kind of awesome