OT: floats
Dom DiSc
dominikus at scherkl.de
Fri Jun 14 06:39:59 UTC 2024
On Thursday, 13 June 2024 at 19:50:34 UTC, Quirin Schroll wrote:
> [...] If you implement an algorithm, you have to take into
> account how rounding errors propagate through the calculations.
> The issue is that you can’t do that intuitively. You just can’t.
Best is to use an interval-type, that says the result is between
the lower and the upper bound. This contains both the error and
the accuracy information.
e.g. sqrt(2) may be ]1.414213, 1.414214[, so you know the exact
result is in this interval and you can't trust digits after the
6th. If now you square this, the result is ]1.9999984,
2.0000012[, which for sure contains the correct answer.
The comparison operators on these types are ⊂, ⊃, ⊆ and ⊇ - which
of course can not only be true or false, but also ND (not
defined) if the two intervals intersect.
so checks would ask something like "if(sqrt(2)^^2 ⊂ ]1.999,
2.001[)", so they don't ask only for the value but also for the
allowed error.
More information about the dip.development
mailing list