Differences in results when using the same function in CTFE and Runtime

Abdulhaq alynch4048 at gmail.com
Tue Aug 13 07:56:34 UTC 2024


On Thursday, 8 August 2024 at 10:31:32 UTC, Carsten Schlote wrote:

>
> Ok, the fractal code uses 'double' floats, which are by their 
> very nature limited in precision. But assuming that the math 
> emulation of CTFE works identical as the CPU does at runtime, 
> the outcome should be identical.
>

> Any experiences or thought on this?
>

It's worth mentioning that in the wider field, it is generally 
held that when working with floating point operations we don't 
expect to see the same duplicate results every time. It is a 
mistake to compare for equality, you should be checking for 
"almost equals".

For your particular application it might feel like a "bug" to see 
different results, but in fact this is expected behaviour and 
generally not held to be a fault.

One little piece of anecdata, when working with python I saw 
differing results in the 17th d.p. when running the exact same 
calculation in the same python session. The reason turned out to 
be which registers were being used each time, which could vary. 
This is not considered to be a bug.


More information about the Digitalmars-d mailing list