cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cmath (math.h) : frexp
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cmath (math.h)
functions:
· acos
· asin
· atan
· atan2
· ceil
· cos
· cosh
· exp
· fabs
· floor
· fmod
· frexp
· ldexp
· log
· log10
· modf
· pow
· sin
· sinh
· sqrt
· tan
· tanh
macro constants:
· HUGE_VAL

-

frexp function
     double frexp (      double x, int * exp );
      float frexp (       float x, int * exp );
long double frexp ( long double x, int * exp );
<cmath>

Get significand and exponent

Breaks the floating point number x into its binary significand (a floating point value between 0.5 and 1.0) and an integral exponent for 2, such that:

x = significand * 2 exponent

The exponent is stored in the location pointed by exp, and the significand is the value returned by the function.

If x is zero, both parts (significand and exponent) are zero.

Parameters

x
Floating point value to be computed.
exp
Pointer to an int object where the value of the exponent is to be stored.

Return Value

The binary significand of x.
This value is the floating point value in the interval [0.5,1] which, once multiplied by 2 raised to the power of *exp*, yields x.

Portability

In C, only the double version of this function exists with this name.

Example

/* frexp example */
#include <stdio.h>
#include <math.h>

int main ()
{
  double param, result;
  int n;

  param = 15.2;
  result = frexp (param , &n);
  printf ("%lf * 2^%d = %f\n", result, n, param);
  return 0;
}

Output:


0.950000 * 2^4 = 15.200000

See also

ldexp Generate number from significand and exponent (function)
log Compute natural logarithm (function)
pow Raise to power (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us