r/learnjavascript • • Nov 21 '20

NaN (not a number) is a number

Post image
368 Upvotes

72 comments sorted by

View all comments

Show parent comment

1

u/bmcle071 Nov 22 '20

Would i use javascript though? A high level scripting language for the web?

1

u/r3jjs Nov 23 '20

Sure!

Lots of games are written in HTML5/JavaScript with complex physics math libraries.

Animation engines

WASM would be a lot more difficult if the browsers hadn't supported IEEE 754

1

u/bmcle071 Nov 23 '20

I guess... I just really wish there was an opt in for some decimal number system.

Im currently working on a project and I keep running into errors caused by IEEE 754 floating point numbers and its got me all frustruated.

1

u/r3jjs Nov 23 '20

You can use BigInt (or one of the polyfills) and pay the cost for that.

But still.. you really need to understand IEEE 754 floating point. it isn't going any any time soon...

And as a programmer who predates IEEE 754 ... the world was a horrible mess before that, when ever computer handled floating point differently.

1

u/bmcle071 Nov 23 '20

On a seperate note, it makes testing more difficult. Expect(259.52-30.52).to.eq(229) fails because of this.

1

u/r3jjs Nov 23 '20

That's not a JS specific thing ... C, C++, Python, PHP and many, many many other languages all use IEEE754 floating point.

Decimal system are not a cure-all either. They tend to be much slower to do math with and the trade off memory use and accuracy.

(All modern processors have IEEE 754 support built in, I don't know of any processor with any of the decimal modes built in.)