This is for a homework assignment about floats and doubles, we are to add 1/1 + 1/2 + 1/3 ... up to 1/10,000,000 and to do it again from 1/10,000,000 back down to 1/1 and to print both answers as doubles and floats. I had no problems with this but both the floats were different numbers with the 1/1 starting float being vastly different and both doubles being the same. I'm just wondering why this is the case and could find little relevant information.
Asked
Active
Viewed 63 times
1
-
1As you can see, `double` is much more precise than `float`. Read more about it [here](https://stackoverflow.com/questions/2386772/difference-between-float-and-double?rq=1). – Sid S Feb 06 '18 at 05:58
-
4"and could find little relevant information" This surprises me. Floating point accuracy issues are one of the topics broadly discussed. Just click on the [tag:floating-accuracy] (you assigned by yourself) to see a lot more Q/As about this. A general understanding of [Floating-point arithmetic](https://en.wikipedia.org/wiki/Floating-point_arithmetic) and [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754) may help also. – Scheff's Cat Feb 06 '18 at 06:03
-
Relevant reading: [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) and [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Jesper Juhl Feb 06 '18 at 06:37
-
See also: [Sometimes Floating Point Math is Perfect](https://randomascii.wordpress.com/2017/06/19/sometimes-floating-point-math-is-perfect/) – Jesper Juhl Feb 06 '18 at 07:44