Search code examples
c++exceptionfloating-pointc++20nothrow

C++: Which floating-point operations, if any, are guaranteed by the standard to be non-throwing?


In C++20 (or later), are there any operations involving floating point numbers that are guaranteed by the standard to never throw?

What about

  1. assignment and copy construction?
  2. comparison?
  3. arithmetic?

Note, I am concerned here only with ordinary regular C++ exceptions, not the special notion of "floating-point exceptions".

Here is a more precise formulation of my question:

If a and b are mutable objects of type double, which of the following expressions, if any, are guaranteed by the C++ standard to evaluate to true?

  1. noexcept(a = b)
  2. noexcept(a == b)
  3. noexcept(a + b)

For new readers, I'd like to clarify that I am only interested in "defined behavior", that is, everything that is not undefined behavior.


Solution

  • Note 1 An exception can be thrown from one of the following contexts: throw-expressions (expr.throw), allocation functions (basic.stc.dynamic.allocation), dynamic_cast (expr.dynamic.cast), typeid (expr.typeid), new-expressions (expr.new), and standard library functions (structure.specifications).

    Floating point operators are none of those.

    Notes are not normative, but they are good enough for me.