OT: floats
Dukc
ajieskola at gmail.com
Wed Jun 12 21:05:39 UTC 2024
Quirin Schroll kirjoitti 12.6.2024 klo 16.25:
> On Sunday, 9 June 2024 at 17:54:38 UTC, Walter Bright wrote:
>> On 5/26/2024 1:05 AM, Daniel N wrote:
>>> I was aware of `-ffast-math` but not that the seemingly harmless
>>> enabling of gnu dialect extensions would change excess-precision!
>>
>> Supporting various kinds of fp math with a switch is just a bad idea,
>> mainly because so few people understand fp math and its tradeoffs. It
>> will also bork up code that is carefully tuned to the default settings.
>
> Every once in a while, I believe floating-point numbers are such
> delicate tools, they should be disabled by default and require a
> compiler switch to enable. Something like
> `--enable-floating-point-types--yes-i-know-what-i-am-doing-with-them--i-swear-i-read-the-docs`. And yeah, this is tongue in cheek, but I taught applied numerics and programming for mathematicians for 4 years, and even I get it wrong sometimes. In my work, we use arbitrary precision rational numbers because they’re fool-proof and we don’t need any transcendental functions.
My rule of thumb - if I don't have a better idea - is to treat FP
numbers like I'd treat readings from a physical instrument: there's
always going to be a slight "random" factor in my calculations. I can't
trust `==` operator with FP expression result just like I can't trust
I'll get exactly the same result if I measure the length of the same
metal rod twice.
Would you agree this being a good basic rule?
More information about the dip.development
mailing list