2

So I am looking at the JavaScript MDN re-intro tutorial and got to the point on Floating Point Imprecision. https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

Why do they use this example? Wouldn't you get that result in most all languages?

enter image description here

timbram
  • 1,797
  • 5
  • 28
  • 49
  • Some languages try to hide those problems from the user. JavaScript doesn't. Anyways, why would you take another example, if this simple one fits already? – Sirko Jun 29 '16 at 20:21
  • 1
    @Sirko he wants to say the example isn't specific to javascript, he instead wants an example that works in other languages but not in javascript – niceman Jun 29 '16 at 20:24
  • Right, and since it specifically says, "if you're used to math in C or Java. Watch out for stuff like:" I would think that is the example they would give. I am trying to make sure I am not missing something here. – timbram Jun 29 '16 at 20:24
  • [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – j08691 Jun 29 '16 at 20:25
  • 2
    @j08691 that's why "if you're used to math in C or Java" sentence is wrong :) – niceman Jun 29 '16 at 20:27
  • 1
    @niceman Right, because I am used to math in C or Java, and the example they posted looks normal to me. – timbram Jun 29 '16 at 20:28
  • 1
    hmmm on second thought timbram, notice the dot after that sentence, I think that suggests they don't link java or C to the example but rather to the fact that javascript doesn't have integers – niceman Jun 29 '16 at 20:29

1 Answers1

2

I think the documentation is just poorly structured. We have:

"There's no such thing as an integer in JavaScript, so you have to be a little careful with your arithmetic if you're used to math in C or Java."

This makes sense. Then we have:

"Watch out for stuff like: 0.1 + 0.2 == 0.30000000000000004"

This also makes sense (as a general warning).

I think the documentation indented to have these as separate thoughts, but with the current formatting, it might taken as a a warning about floats specifically for C and Java programmers.

JonSG
  • 10,542
  • 2
  • 25
  • 36