1 /* Math functions for i387.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 double atan (double __x
);
24 double atan2 (double __y
, double __x
);
25 double ceil (double __x
);
26 double cos (double __x
);
27 double fabs (double __x
);
28 double floor (double __x
);
29 long _ftol (double fl
);
30 double log (double __x
);
31 double __log2 (double __x
);
32 double pow (double __x
, double __y
);
33 double sin (double __x
);
34 double sqrt (double __x
);
35 double tan (double __x
);
38 double atan (double __x
)
40 register double __value
;
44 : "=t" (__value
) : "0" (__x
));
49 double atan2 (double __y
, double __x
)
51 register double __value
;
55 : "=t" (__value
) : "0" (__x
), "u" (__y
));
60 double ceil (double __x
)
62 register double __value
;
63 __volatile
unsigned short int __cw
, __cwtmp
;
65 __asm
__volatile ("fnstcw %0" : "=m" (__cw
));
66 __cwtmp
= (__cw
& 0xf3ff) | 0x0800; /* rounding up */
67 __asm
__volatile ("fldcw %0" : : "m" (__cwtmp
));
68 __asm
__volatile ("frndint" : "=t" (__value
) : "0" (__x
));
69 __asm
__volatile ("fldcw %0" : : "m" (__cw
));
74 double cos (double __x
)
76 register double __value
;
79 : "=t" (__value
): "0" (__x
));
84 double fabs (double __x
)
86 register double __value
;
89 : "=t" (__value
) : "0" (__x
));
94 double floor (double __x
)
96 register double __value
;
97 __volatile
unsigned short int __cw
, __cwtmp
;
99 __asm
__volatile ("fnstcw %0" : "=m" (__cw
));
100 __cwtmp
= (__cw
& 0xf3ff) | 0x0400; /* rounding down */
101 __asm
__volatile ("fldcw %0" : : "m" (__cwtmp
));
102 __asm
__volatile ("frndint" : "=t" (__value
) : "0" (__x
));
103 __asm
__volatile ("fldcw %0" : : "m" (__cw
));
108 long _ftol (double fl
)
113 double log (double __x
)
115 register double __value
;
120 : "=t" (__value
) : "0" (__x
));
125 double __log2 (double __x
)
127 register double __value
;
132 : "=t" (__value
) : "0" (__x
));
137 double pow (double __x
, double __y
)
139 register double __value
, __exponent
;
140 long __p
= (long) __y
;
142 if (__x
== 0.0 && __y
> 0.0)
144 if (__y
== (double) __p
)
166 ("fmul %%st(1) # y * log2(x)\n\t"
168 "frndint # int(y * log2(x))\n\t"
170 "fsub %%st(1) # fract(y * log2(x))\n\t"
171 "f2xm1 # 2^(fract(y * log2(x))) - 1\n\t"
172 : "=t" (__value
), "=u" (__exponent
) : "0" (__log2 (__x
)), "1" (__y
));
176 : "=t" (__value
) : "0" (__value
), "u" (__exponent
));
181 double sin (double __x
)
183 register double __value
;
186 : "=t" (__value
) : "0" (__x
));
191 double sqrt (double __x
)
193 register double __value
;
196 : "=t" (__value
) : "0" (__x
));
201 double tan (double __x
)
203 register double __value
;
204 register double __value2
__attribute__ ((unused
));
207 : "=t" (__value2
), "=u" (__value
) : "0" (__x
));
212 //FIXME! Is there a better algorithm. like FT_MulDiv
213 INT STDCALL
EngMulDiv(
218 #if SIZEOF_LONG_LONG >= 8
221 if (!nDivisor
) return -1;
223 /* We want to deal with a positive divisor to simplify the logic. */
226 nMultiplicand
= - nMultiplicand
;
227 nDivisor
= -nDivisor
;
230 /* If the result is positive, we "add" to round. else, we subtract to round. */
231 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
232 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
233 ret
= (((long long)nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
235 ret
= (((long long)nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;
237 if ((ret
> 2147483647) || (ret
< -2147483647)) return -1;
240 if (!nDivisor
) return -1;
242 /* We want to deal with a positive divisor to simplify the logic. */
245 nMultiplicand
= - nMultiplicand
;
246 nDivisor
= -nDivisor
;
249 /* If the result is positive, we "add" to round. else, we subtract to round. */
250 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
251 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
252 return ((nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
254 return ((nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;