Skip to content
Discussion options

You must be logged in to vote

I assume it's because of the fact, that there is no precise binary representation of 0.01. If you add that over and over, the error will sum up. Rounding after each step prevents this accumulation. If you write e.g.:

i:float = 9486.0

for n in range(0, 128):
    i += 1/128 
    # print(i)
    
print(i)

You will get a proper result. 1/128 can be exactly represented as binary number.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@robert-hh
Comment options

@MichaSU99
Comment options

@MichaSU99
Comment options

@robert-hh
Comment options

Answer selected by MichaSU99
@MichaSU99
Comment options

Comment options

You must be logged in to vote
1 reply
@robert-hh
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
ESP32
Labels
None yet
3 participants