Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7025

MicroPython • Re: int() doing odd things.

$
0
0

Code:

>>> "%.12f"%math.log2(8192)'12.999999046326'
Hence your result. It's FP being a weird little guy again. Not a bug.
I can accept that. But why does 'str()' and 'repr()', and whatever the REPL uses to show the result, show that as "13.0" ?

I would argue they are all lying to me in not telling me what value this float actually has.

It seems to me that MicroPython 32-bit floats have maybe 7 digits of resolution ...

Code:

>>> if True:...   #                  123456789...   "{:.64f}".format(1.000001)...   "{:.64f}".format(1.0000001)...   "{:.64f}".format(1.00000001)...'1.00000095367431640625000000000''1.00000011920928955078125000000''1.00000000000000000000000000000'
I was expecting 'str()', 'repr()' and REPL to show those as above with trailing zeroes lopped off. But they are all doing something other than reporting the actual value. All those report '1.0'.

If any of my software were doing that I'd class it as a bug. It's at least funky unexpected behaviour to me.

I will maybe have to do some digging.

Statistics: Posted by hippy — Mon Apr 28, 2025 12:33 am



Viewing all articles
Browse latest Browse all 7025

Trending Articles