haimkastner / unitsnet-js

A better way to hold unit variables and easily convert to the destination unit

Home Page:https://www.npmjs.com/package/unitsnet-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Math in JS

k3nsei opened this issue · comments

Shouldn't some library be used to do Math within JavaScript land? It's not accurate to use native math operations with decimals.

For example common problem
image

Hi @k3nsei

While working in JS, I think this is the "expected" result, since this is a JS operation matter.

What do you suggest? Are you familiar with a particular library that does this operation correctly?

@haimkastner I firmly believe that when working with measurements, accuracy is a top priority.
Below is a link to an article on the subject and some libraries that could be used.
https://smartbear.com/blog/four-serious-math-libraries-for-javascript/

@k3nsei, I understand your perspective, but I think adding such a dependency might be too much for most situations. While this library is currently pure JS without any dependencies, adding such one would end up making it heavier than necessary.

However, as you mentioned, it is important to allow maximum accuracy. Therefore, I am contemplating a solution where the library will expose an API for replacing the arithmetic functions with external ones. This way, users of the library would have the flexibility to select their preferred arithmetic function while still retaining JavaScript as the default option, with clear documentation provided about it.

This make sense, to have core library and adapters to provide light and accurate but more computation heavy implementation. It's how angular material solves usage of different date libraries in their date picker. Those are just my thoughts after reading source code, after listening podcast about dotnet original library.

@k3nsei version 2.1.1 contains #34 to allow external arithmetic formulas has been released.

Thank you for your valuable input.