Math Background
Math Background
@lou.codes/math
is a curried functional library I created to do simple math
but getting the correct result (because JavaScript doesnโt).
Why
I noticed that some WebApps that even handle money, are not using precise math
for the values, son letโs say that you have to pay 13.1
and you have 8.2
of
taxes, the result will actually be 21.299999999999997
which is not great.
How
I built this library using TypeScript, with configurations from my shared configs, scaffolding it with my trusty create-package. I made it ESM only because CJS no longer made sense when I created this (Node started supporting ESM modules a long time ago), and I made it tree-shakeable by using named exports.
It took around 5 hours to be done. I started from the idea of representing
numbers as a [base, exponent]
tuple using bigint
to ensure round long
numbers, and I went from there.
I tested everything using my test library.
Where
Iโm using it now every time I want to have reliable math in my apps, you can play with it in your browser terminal by going to the reference