I started writing this as a SO question, but I think it's better suited here. While I'm happy for a simple answer I'm also fond of the "Teach a Man to Fish" philosophy so I'm happy for people to point me to documentation.

Is floating-point arithmetic fully locked down by the standard?

In other words, suppose I have a fully compliant c++ program compiled with a fully compliant compiler that performs every possible combination of floating point operation. Will such a program perform identically on any machine with the same data model, regardless of which compliant compiler I use?

Where can I learn more about floating point arithmetic as defined by the C++ standard (I don't have a copy)?

  • 5
    I believe SO has an excellent answer to this already: stackoverflow.com/questions/24157094/…. The short version is that the C++ standard says almost nothing, but most real-world implementations follow the IEEE 754 standard which is close to being fully deterministic. – Ixrec Apr 23 '15 at 22:26
  • @ixrec: By deterministic, do you mean consistently irregular? – Robert Harvey Apr 23 '15 at 23:05
  • 1
    @RobertHarvey I mean there are concrete limits to how irregular any particular operation can be. – Ixrec Apr 23 '15 at 23:07
  • I would believe that a weird implementation where the floating point types are all singleton types (i.e. you have only one floating point value, NAN) is conformant to the letter (but not the spirit) of the C++11 standard. – Basile Starynkevitch Apr 24 '15 at 0:09
  • 1
    But the practical thing to know is floating-point-gui.de – Basile Starynkevitch Apr 24 '15 at 0:16

The C++ standard does not fully define floating point behaviour. However, there are floating point standards, like IEEE 754, that are widely supported by C++ compilers (at least among the compilers that support hardware targets that have proper floating point support).

  • And C++ provides a way to signal that the IEEE 754 floating-point-standard is in force. – Deduplicator Dec 4 '15 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.