This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Ready status.
std::hypot is underspecified compared to the 2-arg overloadSection: 29.7.3 [c.math.hypot3] Status: Ready Submitter: Matthias Kretz Opened: 2018-12-06 Last modified: 2026-07-17
Priority: 3
View all issues with Ready status.
Discussion:
The 2-arg hypot function specified in the C standard is required to avoid overflow and underflow
(7.12.7.3 p2). Furthermore C's Annex F (IEC 60559 floating-point arithmetic) defines special cases for
inputs of ±0 and ±inf (F. 10.4.3). The 3-arg hypot function
29.7.3 [c.math.hypot3] is only specified as "Returns:
.". This is
inconsistent with the 2-arg overload.
It is not clear whether C's Annex F is "imported" into the C++ standard. [cmath.syn] p1 suggests that it
is: "The contents and meaning of the header <cmath> are the same as the C standard library
header <math.h>, […]".
[2018-12-21 Reflector prioritization]
Set Priority to 3
This wording is relative to N4778.
[Drafting Note: Two mutually exclusive options are prepared, depicted below by Option A and Option B, respectively.]
Option A
Modify 29.7.3 [c.math.hypot3] as indicated:
float hypot(float x, float y, float z); double hypot(double x, double y, double z); long double hypot(long double x, long double y, long double z);-?- Effects: The
hypotfunctions compute the square root of the sum of the squares ofx,y, andz, without undue overflow or underflow. A range error may occur.-1- Returns: .
-?- Remarks: If
__STDC_IEC_559__is defined, the following guarantees hold:
hypot(x, y, z),hypot(x, z, y),hypot(z, y, x), andhypot(x, y, -z)are equivalent.if
y2 + z2 == ±0,hypot(x, y, z)is equivalent tofabs(x).
hypot(±∞, y, z)returns+∞, even ifyand/orzis a NaN.
Option B
Add a note that clarifies that the behavior of the 3-arg hypot function
differs from the C specification. I.e. that no special guarantees wrt. over-/underflow or
special values are given.
[2026-06-10; Tim provides new wording]
LWG in Brno is in favor of the direction of Option A. However, __STDC_IEC_559__ is not defined in C++.
The wording has been updated following the current C WD, taking into account
WG14 N2714.
[Brno 2026-06-12; Status changed: New → Ready.]
This wording is relative to N5050.
Modify 29.7.3 [c.math.hypot3] as indicated:
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y, floating-point-type z);-?- Effects: Compute the square root of the sum of the squares of
x,y, andz, without undue overflow or underflow. A range error may occur.-1- Returns: .
-?- Remarks: If
numeric_limits<floating-point-type>::is_iec559istrue, the following guarantees hold:
hypot(x, y, z),hypot(x, z, y),hypot(z, y, x), andhypot(x, y, -z)are equivalent.if
yandzare zero andxis not a NaN,hypot(x, y, z)returns the absolute value ofx.if
xis positive or negative infinity,hypot(x, y, z)returns positive infinity, even ifyand/orzis a NaN.if
xis a NaN and neitherynorzis positive or negative infinity,hypot(x, y, z)returns a NaN.
[2026-06-30; Tim reopens and provides new wording. Status changed: Ready → Open.]
Matthias Kretz pointed out that is_iec559 is the wrong test as it only concerns representation and not behavior.
Until C++ gets its own floating point annex, this wording downgrades the Remarks: to a Recommended practice:
and ties the condition to whether the binary version of hypot conforms to C's Annex F.
[2026-07-17 LWG telecon; Change status New → Ready.]
Proposed resolution:
This wording is relative to N5050.
Modify 29.7.3 [c.math.hypot3] as indicated:
constexpr floating-point-type hypot(floating-point-type x, floating-point-type y, floating-point-type z);-?- Effects: Compute the square root of the sum of the squares of
x,y, andz, without undue overflow or underflow. A range error may occur.-1- Returns: .
-?- Recommended practice: An implementation whose two-parameter overload of
hypotconforms to ISO/IEC 9899:2024 Annex F should provide the following guarantees:
hypot(x, y, z),hypot(x, z, y),hypot(z, y, x), andhypot(x, y, -z)are equivalent.if
yandzare zero andxis not a NaN,hypot(x, y, z)returns the absolute value ofx.if
xis positive or negative infinity,hypot(x, y, z)returns positive infinity, even ifyand/orzis a NaN.if
xis a NaN and neitherynorzis positive or negative infinity,hypot(x, y, z)returns a NaN.