Hacker News new | ask | show | jobs
by arduinomancer 1896 days ago
Does this mean I could write a calculator in JavaScript which is more accurate than the language but not as fast?

For example: just treat numbers as strings and write code that adds the digits one by one and does the right carries

Now that I think about it, is this the whole point of the Java BigDecimal class?

3 comments

You can likely do better than this within rational numbers by working with integer numerator and denominator; you'll still have to make compromises for irrational numbers.
It's been done, there are libraries out there.
Yes, and it would be inexcusable malpractice to implement a calculator using the native floating-point type.
lol, malpractice. What if you want a calculator that specifically uses native floating point math, like to aid in programming, or just playing with the datatype?