- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is caused by the internal representation of floats. The mantissa is expressed as a fraction of 2^n which sometimes cannot be represented without an error (as 1/3 in decimal). The printf() functions round the argument to the required precision so you might not notice any difference. The only consequence for programmers is: Do not test a float for zero (0.0) but abs(float) for a selected epsilon.
Hint: Calculate Sum(1/n) for n = 1 to 100,000 and for n = 100,000 down to 1 and compare the results.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is caused by the internal representation of floats. The mantissa is expressed as a fraction of 2^n which sometimes cannot be represented without an error (as 1/3 in decimal). The printf() functions round the argument to the required precision so you might not notice any difference. The only consequence for programmers is: Do not test a float for zero (0.0) but abs(float) for a selected epsilon.
Hint: Calculate Sum(1/n) for n = 1 to 100,000 and for n = 100,000 down to 1 and compare the results.
Bob