Staging: rtl81xx: Fix build problems when CONFIG_CRYPTO=n
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m68k / math-emu / fp_log.c
blob367ecee2f981db6a5763ed4ac69452f20afbd79d
1 /*
3 fp_trig.c: floating-point math routines for the Linux-m68k
4 floating point emulator.
6 Copyright (c) 1998-1999 David Huggins-Daines / Roman Zippel.
8 I hereby give permission, free of charge, to copy, modify, and
9 redistribute this software, in source or binary form, provided that
10 the above copyright notice and the following disclaimer are included
11 in all such copies.
13 THIS SOFTWARE IS PROVIDED "AS IS", WITH ABSOLUTELY NO WARRANTY, REAL
14 OR IMPLIED.
18 #include "fp_emu.h"
20 static const struct fp_ext fp_one =
22 .exp = 0x3fff,
25 extern struct fp_ext *fp_fadd(struct fp_ext *dest, const struct fp_ext *src);
26 extern struct fp_ext *fp_fdiv(struct fp_ext *dest, const struct fp_ext *src);
28 struct fp_ext *
29 fp_fsqrt(struct fp_ext *dest, struct fp_ext *src)
31 struct fp_ext tmp, src2;
32 int i, exp;
34 dprint(PINSTR, "fsqrt\n");
36 fp_monadic_check(dest, src);
38 if (IS_ZERO(dest))
39 return dest;
41 if (dest->sign) {
42 fp_set_nan(dest);
43 return dest;
45 if (IS_INF(dest))
46 return dest;
49 * sqrt(m) * 2^(p) , if e = 2*p
50 * sqrt(m*2^e) =
51 * sqrt(2*m) * 2^(p) , if e = 2*p + 1
53 * So we use the last bit of the exponent to decide wether to
54 * use the m or 2*m.
56 * Since only the fractional part of the mantissa is stored and
57 * the integer part is assumed to be one, we place a 1 or 2 into
58 * the fixed point representation.
60 exp = dest->exp;
61 dest->exp = 0x3FFF;
62 if (!(exp & 1)) /* lowest bit of exponent is set */
63 dest->exp++;
64 fp_copy_ext(&src2, dest);
67 * The taylor row around a for sqrt(x) is:
68 * sqrt(x) = sqrt(a) + 1/(2*sqrt(a))*(x-a) + R
69 * With a=1 this gives:
70 * sqrt(x) = 1 + 1/2*(x-1)
71 * = 1/2*(1+x)
73 fp_fadd(dest, &fp_one);
74 dest->exp--; /* * 1/2 */
77 * We now apply the newton rule to the function
78 * f(x) := x^2 - r
79 * which has a null point on x = sqrt(r).
81 * It gives:
82 * x' := x - f(x)/f'(x)
83 * = x - (x^2 -r)/(2*x)
84 * = x - (x - r/x)/2
85 * = (2*x - x + r/x)/2
86 * = (x + r/x)/2
88 for (i = 0; i < 9; i++) {
89 fp_copy_ext(&tmp, &src2);
91 fp_fdiv(&tmp, dest);
92 fp_fadd(dest, &tmp);
93 dest->exp--;
96 dest->exp += (exp - 0x3FFF) / 2;
98 return dest;
101 struct fp_ext *
102 fp_fetoxm1(struct fp_ext *dest, struct fp_ext *src)
104 uprint("fetoxm1\n");
106 fp_monadic_check(dest, src);
108 if (IS_ZERO(dest))
109 return dest;
111 return dest;
114 struct fp_ext *
115 fp_fetox(struct fp_ext *dest, struct fp_ext *src)
117 uprint("fetox\n");
119 fp_monadic_check(dest, src);
121 return dest;
124 struct fp_ext *
125 fp_ftwotox(struct fp_ext *dest, struct fp_ext *src)
127 uprint("ftwotox\n");
129 fp_monadic_check(dest, src);
131 return dest;
134 struct fp_ext *
135 fp_ftentox(struct fp_ext *dest, struct fp_ext *src)
137 uprint("ftentox\n");
139 fp_monadic_check(dest, src);
141 return dest;
144 struct fp_ext *
145 fp_flogn(struct fp_ext *dest, struct fp_ext *src)
147 uprint("flogn\n");
149 fp_monadic_check(dest, src);
151 return dest;
154 struct fp_ext *
155 fp_flognp1(struct fp_ext *dest, struct fp_ext *src)
157 uprint("flognp1\n");
159 fp_monadic_check(dest, src);
161 return dest;
164 struct fp_ext *
165 fp_flog10(struct fp_ext *dest, struct fp_ext *src)
167 uprint("flog10\n");
169 fp_monadic_check(dest, src);
171 return dest;
174 struct fp_ext *
175 fp_flog2(struct fp_ext *dest, struct fp_ext *src)
177 uprint("flog2\n");
179 fp_monadic_check(dest, src);
181 return dest;
184 struct fp_ext *
185 fp_fgetexp(struct fp_ext *dest, struct fp_ext *src)
187 dprint(PINSTR, "fgetexp\n");
189 fp_monadic_check(dest, src);
191 if (IS_INF(dest)) {
192 fp_set_nan(dest);
193 return dest;
195 if (IS_ZERO(dest))
196 return dest;
198 fp_conv_long2ext(dest, (int)dest->exp - 0x3FFF);
200 fp_normalize_ext(dest);
202 return dest;
205 struct fp_ext *
206 fp_fgetman(struct fp_ext *dest, struct fp_ext *src)
208 dprint(PINSTR, "fgetman\n");
210 fp_monadic_check(dest, src);
212 if (IS_ZERO(dest))
213 return dest;
215 if (IS_INF(dest))
216 return dest;
218 dest->exp = 0x3FFF;
220 return dest;