5

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)?

10
  • 6
    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. Commented Apr 23, 2015 at 22:26
  • @ixrec: By deterministic, do you mean consistently irregular? Commented Apr 23, 2015 at 23:05
  • 1
    @RobertHarvey I mean there are concrete limits to how irregular any particular operation can be. Commented Apr 23, 2015 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. Commented Apr 24, 2015 at 0:09
  • 1
    But the practical thing to know is floating-point-gui.de Commented Apr 24, 2015 at 0:16

1 Answer 1

2

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).

1
  • And C++ provides a way to signal that the IEEE 754 floating-point-standard is in force. Commented Dec 4, 2015 at 19:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.