j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

Operations in Fortran which are not bit-reproducible #314

Open marshallward opened 9 months ago

marshallward commented 9 months ago

Numerical computation in Fortran uses some form of floating point arithmetic. As a sparse subset of the real numbers, any numerical operation is prone to some kind of estimation. While not explicitly required to use the IEEE-754 model, it is by far the most widely used one.

Although Fortran specifies clear rules for many such operations, there are some areas of ambiguity. This can create challenges for programs which require predictable, bitwise reproducible results.

I have tried to document these areas of ambiguity, along with comments on how to retain some degree of reproducibility.


This was submitted in response to the discussion in #310.

Note that this is not necessarily an "issue"; this should be taken as a reference of possible bit reproducibility issues which one may be encounter. An ambiguous expression provides an opportunity for a compiler to optimize the result, such as for a particular platform.

I can edit this top-level comment to include any other examples of interest.

certik commented 9 months ago

@marshallward awesome, thanks for writing this up!