sl@0: /* S_FREXP.C sl@0: * sl@0: * Portions Copyright (c) 1993-2005 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: */ sl@0: sl@0: sl@0: /* @(#)s_frexp.c 5.1 93/09/24 */ sl@0: /* sl@0: * ==================================================== sl@0: * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. sl@0: * sl@0: * Developed at SunPro, a Sun Microsystems, Inc. business. sl@0: * Permission to use, copy, modify, and distribute this sl@0: * software is freely granted, provided that this notice sl@0: * is preserved. sl@0: * ==================================================== sl@0: */ sl@0: sl@0: /* sl@0: FUNCTION sl@0: <>, <>---split floating-point number sl@0: INDEX sl@0: frexp sl@0: INDEX sl@0: frexpf sl@0: sl@0: ANSI_SYNOPSIS sl@0: #include sl@0: double frexp(double <[val]>, int *<[exp]>); sl@0: float frexpf(float <[val]>, int *<[exp]>); sl@0: sl@0: TRAD_SYNOPSIS sl@0: #include sl@0: double frexp(<[val]>, <[exp]>) sl@0: double <[val]>; sl@0: int *<[exp]>; sl@0: sl@0: float frexpf(<[val]>, <[exp]>) sl@0: float <[val]>; sl@0: int *<[exp]>; sl@0: sl@0: sl@0: DESCRIPTION sl@0: All non zero, normal numbers can be described as <[m]> * 2**<[p]>. sl@0: <> represents the double <[val]> as a mantissa <[m]> sl@0: and a power of two <[p]>. The resulting mantissa will always sl@0: be greater than or equal to <<0.5>>, and less than <<1.0>> (as sl@0: long as <[val]> is nonzero). The power of two will be stored sl@0: in <<*>><[exp]>. sl@0: sl@0: @ifinfo sl@0: <[m]> and <[p]> are calculated so that sl@0: <[val]> is <[m]> times <<2>> to the power <[p]>. sl@0: @end ifinfo sl@0: @tex sl@0: <[m]> and <[p]> are calculated so that sl@0: $ val = m \times 2^p $. sl@0: @end tex sl@0: sl@0: <> is identical, other than taking and returning sl@0: floats rather than doubles. sl@0: sl@0: RETURNS sl@0: <> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity, sl@0: or Nan, <> will set <<*>><[exp]> to <<0>> and return <[val]>. sl@0: sl@0: PORTABILITY sl@0: <> is ANSI. sl@0: <> is an extension. sl@0: sl@0: sl@0: */ sl@0: sl@0: /* sl@0: * for non-zero x sl@0: * x = frexp(arg,&exp); sl@0: * return a double fp quantity x such that 0.5 <= |x| <1.0 sl@0: * and the corresponding binary exponent "exp". That is sl@0: * arg = x*2^exp. sl@0: * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg sl@0: * with *exp=0. sl@0: */ sl@0: sl@0: #include "FDLIBM.H" sl@0: sl@0: static const double sl@0: two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ sl@0: sl@0: /** sl@0: Get mantissa and exponent of floating-point value. sl@0: Calculates mantissa (a floating-point value between 0.5 and 1) sl@0: and exponent (an integer value) where x is parameter x, sl@0: mantissa is the value returned by the function and exponent sl@0: is set by the function at location pointed by eptr. sl@0: @return Mantissa. sl@0: @param x Floating point value sl@0: @param eptr Location where to exponent will be received. sl@0: */ sl@0: EXPORT_C double frexp(double x, int *eptr) __SOFTFP sl@0: { sl@0: __int32_t hx, ix, lx; sl@0: EXTRACT_WORDS(hx,lx,x); sl@0: ix = 0x7fffffff&hx; sl@0: *eptr = 0; sl@0: if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ sl@0: if (ix<0x00100000) { /* subnormal */ sl@0: x *= two54; sl@0: GET_HIGH_WORD(hx,x); sl@0: ix = hx&0x7fffffff; sl@0: *eptr = -54; sl@0: } sl@0: *eptr += (ix>>20)-1022; sl@0: hx = (hx&0x800fffff)|0x3fe00000; sl@0: SET_HIGH_WORD(x,hx); sl@0: return x; sl@0: }