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

Off topic discussion • Re: Python Floating point addtion question

$
0
0
yes, CircuitPython is derived from MicroPython, and most of its variants use single-precision floating point to save space. It may be possible to build CircuitPython with double-precision floats.

You know that even with double precision, there are some numbers you can't represent, right? You're trying to add numbers that are roughly seven orders of magnitude apart. Are you sure those numbers after the decimal point are significant?

Once you get to 2451545.0, single precision numbers only occur every 0.25. Your only representable numbers are 2451545.0, 2451545.25, 2451545.5, 2451545.75, 2451546.0. When you added 0.234567, that's less than 0.25, so the result stayed at 2451545.

(Contrast with double precision: the next number is 2451545.0000000005, so your addend of 0.234567 is relatively huge, and the result doesn't fall in a hole between numbers*)

What are you using these numbers for? If it's for precise astronomical work, I'd be concerned. If it's for general numerics, or control of small devices, single precision is adequate. CircuitPython (as far as I remember) doesn't have the Decimal or Fraction types that can be used to extend precision in regular Python.

--
* : try 2451545.0 + 0.0000000002 in regular Python to show double precision falling into a hole.

Statistics: Posted by scruss — Fri Aug 22, 2025 12:01 am



Viewing all articles
Browse latest Browse all 8082

Trending Articles