December 2005
Beginner to intermediate
618 pages
20h 19m
English
fabs
Obtains the absolute value of a number
#include <math.h> doublefabs( doublex); floatfabsf( floatx); long doublefabsl( long doublex);
The fabs() function returns
the absolute value of its floating-point argument
x; if x is
greater than or equal to 0, the return value is equal to
x. If x is
less than 0, the function returns
-x.
float x = 4.0F * atanf( 1.0F ); long double y = 4.0L * atanl( 1.0L ); if ( x == y ) printf( "x and y are exactly equal.\n" ); else if (fabs( x − y ) < 0.0001 *fabsl( y ) ) printf( "x and y are approximately equal:\n" "x is %.8f; y is %.8Lf.\n", x, y );
This code produces the following output:
x and y are approximately equal: x is 3.14159274; y is 3.14159265.
Read now
Unlock full access