Remix.run Logo
OskarS 2 days ago

Couldn't resist checking what math.h does for floats and doubles on godbolt, it returns slightly above 9, but curiously not exactly equal to any answer in that list [1]. Maybe not that surprising, these transcendental functions are always iffy in the last digits.

[1]: https://godbolt.org/z/dK85Eq8r6

chongli 2 days ago | parent | next [-]

I would be really surprised if any physical calculator used binary floating point numbers instead of binary-coded decimal. The appearance of repeating bits even for relatively simple decimal numbers like 0.1 is likely to confuse and annoy a calculator user expecting an exact answer.

OskarS 2 days ago | parent [-]

I would assume most basic calculators use regular floating point circuits, and then just round aggressively for the display.

inejge 2 days ago | parent [-]

Cheap calculators use microcontroller-like CPUs which simply have no room for floating-point hardware. BCD or fixed-point integers in software are much cheaper and simpler.

masfuerte 2 days ago | parent | prev | next [-]

CORE-MATH provides correctly rounded transcendental functions. (Though that doesn't mean that this calculation will return exactly 9. And I haven't tried it.)

https://core-math.gitlabpages.inria.fr/

avipars 2 days ago | parent | prev [-]

chalk it up to floating point accuracy