genericopenlibs/cstdlib/LMATH/S_LDEXP.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /* S_LDEXP.C
       
     2  * 
       
     3  * Portions Copyright (c) 1993-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  */
       
     6 
       
     7 
       
     8 /* @(#)s_ldexp.c 5.1 93/09/24 */
       
     9 /*
       
    10  * ====================================================
       
    11  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
       
    12  *
       
    13  * Developed at SunPro, a Sun Microsystems, Inc. business.
       
    14  * Permission to use, copy, modify, and distribute this
       
    15  * software is freely granted, provided that this notice 
       
    16  * is preserved.
       
    17  * ====================================================
       
    18  */
       
    19 
       
    20 /*
       
    21 FUNCTION
       
    22        <<ldexp>>, <<ldexpf>>---load exponent
       
    23 
       
    24 INDEX
       
    25 	ldexp
       
    26 INDEX
       
    27 	ldexpf
       
    28 
       
    29 ANSI_SYNOPSIS
       
    30        #include <math.h>
       
    31        double ldexp(double <[val]>, int <[exp]>);
       
    32        float ldexpf(float <[val]>, int <[exp]>);
       
    33 
       
    34 TRAD_SYNOPSIS
       
    35        #include <math.h>
       
    36 
       
    37        double ldexp(<[val]>, <[exp]>)
       
    38               double <[val]>;
       
    39               int <[exp]>;
       
    40 
       
    41        float ldexpf(<[val]>, <[exp]>)
       
    42               float <[val]>;
       
    43               int <[exp]>;
       
    44 
       
    45 
       
    46 DESCRIPTION
       
    47 <<ldexp>> calculates the value 
       
    48 @ifinfo
       
    49 <[val]> times 2 to the power <[exp]>.
       
    50 @end ifinfo
       
    51 @tex
       
    52 $val\times 2^{exp}$.
       
    53 @end tex
       
    54 <<ldexpf>> is identical, save that it takes and returns <<float>>
       
    55 rather than <<double>> values.
       
    56 
       
    57 RETURNS
       
    58 <<ldexp>> returns the calculated value.
       
    59 
       
    60 Underflow and overflow both set <<errno>> to <<ERANGE>>.
       
    61 On underflow, <<ldexp>> and <<ldexpf>> return 0.0.
       
    62 On overflow, <<ldexp>> returns plus or minus <<HUGE_VAL>>.
       
    63 
       
    64 PORTABILITY
       
    65 <<ldexp>> is ANSI, <<ldexpf>> is an extension.
       
    66               
       
    67 */   
       
    68 
       
    69 #include "FDLIBM.H"
       
    70 #include <errno.h>
       
    71 
       
    72 /**
       
    73 Get floating-point value from mantissa and exponent.
       
    74 Calculates the floating point value corresponding to 
       
    75 the given mantissa and exponent
       
    76 @return   Floating-point value equal to value * 2exp.
       
    77 @param x Floating point value representing mantissa 
       
    78 @param exp Integer exponent
       
    79 */	
       
    80 EXPORT_C double ldexp(double value, int exp) __SOFTFP
       
    81 {
       
    82 	if(!finite(value)||value==0.0) return value;
       
    83 	value = scalbn(value,exp);
       
    84 	if(!finite(value)||value==0.0) errno = ERANGE;
       
    85 	return value;
       
    86 }