Title
3-arg std::hypot is underspecified compared to the 2-arg overload
Status
new
Section
[c.math.hypot3]
Submitter
Matthias Kretz

Created on 2018-12-06.00:00:00 last changed 64 months ago

Messages

Date: 2018-12-21.15:26:00
xmlns:ns0="http://www.w3.org/1998/Math/MathML">

Proposed resolution:

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

  1. Modify [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 hypot functions compute the square root of the sum of the squares of x, y, and z, without undue overflow or underflow. A range error may occur.

    -1- Returns: x2+ y2+z2.

    -?- Remarks: If __STDC_IEC_559__ is defined, the following guarantees hold:

    • hypot(x, y, z), hypot(x, z, y), hypot(z, y, x), and hypot(x, y, -z) are equivalent.

    • if y2 + z2 == ±0, hypot(x, y, z) is equivalent to fabs(x).

    • hypot(±∞, y, z) returns +∞, even if y and/or z is a NaN.

Option B

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

Date: 2018-12-21.00:00:00

[ 2018-12-21 Reflector prioritization ]

Set Priority to 3

Date: 2018-12-06.00:00:00
xmlns:ns0="http://www.w3.org/1998/Math/MathML">

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 [c.math.hypot3] is only specified as "Returns: x2+ y2+z2.". 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>, […]".

History
Date User Action Args
2018-12-21 15:26:00adminsetmessages: + msg10263
2018-12-09 13:28:30adminsetmessages: + msg10250
2018-12-06 00:00:00admincreate