Differences in results when using the same function in CTFE and Runtime
Abdulhaq
alynch4048 at gmail.com
Thu Aug 15 19:38:23 UTC 2024
On Thursday, 15 August 2024 at 16:51:51 UTC, Timon Gehr wrote:
> On 8/15/24 18:21, Abdulhaq wrote:
>> Why do you want to reproduce the errors?
>
> It's you who calls it "errors". Someone else may just call it
> "results".
>
Here by "error" I mean where the result is different to a known
correct answer. It's a simple matter to propose a method for
producing a fractal plot, and to have a notional "correct" plot
if calculated to infinite precision. Then, at sufficient depth of
an e.g. mandelbrot plot, at a finite precision, some pixels will
differ from the ideal plot produced by the machine of infinite
precision. These divergences are, by my definition, errors. Yes,
it's all results, and some results are errors.
> Science. Determinism, e.g. blockchain or other deterministic
> lock-step networking. etc. It's not hard to come up with use
> cases. Sometimes what exact result you get is not very
> important, but it is important that you get the same one.
>
>>
This is why I was careful to say that I was generalising. Of
course we can come up with examples where reproduceability is an
essential requirement. In this case we can often work out what
precision is required to achieve said reproduceability.
>> In general floating point calculations are inexact, and we
>> shouldn't (generalising here) expect to get the same error
>> across different platforms.
>
> It's just not true that floating point calculations are somehow
> "inexact". You are confusing digital and analog computing. This
> is still digital computing. Rounding is a deterministic, exact
> function, like any other.
Fair point. I meant to refer to floating point numbers rather
than calculations. There are an infinite number of real numbers
that cannot be exactly represented by a floating point number of
finite precision. The floating point representations of those
numbers are inexact.
If we calculate 1/3 using floating point, the result can be
exactly correct in the sense there is a correct answer in the
world of floating point, but the calculated result will be an
inexact representation of the correct number, which is what I had
in mind.
More information about the Digitalmars-d
mailing list