1 | |
---|
2 | /* @(#)w_log10.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 | <<log10>>, <<log10f>>---base 10 logarithms |
---|
17 | |
---|
18 | INDEX |
---|
19 | log10 |
---|
20 | INDEX |
---|
21 | log10f |
---|
22 | |
---|
23 | SYNOPSIS |
---|
24 | #include <math.h> |
---|
25 | double log10(double <[x]>); |
---|
26 | float log10f(float <[x]>); |
---|
27 | |
---|
28 | DESCRIPTION |
---|
29 | <<log10>> returns the base 10 logarithm of <[x]>. |
---|
30 | It is implemented as <<log(<[x]>) / log(10)>>. |
---|
31 | |
---|
32 | <<log10f>> is identical, save that it takes and returns <<float>> values. |
---|
33 | |
---|
34 | RETURNS |
---|
35 | <<log10>> and <<log10f>> return the calculated value. |
---|
36 | |
---|
37 | See the description of <<log>> for information on errors. |
---|
38 | |
---|
39 | PORTABILITY |
---|
40 | <<log10>> is ANSI C. <<log10f>> is an extension. |
---|
41 | |
---|
42 | */ |
---|
43 | |
---|
44 | /* |
---|
45 | * wrapper log10(X) |
---|
46 | */ |
---|
47 | |
---|
48 | #include "fdlibm.h" |
---|
49 | #include <errno.h> |
---|
50 | |
---|
51 | #ifndef _DOUBLE_IS_32BITS |
---|
52 | |
---|
53 | #ifdef __STDC__ |
---|
54 | double log10(double x) /* wrapper log10 */ |
---|
55 | #else |
---|
56 | double log10(x) /* wrapper log10 */ |
---|
57 | double x; |
---|
58 | #endif |
---|
59 | { |
---|
60 | #ifdef _IEEE_LIBM |
---|
61 | return __ieee754_log10(x); |
---|
62 | #else |
---|
63 | double z; |
---|
64 | struct exception exc; |
---|
65 | z = __ieee754_log10(x); |
---|
66 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; |
---|
67 | if(x<=0.0) { |
---|
68 | #ifndef HUGE_VAL |
---|
69 | #define HUGE_VAL inf |
---|
70 | double inf = 0.0; |
---|
71 | |
---|
72 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
---|
73 | #endif |
---|
74 | exc.name = "log10"; |
---|
75 | exc.err = 0; |
---|
76 | exc.arg1 = x; |
---|
77 | exc.arg2 = x; |
---|
78 | if (_LIB_VERSION == _SVID_) |
---|
79 | exc.retval = -HUGE; |
---|
80 | else |
---|
81 | exc.retval = -HUGE_VAL; |
---|
82 | if(x==0.0) { |
---|
83 | /* log10(0) */ |
---|
84 | exc.type = SING; |
---|
85 | if (_LIB_VERSION == _POSIX_) |
---|
86 | errno = ERANGE; |
---|
87 | else if (!matherr(&exc)) { |
---|
88 | errno = ERANGE; |
---|
89 | } |
---|
90 | } else { |
---|
91 | /* log10(x<0) */ |
---|
92 | exc.type = DOMAIN; |
---|
93 | if (_LIB_VERSION == _POSIX_) |
---|
94 | errno = EDOM; |
---|
95 | else if (!matherr(&exc)) { |
---|
96 | errno = EDOM; |
---|
97 | } |
---|
98 | exc.retval = nan(""); |
---|
99 | } |
---|
100 | if (exc.err != 0) |
---|
101 | errno = exc.err; |
---|
102 | return exc.retval; |
---|
103 | } else |
---|
104 | return z; |
---|
105 | #endif |
---|
106 | } |
---|
107 | |
---|
108 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|