Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / mathieeesingtrans / ieeesplog.c
blobef6bae9675ecbd19d612857643bf9dc0eb13cc2e
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 e) 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 (ln is the logarithm with base e)
38 y = M * 2^E
40 <code>
41 ln y = ln ( M * 2^E ) =
43 = ln M + ln 2^E =
45 = ln M + E * ln (2) =
47 ld M ld 2
48 = ----- + E * ----- = [ld 2 = 1]
49 ld e ld e
51 ld M + E
52 = --------
53 ld e
54 </code>
56 ld e can be precalculated, of course.
57 For calculating ld M see file intern_ieeespld.c
59 HISTORY
62 AROS_LH1(float, IEEESPLog,
63 AROS_LHA(float, y, D0),
64 struct Library *, MathIeeeSingTransBase, 14, 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;
94 /* find the number of the highest set bit in the exponent */
95 if (Exponent != 0)
97 i = 0;
98 while ( (Mask & Exponent) == 0)
100 i ++;
101 Mask >>= 1;
104 Exponent <<= (17 + i);
105 Exponent &= IEEESPMantisse_Mask;
106 Exponent |= ((0x85 - i ) << 23);
107 Exponent |= Sign;
110 ld_M = intern_IEEESPLd((y & IEEESPMantisse_Mask) | 0x3f000000);
113 ld M + E
114 ln(fnum1) = --------
115 ld e
118 return IEEESPMul( IEEESPAdd(ld_M, Exponent), InvLde);
120 AROS_LIBFUNC_EXIT