alsa.audio: limit the supported frequencies to common set
[AROS.git] / workbench / libs / mathtrans / splog10.c
blob7669b0caf2744ea1b7ddadba8fe5f9e6a99b92e1
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "mathtrans_intern.h"
8 /*****************************************************************************
10 NAME */
12 AROS_LH1(float, SPLog10,
14 /* SYNOPSIS */
15 AROS_LHA(float, fnum1, D0),
17 /* LOCATION */
18 struct Library *, MathTransBase, 21, MathTrans)
20 /* FUNCTION
21 Calculate logarithm (base 10) of the given ffp number
23 INPUTS
25 RESULT
26 ffp number
28 flags:
29 zero : result is zero
30 negative : result is negative
31 overflow : argument was negative
33 BUGS
35 INTERNALS
36 ALGORITHM:
38 If the Argument is negative set overflow-flag and return 0.
39 If the Argument is 0 return 0xde5bd8fe.
41 All other cases:
43 (ld is the logarithm with base 2)
44 (log is the logarithm with base 10)
46 fnum1 = M * 2^E
48 log fnum1 = log ( M * 2^E ) =
50 = log M + log 2^E =
52 = log M + E * log (2) =
54 ld M ld 2
55 = ----- + E * ----- = [ld 2 = 1]
56 ld 10 ld 10
58 ld M + E
59 = --------
60 ld 10
62 ld 10 can be precalculated, of course.
63 For calculating ld M see file intern_spld.c
65 *****************************************************************************/
67 AROS_LIBFUNC_INIT
69 LONG ld_M, Exponent, Mask = 0x40, i, Sign;
71 /* check for negative sign */
72 if ((char) fnum1 < 0)
74 SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
75 return 0;
78 if (0 == fnum1) return 0xde5bd8fe; /* result of the orig. library */
80 /* convert the Exponent of the argument (fnum1) to the ffp-format */
81 Exponent = (fnum1 & FFPExponent_Mask) - 0x40;
82 if (Exponent < 0 )
84 Exponent = -Exponent;
85 Sign = FFPSign_Mask;
87 else
89 Sign = 0;
92 /* find the number of the highest set bit in the exponent */
93 if (Exponent != 0)
95 i = 0;
96 while ( (Mask & Exponent) == 0)
98 i ++;
99 Mask >>= 1;
102 Exponent <<= (25 + i);
103 Exponent |= (0x47 - i + Sign);
106 ld_M = intern_SPLd((fnum1 & FFPMantisse_Mask) | 0x40);
109 ld M + E
110 log(fnum1) = --------
111 ld 10
114 return SPMul( SPAdd(ld_M, Exponent), InvLd10);
116 AROS_LIBFUNC_EXIT