Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 10 - Transcendental Functions / Miscellaneous Functions


hypot

You can use the hypot function to compute the length of the hypotenuse of a right triangle.

double_t hypot(double_t x, double_t y);
x
Any floating-point number.
y
Any floating-point number.
DESCRIPTION
The hypot function computes the square root of the sum of the squares of its arguments. This is an ANSI standard C library function.

hypot(x,y) = SQRTx2+y2

The function hypot performs its computation without undeserved overflow or underflow. For example, if x2+y2 is greater than the maximum representable value
of the data type but the square root of x2+y2 is not, then no overflow occurs.

EXCEPTIONS
When x and y are finite and nonzero, either the result of hypot(x,y) is exact or it raises one of the following exceptions:

  • inexact (if the result must be rounded or an overflow or underflow occurs)
  • overflow (if the result is outside the range of the data type)
  • underflow (if the result is inexact and must be represented as a denormalized number or 0)

SPECIAL CASES
Table 10-40 shows the results when one of the arguments to the hypot function is a zero, a NaN, or an Infinity. In this table, x and y are finite, nonzero floating-point numbers.
Special cases for the hypot function
OperationResultExceptions raised
hypot(+0,y) |y|None
hypot(x,+0) |x|None
hypot(-0,y) |y|None
hypot(x,-0) |x|None
hypot(NaN,y) NaNNone[65]
hypot(x,NaN) NaNNone[65]
hypot(NaN,± ) None
hypot(± ,NaN) None
hypot(+ ,y) + None
hypot(x,+ ) + None
hypot(- ,y) + None
hypot(x,- ) + None

EXAMPLES
z = hypot(2.0, 2.0); /* z = sqrt(8.0)  2.82843. The inexact 
                        exception is raised. */

[65] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996