childs -> children.
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesplog10.c
blob5a392c301d30f851b0025a78cf273573fe8937e6
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathieeesingtrans_intern.h"
8 /*
9 FUNCTION
10 Calculate logarithm (base 10) of the given IEEE single precision number
12 RESULT
13 IEEE single precision number
15 flags:
16 zero : result is zero
17 negative : result is negative
18 overflow : argument was negative
20 NOTES
22 EXAMPLE
24 BUGS
26 SEE ALSO
28 INTERNALS
29 ALGORITHM:
31 If the Argument is negative set overflow-flag and return 0.
32 If the Argument is 0 return 0xffffffff.
34 All other cases:
36 (ld is the logarithm with base 2)
37 (log is the logarithm with base 10)
38 y = M * 2^E
40 <code>
41 log y = log ( M * 2^E ) =
43 = log M + log 2^E =
45 = log M + E * log (2) =
47 ld M ld 2
48 = ----- + E * ----- = [ld 2 = 1]
49 ld 10 ld 10
51 ld M + E
52 = --------
53 ld 10
54 </code>
56 ld 10 can be precalculated, of course.
57 For calculating ld M see file intern_ieeespld.c
59 HISTORY
62 AROS_LH1(float, IEEESPLog10,
63 AROS_LHA(float, y, D0),
64 struct Library *, MathIeeeSingTransBase, 21, MathIeeeSingTrans
67 AROS_LIBFUNC_INIT
69 LONG ld_M, Exponent, Mask = 0x40, i, Sign;
71 /* check for negative sign */
72 if ( y < 0)
74 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
75 return 0;
78 /* check for argument == 0 or argument == +infinity */
79 if (0 == y || IEEESP_Pinfty == y) return y;
81 /* convert the Exponent of the argument (y) to the ieeesp-format */
82 Exponent = ((y & IEEESPExponent_Mask) >> 23) - 0x7e ;
84 if (Exponent < 0 )
86 Exponent =-Exponent;
87 Sign = IEEESPSign_Mask;
89 else
91 Sign = 0;
93 /* find the number of the highest set bit in the exponent */
94 if (Exponent != 0)
96 i = 0;
97 while ( (Mask & Exponent) == 0)
99 i ++;
100 Mask >>= 1;
103 Exponent <<= (17 + i);
104 Exponent &= IEEESPMantisse_Mask;
105 Exponent |= ((0x85 - i ) << 23);
106 Exponent |= Sign;
109 ld_M = intern_IEEESPLd((y & IEEESPMantisse_Mask) | 0x3f000000);
112 ld M + E
113 log(fnum1) = --------
114 ld 10
117 return IEEESPMul( IEEESPAdd(ld_M, Exponent), InvLd10);
119 AROS_LIBFUNC_EXIT