cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable
0 Likes
Reply
1 Solution
Esteemed Contributor II

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

View solution in original post

2 Replies
Moderator
Moderator

texnos

Moving to the PSoC 5 community.

0 Likes
Reply
Esteemed Contributor II

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

View solution in original post