os/ossrv/genericopenlibs/cstdlib/LMATH/S_FREXP.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* S_FREXP.C
sl@0
     2
 * 
sl@0
     3
 * Portions Copyright (c) 1993-2005 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     4
 * All rights reserved.
sl@0
     5
 */
sl@0
     6
sl@0
     7
sl@0
     8
/* @(#)s_frexp.c 5.1 93/09/24 */
sl@0
     9
/*
sl@0
    10
 * ====================================================
sl@0
    11
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
sl@0
    12
 *
sl@0
    13
 * Developed at SunPro, a Sun Microsystems, Inc. business.
sl@0
    14
 * Permission to use, copy, modify, and distribute this
sl@0
    15
 * software is freely granted, provided that this notice 
sl@0
    16
 * is preserved.
sl@0
    17
 * ====================================================
sl@0
    18
 */
sl@0
    19
sl@0
    20
/*
sl@0
    21
FUNCTION
sl@0
    22
       <<frexp>>, <<frexpf>>---split floating-point number
sl@0
    23
INDEX
sl@0
    24
	frexp
sl@0
    25
INDEX
sl@0
    26
	frexpf
sl@0
    27
sl@0
    28
ANSI_SYNOPSIS
sl@0
    29
	#include <math.h>
sl@0
    30
        double frexp(double <[val]>, int *<[exp]>);
sl@0
    31
        float frexpf(float <[val]>, int *<[exp]>);
sl@0
    32
sl@0
    33
TRAD_SYNOPSIS
sl@0
    34
	#include <math.h>
sl@0
    35
        double frexp(<[val]>, <[exp]>)
sl@0
    36
        double <[val]>;
sl@0
    37
        int *<[exp]>;
sl@0
    38
sl@0
    39
        float frexpf(<[val]>, <[exp]>)
sl@0
    40
        float <[val]>;
sl@0
    41
        int *<[exp]>;
sl@0
    42
sl@0
    43
sl@0
    44
DESCRIPTION
sl@0
    45
	All non zero, normal numbers can be described as <[m]> * 2**<[p]>.
sl@0
    46
	<<frexp>> represents the double <[val]> as a mantissa <[m]>
sl@0
    47
	and a power of two <[p]>. The resulting mantissa will always
sl@0
    48
	be greater than or equal to <<0.5>>, and less than <<1.0>> (as
sl@0
    49
	long as <[val]> is nonzero). The power of two will be stored
sl@0
    50
	in <<*>><[exp]>. 
sl@0
    51
sl@0
    52
@ifinfo
sl@0
    53
<[m]> and <[p]> are calculated so that
sl@0
    54
<[val]> is <[m]> times <<2>> to the power <[p]>.
sl@0
    55
@end ifinfo
sl@0
    56
@tex
sl@0
    57
<[m]> and <[p]> are calculated so that
sl@0
    58
$ val = m \times 2^p $.
sl@0
    59
@end tex
sl@0
    60
sl@0
    61
<<frexpf>> is identical, other than taking and returning
sl@0
    62
floats rather than doubles.
sl@0
    63
sl@0
    64
RETURNS
sl@0
    65
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
sl@0
    66
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
sl@0
    67
sl@0
    68
PORTABILITY
sl@0
    69
<<frexp>> is ANSI.
sl@0
    70
<<frexpf>> is an extension.
sl@0
    71
sl@0
    72
sl@0
    73
*/
sl@0
    74
sl@0
    75
/*
sl@0
    76
 * for non-zero x 
sl@0
    77
 *	x = frexp(arg,&exp);
sl@0
    78
 * return a double fp quantity x such that 0.5 <= |x| <1.0
sl@0
    79
 * and the corresponding binary exponent "exp". That is
sl@0
    80
 *	arg = x*2^exp.
sl@0
    81
 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg 
sl@0
    82
 * with *exp=0. 
sl@0
    83
 */
sl@0
    84
sl@0
    85
#include "FDLIBM.H"
sl@0
    86
sl@0
    87
static const double
sl@0
    88
two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
sl@0
    89
sl@0
    90
/**
sl@0
    91
Get mantissa and exponent of floating-point value.
sl@0
    92
Calculates mantissa (a floating-point value between 0.5 and 1) 
sl@0
    93
and exponent (an integer value) where x is parameter x, 
sl@0
    94
mantissa is the value returned by the function and exponent
sl@0
    95
is set by the function at location pointed by eptr.
sl@0
    96
@return Mantissa.
sl@0
    97
@param x Floating point value 
sl@0
    98
@param eptr Location where to exponent will be received.
sl@0
    99
*/	
sl@0
   100
EXPORT_C double frexp(double x, int *eptr) __SOFTFP
sl@0
   101
{
sl@0
   102
	__int32_t hx, ix, lx;
sl@0
   103
	EXTRACT_WORDS(hx,lx,x);
sl@0
   104
	ix = 0x7fffffff&hx;
sl@0
   105
	*eptr = 0;
sl@0
   106
	if(ix>=0x7ff00000||((ix|lx)==0)) return x;	/* 0,inf,nan */
sl@0
   107
	if (ix<0x00100000) {		/* subnormal */
sl@0
   108
	    x *= two54;
sl@0
   109
	    GET_HIGH_WORD(hx,x);
sl@0
   110
	    ix = hx&0x7fffffff;
sl@0
   111
	    *eptr = -54;
sl@0
   112
	}
sl@0
   113
	*eptr += (ix>>20)-1022;
sl@0
   114
	hx = (hx&0x800fffff)|0x3fe00000;
sl@0
   115
	SET_HIGH_WORD(x,hx);
sl@0
   116
	return x;
sl@0
   117
}