Title
`std::abs(float)` is underspecified
Status
new
Section
[c.math.abs]
Submitter
Jan Schultke

Created on 2026-11-06.00:00:00 last changed 7 days ago

Messages

Date: 2026-11-07.13:24:07

Proposed resolution:

This wording is relative to N5054.

  1. Modify [c.math.abs] as indicated:

    constexpr floating-point-type abs(floating-point-type x);
    

    -4- ReturnsEffects: The absolute value of `x` Equivalent to: `return fabs(x);`.

    See also: ISO/IEC 9899:2024, 7.12.8.3, 7.24.7.1

Date: 2026-11-06.00:00:00

[c.math.abs] states that std::abs(floating-point-type x):

Returns: The absolute value of `x`.

What is the absolute value of NaN? What happens when passing signaling NaN? What about infinity? Does it produce positive zero when given negative zero? What about floating-point exceptions? When is it a constant expression? Nobody knows.

In practice, all major standard libraries forward to `std::fabs`.

History
Date User Action Args
2026-11-07 13:24:07adminsetmessages: + msg16648
2026-11-06 00:00:00admincreate