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 / Comparison Functions


fdim

You can use the fdim function to determine the positive difference between two real numbers.

double_t fdim (double_t x, double_t y);
x
Any floating-point number.
y
Any floating-point number.
DESCRIPTION
The fdim function returns the positive difference between its two arguments.

fdim(x,y) = x+-y if x > y
fdim(x,y) = +0 if x y

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

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

SPECIAL CASES
Table 10-1 shows the results when one of the arguments to the fdim 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 fdim function
OperationResultExceptions raised
fdim(+0,y) +0None
fdim(x,+0) xNone
fdim(-0,y) +0None
fdim(x,-0) xNone
fdim(NaN,y) NaN[19]None[20]
fdim(x,NaN) NaNNone
fdim(+ ,y) + None
fdim(x,+ ) +0None
fdim(- ,y) +0None
fdim(x,- ) + None

EXAMPLES
z = fdim(+INFINITY, 300);  /* z = +   - 300 = +INFINITY because 
                              +   > 300 */
z = fdim(300, +INFINITY);  /* z = +0 because 300  +   */

[19] If both arguments are NaN, the first NaN is returned.
[20] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996