1 | |
---|
2 | /* @(#)s_ldexp.c 5.1 93/09/24 */ |
---|
3 | /* |
---|
4 | * ==================================================== |
---|
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
6 | * |
---|
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
8 | * Permission to use, copy, modify, and distribute this |
---|
9 | * software is freely granted, provided that this notice |
---|
10 | * is preserved. |
---|
11 | * ==================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | FUNCTION |
---|
16 | <<ldexp>>, <<ldexpf>>---load exponent |
---|
17 | |
---|
18 | INDEX |
---|
19 | ldexp |
---|
20 | INDEX |
---|
21 | ldexpf |
---|
22 | |
---|
23 | SYNOPSIS |
---|
24 | #include <math.h> |
---|
25 | double ldexp(double <[val]>, int <[exp]>); |
---|
26 | float ldexpf(float <[val]>, int <[exp]>); |
---|
27 | |
---|
28 | DESCRIPTION |
---|
29 | <<ldexp>> calculates the value |
---|
30 | @ifnottex |
---|
31 | <[val]> times 2 to the power <[exp]>. |
---|
32 | @end ifnottex |
---|
33 | @tex |
---|
34 | $val\times 2^{exp}$. |
---|
35 | @end tex |
---|
36 | <<ldexpf>> is identical, save that it takes and returns <<float>> |
---|
37 | rather than <<double>> values. |
---|
38 | |
---|
39 | RETURNS |
---|
40 | <<ldexp>> returns the calculated value. |
---|
41 | |
---|
42 | Underflow and overflow both set <<errno>> to <<ERANGE>>. |
---|
43 | On underflow, <<ldexp>> and <<ldexpf>> return 0.0. |
---|
44 | On overflow, <<ldexp>> returns plus or minus <<HUGE_VAL>>. |
---|
45 | |
---|
46 | PORTABILITY |
---|
47 | <<ldexp>> is ANSI. <<ldexpf>> is an extension. |
---|
48 | |
---|
49 | */ |
---|
50 | |
---|
51 | #include "fdlibm.h" |
---|
52 | #include <errno.h> |
---|
53 | |
---|
54 | #ifndef _DOUBLE_IS_32BITS |
---|
55 | |
---|
56 | #ifdef __STDC__ |
---|
57 | double ldexp(double value, int exp) |
---|
58 | #else |
---|
59 | double ldexp(value, exp) |
---|
60 | double value; int exp; |
---|
61 | #endif |
---|
62 | { |
---|
63 | if(!finite(value)||value==0.0) return value; |
---|
64 | value = scalbn(value,exp); |
---|
65 | if(!finite(value)||value==0.0) errno = ERANGE; |
---|
66 | return value; |
---|
67 | } |
---|
68 | |
---|
69 | #endif /* _DOUBLE_IS_32BITS */ |
---|