2 * msvcrt.dll math functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This 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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
24 #define __USE_ISOC9X 1
25 #define __USE_ISOC99 1
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
38 #define finitef(x) isfinite(x)
43 #define isnanf(x) isnan(x)
49 /* FIXME: Does not work with -NAN and -0. */
51 #define signbit(x) ((x) < 0)
54 typedef int (CDECL
*MSVCRT_matherr_func
)(struct MSVCRT__exception
*);
55 typedef double LDOUBLE
; /* long double is just a double */
57 static MSVCRT_matherr_func MSVCRT_default_matherr_func
= NULL
;
59 static BOOL sse2_supported
;
60 static BOOL sse2_enabled
;
62 void msvcrt_init_math(void)
64 sse2_supported
= sse2_enabled
= IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE
);
67 /*********************************************************************
68 * _set_SSE2_enable (MSVCRT.@)
70 int CDECL
MSVCRT__set_SSE2_enable(int flag
)
72 sse2_enabled
= flag
&& sse2_supported
;
77 /*********************************************************************
78 * _set_FMA3_enable (MSVCR120.@)
80 int CDECL
MSVCRT__set_FMA3_enable(int flag
)
82 FIXME("(%x) stub\n", flag
);
87 #if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
89 /*********************************************************************
90 * _chgsignf (MSVCRT.@)
92 float CDECL
MSVCRT__chgsignf( float num
)
94 /* FIXME: +-infinity,Nan not tested */
98 /*********************************************************************
99 * _copysignf (MSVCRT.@)
101 float CDECL
MSVCRT__copysignf( float num
, float sign
)
104 return signbit(num
) ? num
: -num
;
105 return signbit(num
) ? -num
: num
;
108 /*********************************************************************
109 * _nextafterf (MSVCRT.@)
111 float CDECL
MSVCRT__nextafterf( float num
, float next
)
113 if (!finitef(num
) || !finitef(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
114 return nextafterf( num
, next
);
118 #if defined(__x86_64__) || defined(__arm__)
120 /*********************************************************************
121 * _finitef (MSVCRT.@)
123 int CDECL
MSVCRT__finitef( float num
)
125 return finitef(num
) != 0; /* See comment for _isnan() */
128 /*********************************************************************
131 INT CDECL
MSVCRT__isnanf( float num
)
133 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
134 * Do the same, as the result may be used in calculations
136 return isnanf(num
) != 0;
139 /*********************************************************************
142 float CDECL
MSVCRT__logbf( float num
)
144 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
148 /*********************************************************************
149 * MSVCRT_acosf (MSVCRT.@)
151 float CDECL
MSVCRT_acosf( float x
)
153 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
154 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
155 * asin() uses a similar construction. This is bad because as x gets nearer to
156 * 1 the error in the expression "1 - x^2" can get relatively large due to
157 * cancellation. The sqrt() makes things worse. A safer way to calculate
158 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
159 return atan2f(sqrtf((1 - x
) * (1 + x
)), x
);
162 /*********************************************************************
163 * MSVCRT_asinf (MSVCRT.@)
165 float CDECL
MSVCRT_asinf( float x
)
167 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
168 return atan2f(x
, sqrtf((1 - x
) * (1 + x
)));
171 /*********************************************************************
172 * MSVCRT_atanf (MSVCRT.@)
174 float CDECL
MSVCRT_atanf( float x
)
176 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
180 /*********************************************************************
181 * MSVCRT_atan2f (MSVCRT.@)
183 float CDECL
MSVCRT_atan2f( float x
, float y
)
185 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
189 /*********************************************************************
190 * MSVCRT_cosf (MSVCRT.@)
192 float CDECL
MSVCRT_cosf( float x
)
194 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
198 /*********************************************************************
199 * MSVCRT_coshf (MSVCRT.@)
201 float CDECL
MSVCRT_coshf( float x
)
203 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
207 /*********************************************************************
208 * MSVCRT_expf (MSVCRT.@)
210 float CDECL
MSVCRT_expf( float x
)
212 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
216 /*********************************************************************
217 * MSVCRT_fmodf (MSVCRT.@)
219 float CDECL
MSVCRT_fmodf( float x
, float y
)
221 if (!finitef(x
) || !finitef(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
225 /*********************************************************************
226 * MSVCRT_logf (MSVCRT.@)
228 float CDECL
MSVCRT_logf( float x
)
230 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
231 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
235 /*********************************************************************
236 * MSVCRT_log10f (MSVCRT.@)
238 float CDECL
MSVCRT_log10f( float x
)
240 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
241 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
245 /*********************************************************************
246 * MSVCRT_powf (MSVCRT.@)
248 float CDECL
MSVCRT_powf( float x
, float y
)
250 /* FIXME: If x < 0 and y is not integral, set EDOM */
252 if (!finitef(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
256 /*********************************************************************
257 * MSVCRT_sinf (MSVCRT.@)
259 float CDECL
MSVCRT_sinf( float x
)
261 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
265 /*********************************************************************
266 * MSVCRT_sinhf (MSVCRT.@)
268 float CDECL
MSVCRT_sinhf( float x
)
270 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
274 /*********************************************************************
275 * MSVCRT_sqrtf (MSVCRT.@)
277 float CDECL
MSVCRT_sqrtf( float x
)
279 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
283 /*********************************************************************
284 * MSVCRT_tanf (MSVCRT.@)
286 float CDECL
MSVCRT_tanf( float x
)
288 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
292 /*********************************************************************
293 * MSVCRT_tanhf (MSVCRT.@)
295 float CDECL
MSVCRT_tanhf( float x
)
297 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
301 /*********************************************************************
304 float CDECL
MSVCRT_ceilf( float x
)
309 /*********************************************************************
312 float CDECL
MSVCRT_fabsf( float x
)
317 /*********************************************************************
320 float CDECL
MSVCRT_floorf( float x
)
325 /*********************************************************************
328 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
330 return frexpf( x
, exp
);
333 /*********************************************************************
336 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
338 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
339 return ldexpf(num
, power
);
342 /*********************************************************************
345 float CDECL
MSVCRT_modff( float x
, float *iptr
)
347 return modff( x
, iptr
);
352 /*********************************************************************
353 * MSVCRT_acos (MSVCRT.@)
355 double CDECL
MSVCRT_acos( double x
)
357 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
358 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
359 * asin() uses a similar construction. This is bad because as x gets nearer to
360 * 1 the error in the expression "1 - x^2" can get relatively large due to
361 * cancellation. The sqrt() makes things worse. A safer way to calculate
362 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
363 return atan2(sqrt((1 - x
) * (1 + x
)), x
);
366 /*********************************************************************
367 * MSVCRT_asin (MSVCRT.@)
369 double CDECL
MSVCRT_asin( double x
)
371 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
372 return atan2(x
, sqrt((1 - x
) * (1 + x
)));
375 /*********************************************************************
376 * MSVCRT_atan (MSVCRT.@)
378 double CDECL
MSVCRT_atan( double x
)
380 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
384 /*********************************************************************
385 * MSVCRT_atan2 (MSVCRT.@)
387 double CDECL
MSVCRT_atan2( double x
, double y
)
389 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
393 /*********************************************************************
394 * MSVCRT_cos (MSVCRT.@)
396 double CDECL
MSVCRT_cos( double x
)
398 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
402 /*********************************************************************
403 * MSVCRT_cosh (MSVCRT.@)
405 double CDECL
MSVCRT_cosh( double x
)
407 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
411 /*********************************************************************
412 * MSVCRT_exp (MSVCRT.@)
414 double CDECL
MSVCRT_exp( double x
)
416 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
420 /*********************************************************************
421 * MSVCRT_fmod (MSVCRT.@)
423 double CDECL
MSVCRT_fmod( double x
, double y
)
425 if (!isfinite(x
) || !isfinite(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
429 /*********************************************************************
430 * MSVCRT_log (MSVCRT.@)
432 double CDECL
MSVCRT_log( double x
)
434 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
435 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
439 /*********************************************************************
440 * MSVCRT_log10 (MSVCRT.@)
442 double CDECL
MSVCRT_log10( double x
)
444 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
445 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
449 /*********************************************************************
450 * MSVCRT_pow (MSVCRT.@)
452 double CDECL
MSVCRT_pow( double x
, double y
)
454 /* FIXME: If x < 0 and y is not integral, set EDOM */
456 if (!isfinite(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
460 /*********************************************************************
461 * MSVCRT_sin (MSVCRT.@)
463 double CDECL
MSVCRT_sin( double x
)
465 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
469 /*********************************************************************
470 * MSVCRT_sinh (MSVCRT.@)
472 double CDECL
MSVCRT_sinh( double x
)
474 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
478 /*********************************************************************
479 * MSVCRT_sqrt (MSVCRT.@)
481 double CDECL
MSVCRT_sqrt( double x
)
483 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
487 /*********************************************************************
488 * MSVCRT_tan (MSVCRT.@)
490 double CDECL
MSVCRT_tan( double x
)
492 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
496 /*********************************************************************
497 * MSVCRT_tanh (MSVCRT.@)
499 double CDECL
MSVCRT_tanh( double x
)
501 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
506 #if defined(__GNUC__) && defined(__i386__)
508 #define FPU_DOUBLE(var) double var; \
509 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
510 #define FPU_DOUBLES(var1,var2) double var1,var2; \
511 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
512 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
514 /*********************************************************************
517 double CDECL
_CIacos(void)
520 return MSVCRT_acos(x
);
523 /*********************************************************************
526 double CDECL
_CIasin(void)
529 return MSVCRT_asin(x
);
532 /*********************************************************************
535 double CDECL
_CIatan(void)
538 return MSVCRT_atan(x
);
541 /*********************************************************************
542 * _CIatan2 (MSVCRT.@)
544 double CDECL
_CIatan2(void)
547 return MSVCRT_atan2(x
,y
);
550 /*********************************************************************
553 double CDECL
_CIcos(void)
556 return MSVCRT_cos(x
);
559 /*********************************************************************
562 double CDECL
_CIcosh(void)
565 return MSVCRT_cosh(x
);
568 /*********************************************************************
571 double CDECL
_CIexp(void)
574 return MSVCRT_exp(x
);
577 /*********************************************************************
580 double CDECL
_CIfmod(void)
583 return MSVCRT_fmod(x
,y
);
586 /*********************************************************************
589 double CDECL
_CIlog(void)
592 return MSVCRT_log(x
);
595 /*********************************************************************
596 * _CIlog10 (MSVCRT.@)
598 double CDECL
_CIlog10(void)
601 return MSVCRT_log10(x
);
604 /*********************************************************************
607 double CDECL
_CIpow(void)
610 return MSVCRT_pow(x
,y
);
613 /*********************************************************************
616 double CDECL
_CIsin(void)
619 return MSVCRT_sin(x
);
622 /*********************************************************************
625 double CDECL
_CIsinh(void)
628 return MSVCRT_sinh(x
);
631 /*********************************************************************
634 double CDECL
_CIsqrt(void)
637 return MSVCRT_sqrt(x
);
640 /*********************************************************************
643 double CDECL
_CItan(void)
646 return MSVCRT_tan(x
);
649 /*********************************************************************
652 double CDECL
_CItanh(void)
655 return MSVCRT_tanh(x
);
658 /*********************************************************************
661 LONGLONG CDECL
MSVCRT__ftol(void)
667 #endif /* defined(__GNUC__) && defined(__i386__) */
669 /*********************************************************************
670 * _fpclass (MSVCRT.@)
672 int CDECL
MSVCRT__fpclass(double num
)
674 #if defined(HAVE_FPCLASS) || defined(fpclass)
675 switch (fpclass( num
))
678 case FP_SNAN
: return MSVCRT__FPCLASS_SNAN
;
681 case FP_QNAN
: return MSVCRT__FPCLASS_QNAN
;
684 case FP_NINF
: return MSVCRT__FPCLASS_NINF
;
687 case FP_PINF
: return MSVCRT__FPCLASS_PINF
;
690 case FP_NDENORM
: return MSVCRT__FPCLASS_ND
;
693 case FP_PDENORM
: return MSVCRT__FPCLASS_PD
;
696 case FP_NZERO
: return MSVCRT__FPCLASS_NZ
;
699 case FP_PZERO
: return MSVCRT__FPCLASS_PZ
;
702 case FP_NNORM
: return MSVCRT__FPCLASS_NN
;
705 case FP_PNORM
: return MSVCRT__FPCLASS_PN
;
707 default: return MSVCRT__FPCLASS_PN
;
709 #elif defined (fpclassify)
710 switch (fpclassify( num
))
712 case FP_NAN
: return MSVCRT__FPCLASS_QNAN
;
713 case FP_INFINITE
: return signbit(num
) ? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
714 case FP_SUBNORMAL
: return signbit(num
) ?MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
715 case FP_ZERO
: return signbit(num
) ? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
717 return signbit(num
) ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
720 return MSVCRT__FPCLASS_QNAN
;
721 return num
== 0.0 ? MSVCRT__FPCLASS_PZ
: (num
< 0 ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
);
725 /*********************************************************************
728 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
731 return (num
<< shift
) | (num
>> (32-shift
));
734 /*********************************************************************
737 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
740 return (num
<< shift
) | (num
>> (32-shift
));
743 /*********************************************************************
746 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
749 return (num
>> shift
) | (num
<< (32-shift
));
752 /*********************************************************************
755 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
758 return (num
>> shift
) | (num
<< (32-shift
));
761 /*********************************************************************
764 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
767 return (num
<< shift
) | (num
>> (64-shift
));
770 /*********************************************************************
773 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
776 return (num
>> shift
) | (num
<< (64-shift
));
779 /*********************************************************************
782 int CDECL
MSVCRT_abs( int n
)
784 return n
>= 0 ? n
: -n
;
787 /*********************************************************************
790 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
792 return n
>= 0 ? n
: -n
;
795 /*********************************************************************
798 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
800 return n
>= 0 ? n
: -n
;
803 /*********************************************************************
806 __int64 CDECL
_abs64( __int64 n
)
808 return n
>= 0 ? n
: -n
;
811 /*********************************************************************
814 double CDECL
MSVCRT__logb(double num
)
816 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
820 /*********************************************************************
823 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
825 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
826 return ldexp(num
, power
);
829 /*********************************************************************
832 double CDECL
_hypot(double x
, double y
)
834 /* FIXME: errno handling */
835 return hypot( x
, y
);
838 /*********************************************************************
841 float CDECL
MSVCRT__hypotf(float x
, float y
)
843 /* FIXME: errno handling */
844 return hypotf( x
, y
);
847 /*********************************************************************
850 double CDECL
MSVCRT_ceil( double x
)
855 /*********************************************************************
858 double CDECL
MSVCRT_floor( double x
)
863 /*********************************************************************
866 double CDECL
MSVCRT_fabs( double x
)
871 /*********************************************************************
874 double CDECL
MSVCRT_frexp( double x
, int *exp
)
876 return frexp( x
, exp
);
879 /*********************************************************************
882 double CDECL
MSVCRT_modf( double x
, double *iptr
)
884 return modf( x
, iptr
);
887 /*********************************************************************
888 * _matherr (MSVCRT.@)
890 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
893 TRACE("(%p = %d, %s, %g %g %g)\n",e
, e
->type
, e
->name
, e
->arg1
, e
->arg2
,
897 if (MSVCRT_default_matherr_func
)
898 return MSVCRT_default_matherr_func(e
);
899 ERR(":Unhandled math error!\n");
903 /*********************************************************************
904 * __setusermatherr (MSVCRT.@)
906 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
908 MSVCRT_default_matherr_func
= func
;
909 TRACE(":new matherr handler %p\n", func
);
912 /**********************************************************************
913 * _statusfp2 (MSVCRT.@)
915 * Not exported by native msvcrt, added in msvcr80.
917 #if defined(__i386__) || defined(__x86_64__)
918 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
922 unsigned long fpword
;
926 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
928 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
929 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
930 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
931 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
932 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
933 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
937 if (!sse2_sw
) return;
941 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
943 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
944 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
945 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
946 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
947 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
948 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
953 FIXME( "not implemented\n" );
958 /**********************************************************************
959 * _statusfp (MSVCRT.@)
961 unsigned int CDECL
_statusfp(void)
963 #if defined(__i386__) || defined(__x86_64__)
964 unsigned int x86_sw
, sse2_sw
;
966 _statusfp2( &x86_sw
, &sse2_sw
);
967 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
968 return x86_sw
| sse2_sw
;
970 FIXME( "not implemented\n" );
975 /*********************************************************************
976 * _clearfp (MSVCRT.@)
978 unsigned int CDECL
_clearfp(void)
980 unsigned int flags
= 0;
981 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
982 unsigned long fpword
;
984 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
985 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
986 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
987 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
988 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
989 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
990 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
994 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
995 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
996 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
997 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
998 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
999 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1000 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1002 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1005 FIXME( "not implemented\n" );
1010 /*********************************************************************
1011 * __fpecode (MSVCRT.@)
1013 int * CDECL
__fpecode(void)
1015 return &msvcrt_get_thread_data()->fpecode
;
1018 /*********************************************************************
1021 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1023 double z
= ldexp(num
,exp
);
1026 *MSVCRT__errno() = MSVCRT_ERANGE
;
1027 else if (z
== 0 && signbit(z
))
1028 z
= 0.0; /* Convert -0 -> +0 */
1032 /*********************************************************************
1035 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1037 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1040 /*********************************************************************
1041 * _chgsign (MSVCRT.@)
1043 double CDECL
MSVCRT__chgsign(double num
)
1045 /* FIXME: +-infinity,Nan not tested */
1049 /*********************************************************************
1050 * __control87_2 (MSVCRT.@)
1052 * Not exported by native msvcrt, added in msvcr80.
1054 #if defined(__i386__) || defined(__x86_64__)
1055 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1056 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1059 unsigned long fpword
;
1064 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1066 /* Convert into mask constants */
1068 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1069 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1070 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1071 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1072 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1073 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1074 switch (fpword
& 0xc00)
1076 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1077 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1078 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1080 switch (fpword
& 0x300)
1082 case 0x0: flags
|= MSVCRT__PC_24
; break;
1083 case 0x200: flags
|= MSVCRT__PC_53
; break;
1084 case 0x300: flags
|= MSVCRT__PC_64
; break;
1086 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1088 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1091 flags
= (flags
& ~mask
) | (newval
& mask
);
1093 /* Convert (masked) value back to fp word */
1095 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1096 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1097 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1098 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1099 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1100 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1101 switch (flags
& MSVCRT__MCW_RC
)
1103 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1104 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1105 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1107 switch (flags
& MSVCRT__MCW_PC
)
1109 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1110 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1111 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1113 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1115 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1120 if (!sse2_cw
) return 1;
1124 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1126 /* Convert into mask constants */
1128 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1129 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1130 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1131 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1132 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1133 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1134 switch (fpword
& 0x6000)
1136 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1137 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1138 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1140 switch (fpword
& 0x8040)
1142 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1143 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1144 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1147 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1150 flags
= (flags
& ~mask
) | (newval
& mask
);
1152 /* Convert (masked) value back to fp word */
1154 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1155 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1156 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1157 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1158 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1159 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1160 switch (flags
& MSVCRT__MCW_RC
)
1162 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1163 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1164 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1166 switch (flags
& MSVCRT__MCW_DN
)
1168 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1169 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1170 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1172 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1180 FIXME( "not implemented\n" );
1186 /*********************************************************************
1187 * _control87 (MSVCRT.@)
1189 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1191 #if defined(__i386__) || defined(__x86_64__)
1192 unsigned int x86_cw
, sse2_cw
;
1194 __control87_2( newval
, mask
, &x86_cw
, &sse2_cw
);
1196 if ((x86_cw
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) x86_cw
|= MSVCRT__EM_AMBIGUOUS
;
1199 FIXME( "not implemented\n" );
1204 /*********************************************************************
1205 * _controlfp (MSVCRT.@)
1207 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
1209 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
1212 /*********************************************************************
1213 * _set_controlfp (MSVCRT.@)
1215 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
1217 _controlfp( newval
, mask
);
1220 /*********************************************************************
1221 * _controlfp_s (MSVCRT.@)
1223 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
1225 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
1226 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
1229 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
1231 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
1232 return MSVCRT_EINVAL
;
1234 val
= _controlfp( newval
, mask
);
1235 if (cur
) *cur
= val
;
1239 /*********************************************************************
1240 * _copysign (MSVCRT.@)
1242 double CDECL
MSVCRT__copysign(double num
, double sign
)
1245 return signbit(num
) ? num
: -num
;
1246 return signbit(num
) ? -num
: num
;
1249 /*********************************************************************
1250 * _finite (MSVCRT.@)
1252 int CDECL
MSVCRT__finite(double num
)
1254 return isfinite(num
) != 0; /* See comment for _isnan() */
1257 /*********************************************************************
1258 * _fpreset (MSVCRT.@)
1260 void CDECL
_fpreset(void)
1262 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1263 const unsigned int x86_cw
= 0x27f;
1264 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
1267 const unsigned long sse2_cw
= 0x1f80;
1268 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
1271 FIXME( "not implemented\n" );
1275 /*********************************************************************
1278 INT CDECL
MSVCRT__isnan(double num
)
1280 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1281 * Do the same, as the result may be used in calculations
1283 return isnan(num
) != 0;
1286 /*********************************************************************
1289 double CDECL
MSVCRT__j0(double num
)
1291 /* FIXME: errno handling */
1295 /*********************************************************************
1298 double CDECL
MSVCRT__j1(double num
)
1300 /* FIXME: errno handling */
1304 /*********************************************************************
1307 double CDECL
MSVCRT__jn(int n
, double num
)
1309 /* FIXME: errno handling */
1313 /*********************************************************************
1316 double CDECL
MSVCRT__y0(double num
)
1319 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1321 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1323 *MSVCRT__errno() = MSVCRT_EDOM
;
1329 /*********************************************************************
1332 double CDECL
MSVCRT__y1(double num
)
1335 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1337 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1339 *MSVCRT__errno() = MSVCRT_EDOM
;
1345 /*********************************************************************
1348 double CDECL
MSVCRT__yn(int order
, double num
)
1351 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1352 retval
= yn(order
,num
);
1353 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1355 *MSVCRT__errno() = MSVCRT_EDOM
;
1361 /*********************************************************************
1362 * _nextafter (MSVCRT.@)
1364 double CDECL
MSVCRT__nextafter(double num
, double next
)
1367 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1368 retval
= nextafter(num
,next
);
1372 /*********************************************************************
1375 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
1378 thread_data_t
*data
= msvcrt_get_thread_data();
1379 /* FIXME: check better for overflow (native supports over 300 chars) */
1380 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
1381 * 4 for exponent and one for
1382 * terminating '\0' */
1383 if (!data
->efcvt_buffer
)
1384 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1391 /* handle cases with zero ndigits or less */
1393 if( prec
< 1) prec
= 2;
1394 len
= snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
1395 /* take the decimal "point away */
1397 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
1398 /* take the exponential "e" out */
1399 data
->efcvt_buffer
[ prec
] = '\0';
1400 /* read the exponent */
1401 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
1403 /* adjust for some border cases */
1404 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
1406 /* handle cases with zero ndigits or less */
1408 if( data
->efcvt_buffer
[ 0] >= '5')
1410 data
->efcvt_buffer
[ 0] = '\0';
1412 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
1413 return data
->efcvt_buffer
;
1416 /*********************************************************************
1417 * _ecvt_s (MSVCRT.@)
1419 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
1423 const char infret
[] = "1#INF";
1425 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
1426 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
1427 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
1428 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1429 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1431 /* special case - inf */
1432 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
1434 memset(buffer
, '0', ndigits
);
1435 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
1436 buffer
[ndigits
] = '\0';
1438 if(number
== -HUGE_VAL
)
1444 /* handle cases with zero ndigits or less */
1446 if( prec
< 1) prec
= 2;
1447 result
= MSVCRT_malloc(prec
+ 7);
1454 len
= snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
1455 /* take the decimal "point away */
1457 memmove( result
+ 1, result
+ 2, len
- 1 );
1458 /* take the exponential "e" out */
1459 result
[ prec
] = '\0';
1460 /* read the exponent */
1461 sscanf( result
+ prec
+ 1, "%d", decpt
);
1463 /* adjust for some border cases */
1464 if( result
[0] == '0')/* value is zero */
1466 /* handle cases with zero ndigits or less */
1468 if( result
[ 0] >= '5')
1472 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
1473 MSVCRT_free( result
);
1477 /***********************************************************************
1480 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
1482 thread_data_t
*data
= msvcrt_get_thread_data();
1483 int stop
, dec1
, dec2
;
1484 char *ptr1
, *ptr2
, *first
;
1485 char buf
[80]; /* ought to be enough */
1487 if (!data
->efcvt_buffer
)
1488 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1496 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1498 ptr2
= data
->efcvt_buffer
;
1503 /* For numbers below the requested resolution, work out where
1504 the decimal point will be rather than finding it in the string */
1505 if (number
< 1.0 && number
> 0.0) {
1506 dec2
= log10(number
+ 1e-10);
1507 if (-dec2
<= ndigits
) dec2
= 0;
1510 /* If requested digits is zero or less, we will need to truncate
1511 * the returned string */
1513 stop
= strlen(buf
) + ndigits
;
1518 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1519 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1520 if (!first
) first
= ptr2
;
1521 if ((ptr1
- buf
) < stop
) {
1532 while (*ptr1
== '0') { /* Process leading zeroes */
1537 while (*ptr1
!= '\0') {
1538 if (!first
) first
= ptr2
;
1545 /* We never found a non-zero digit, then our number is either
1546 * smaller than the requested precision, or 0.0 */
1551 first
= data
->efcvt_buffer
;
1556 *decpt
= dec2
? dec2
: dec1
;
1560 /***********************************************************************
1561 * _fcvt_s (MSVCRT.@)
1563 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
1565 int stop
, dec1
, dec2
;
1566 char *ptr1
, *ptr2
, *first
;
1567 char buf
[80]; /* ought to be enough */
1569 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
1571 *MSVCRT__errno() = MSVCRT_EINVAL
;
1572 return MSVCRT_EINVAL
;
1581 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1588 /* For numbers below the requested resolution, work out where
1589 the decimal point will be rather than finding it in the string */
1590 if (number
< 1.0 && number
> 0.0) {
1591 dec2
= log10(number
+ 1e-10);
1592 if (-dec2
<= ndigits
) dec2
= 0;
1595 /* If requested digits is zero or less, we will need to truncate
1596 * the returned string */
1598 stop
= strlen(buf
) + ndigits
;
1603 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1604 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1605 if (!first
) first
= ptr2
;
1606 if ((ptr1
- buf
) < stop
) {
1620 while (*ptr1
== '0') { /* Process leading zeroes */
1621 if (number
== 0.0 && size
> 1) {
1629 while (*ptr1
!= '\0') {
1630 if (!first
) first
= ptr2
;
1640 /* We never found a non-zero digit, then our number is either
1641 * smaller than the requested precision, or 0.0 */
1642 if (!first
&& (number
<= 0.0))
1645 *decpt
= dec2
? dec2
: dec1
;
1649 /***********************************************************************
1652 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
1655 *MSVCRT__errno() = MSVCRT_EINVAL
;
1660 *MSVCRT__errno() = MSVCRT_ERANGE
;
1664 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
1668 /***********************************************************************
1669 * _gcvt_s (MSVCRT.@)
1671 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
1676 *MSVCRT__errno() = MSVCRT_EINVAL
;
1677 return MSVCRT_EINVAL
;
1680 if( digits
<0 || digits
>=size
) {
1684 *MSVCRT__errno() = MSVCRT_ERANGE
;
1685 return MSVCRT_ERANGE
;
1688 len
= MSVCRT__scprintf("%.*g", digits
, number
);
1691 *MSVCRT__errno() = MSVCRT_ERANGE
;
1692 return MSVCRT_ERANGE
;
1695 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
1699 #include <stdlib.h> /* div_t, ldiv_t */
1701 /*********************************************************************
1704 * [i386] Windows binary compatible - returns the struct in eax/edx.
1707 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
1709 div_t dt
= div(num
,denom
);
1710 return ((unsigned __int64
)dt
.rem
<< 32) | (unsigned int)dt
.quot
;
1713 /*********************************************************************
1716 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1718 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
1720 div_t dt
= div(num
,denom
);
1728 #endif /* ifdef __i386__ */
1731 /*********************************************************************
1734 * [i386] Windows binary compatible - returns the struct in eax/edx.
1737 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1739 ldiv_t ldt
= ldiv(num
,denom
);
1740 return ((unsigned __int64
)ldt
.rem
<< 32) | (MSVCRT_ulong
)ldt
.quot
;
1743 /*********************************************************************
1746 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1748 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1750 ldiv_t result
= ldiv(num
,denom
);
1753 ret
.quot
= result
.quot
;
1754 ret
.rem
= result
.rem
;
1758 #endif /* ifdef __i386__ */
1762 /*********************************************************************
1763 * _adjust_fdiv (MSVCRT.@)
1764 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1766 int MSVCRT__adjust_fdiv
= 0;
1768 /***********************************************************************
1769 * _adj_fdiv_m16i (MSVCRT.@)
1772 * I _think_ this function is intended to work around the Pentium
1775 void __stdcall
_adj_fdiv_m16i( short arg
)
1777 TRACE("(): stub\n");
1780 /***********************************************************************
1781 * _adj_fdiv_m32 (MSVCRT.@)
1784 * I _think_ this function is intended to work around the Pentium
1787 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
1789 TRACE("(): stub\n");
1792 /***********************************************************************
1793 * _adj_fdiv_m32i (MSVCRT.@)
1796 * I _think_ this function is intended to work around the Pentium
1799 void __stdcall
_adj_fdiv_m32i( int arg
)
1801 TRACE("(): stub\n");
1804 /***********************************************************************
1805 * _adj_fdiv_m64 (MSVCRT.@)
1808 * I _think_ this function is intended to work around the Pentium
1811 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
1813 TRACE("(): stub\n");
1816 /***********************************************************************
1817 * _adj_fdiv_r (MSVCRT.@)
1819 * This function is likely to have the wrong number of arguments.
1822 * I _think_ this function is intended to work around the Pentium
1825 void _adj_fdiv_r(void)
1827 TRACE("(): stub\n");
1830 /***********************************************************************
1831 * _adj_fdivr_m16i (MSVCRT.@)
1834 * I _think_ this function is intended to work around the Pentium
1837 void __stdcall
_adj_fdivr_m16i( short arg
)
1839 TRACE("(): stub\n");
1842 /***********************************************************************
1843 * _adj_fdivr_m32 (MSVCRT.@)
1846 * I _think_ this function is intended to work around the Pentium
1849 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
1851 TRACE("(): stub\n");
1854 /***********************************************************************
1855 * _adj_fdivr_m32i (MSVCRT.@)
1858 * I _think_ this function is intended to work around the Pentium
1861 void __stdcall
_adj_fdivr_m32i( int arg
)
1863 TRACE("(): stub\n");
1866 /***********************************************************************
1867 * _adj_fdivr_m64 (MSVCRT.@)
1870 * I _think_ this function is intended to work around the Pentium
1873 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
1875 TRACE("(): stub\n");
1878 /***********************************************************************
1879 * _adj_fpatan (MSVCRT.@)
1881 * This function is likely to have the wrong number of arguments.
1884 * I _think_ this function is intended to work around the Pentium
1887 void _adj_fpatan(void)
1889 TRACE("(): stub\n");
1892 /***********************************************************************
1893 * _adj_fprem (MSVCRT.@)
1895 * This function is likely to have the wrong number of arguments.
1898 * I _think_ this function is intended to work around the Pentium
1901 void _adj_fprem(void)
1903 TRACE("(): stub\n");
1906 /***********************************************************************
1907 * _adj_fprem1 (MSVCRT.@)
1909 * This function is likely to have the wrong number of arguments.
1912 * I _think_ this function is intended to work around the Pentium
1915 void _adj_fprem1(void)
1917 TRACE("(): stub\n");
1920 /***********************************************************************
1921 * _adj_fptan (MSVCRT.@)
1923 * This function is likely to have the wrong number of arguments.
1926 * I _think_ this function is intended to work around the Pentium
1929 void _adj_fptan(void)
1931 TRACE("(): stub\n");
1934 /***********************************************************************
1935 * _safe_fdiv (MSVCRT.@)
1937 * This function is likely to have the wrong number of arguments.
1940 * I _think_ this function is intended to work around the Pentium
1943 void _safe_fdiv(void)
1945 TRACE("(): stub\n");
1948 /***********************************************************************
1949 * _safe_fdivr (MSVCRT.@)
1951 * This function is likely to have the wrong number of arguments.
1954 * I _think_ this function is intended to work around the Pentium
1957 void _safe_fdivr(void)
1959 TRACE("(): stub\n");
1962 /***********************************************************************
1963 * _safe_fprem (MSVCRT.@)
1965 * This function is likely to have the wrong number of arguments.
1968 * I _think_ this function is intended to work around the Pentium
1971 void _safe_fprem(void)
1973 TRACE("(): stub\n");
1976 /***********************************************************************
1977 * _safe_fprem1 (MSVCRT.@)
1980 * This function is likely to have the wrong number of arguments.
1983 * I _think_ this function is intended to work around the Pentium
1986 void _safe_fprem1(void)
1988 TRACE("(): stub\n");
1991 /***********************************************************************
1992 * __libm_sse2_acos (MSVCRT.@)
1994 void __cdecl
MSVCRT___libm_sse2_acos(void)
1997 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
1999 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2002 /***********************************************************************
2003 * __libm_sse2_acosf (MSVCRT.@)
2005 void __cdecl
MSVCRT___libm_sse2_acosf(void)
2008 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2010 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2013 /***********************************************************************
2014 * __libm_sse2_asin (MSVCRT.@)
2016 void __cdecl
MSVCRT___libm_sse2_asin(void)
2019 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2021 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2024 /***********************************************************************
2025 * __libm_sse2_asinf (MSVCRT.@)
2027 void __cdecl
MSVCRT___libm_sse2_asinf(void)
2030 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2032 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2035 /***********************************************************************
2036 * __libm_sse2_atan (MSVCRT.@)
2038 void __cdecl
MSVCRT___libm_sse2_atan(void)
2041 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2043 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2046 /***********************************************************************
2047 * __libm_sse2_atan2 (MSVCRT.@)
2049 void __cdecl
MSVCRT___libm_sse2_atan2(void)
2052 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2053 d1
= atan2( d1
, d2
);
2054 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2057 /***********************************************************************
2058 * __libm_sse2_atanf (MSVCRT.@)
2060 void __cdecl
MSVCRT___libm_sse2_atanf(void)
2063 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2065 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2068 /***********************************************************************
2069 * __libm_sse2_cos (MSVCRT.@)
2071 void __cdecl
MSVCRT___libm_sse2_cos(void)
2074 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2076 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2079 /***********************************************************************
2080 * __libm_sse2_cosf (MSVCRT.@)
2082 void __cdecl
MSVCRT___libm_sse2_cosf(void)
2085 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2087 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2090 /***********************************************************************
2091 * __libm_sse2_exp (MSVCRT.@)
2093 void __cdecl
MSVCRT___libm_sse2_exp(void)
2096 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2098 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2101 /***********************************************************************
2102 * __libm_sse2_expf (MSVCRT.@)
2104 void __cdecl
MSVCRT___libm_sse2_expf(void)
2107 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2109 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2112 /***********************************************************************
2113 * __libm_sse2_log (MSVCRT.@)
2115 void __cdecl
MSVCRT___libm_sse2_log(void)
2118 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2120 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2123 /***********************************************************************
2124 * __libm_sse2_log10 (MSVCRT.@)
2126 void __cdecl
MSVCRT___libm_sse2_log10(void)
2129 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2131 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2134 /***********************************************************************
2135 * __libm_sse2_log10f (MSVCRT.@)
2137 void __cdecl
MSVCRT___libm_sse2_log10f(void)
2140 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2142 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2145 /***********************************************************************
2146 * __libm_sse2_logf (MSVCRT.@)
2148 void __cdecl
MSVCRT___libm_sse2_logf(void)
2151 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2153 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2156 /***********************************************************************
2157 * __libm_sse2_pow (MSVCRT.@)
2159 void __cdecl
MSVCRT___libm_sse2_pow(void)
2162 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2164 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2167 /***********************************************************************
2168 * __libm_sse2_powf (MSVCRT.@)
2170 void __cdecl
MSVCRT___libm_sse2_powf(void)
2173 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
2174 f1
= powf( f1
, f2
);
2175 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
2178 /***********************************************************************
2179 * __libm_sse2_sin (MSVCRT.@)
2181 void __cdecl
MSVCRT___libm_sse2_sin(void)
2184 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2186 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2189 /***********************************************************************
2190 * __libm_sse2_sinf (MSVCRT.@)
2192 void __cdecl
MSVCRT___libm_sse2_sinf(void)
2195 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2197 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2200 /***********************************************************************
2201 * __libm_sse2_tan (MSVCRT.@)
2203 void __cdecl
MSVCRT___libm_sse2_tan(void)
2206 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2208 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2211 /***********************************************************************
2212 * __libm_sse2_tanf (MSVCRT.@)
2214 void __cdecl
MSVCRT___libm_sse2_tanf(void)
2217 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2219 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2222 /***********************************************************************
2223 * __libm_sse2_sqrt_precise (MSVCR110.@)
2225 void __cdecl
MSVCRT___libm_sse2_sqrt_precise(void)
2228 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2230 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2233 #endif /* __i386__ */
2235 /*********************************************************************
2238 double CDECL
MSVCR120_cbrt(double x
)
2243 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
2247 /*********************************************************************
2248 * cbrtf (MSVCR120.@)
2250 float CDECL
MSVCR120_cbrtf(float x
)
2255 return MSVCR120_cbrt(x
);
2259 /*********************************************************************
2260 * cbrtl (MSVCR120.@)
2262 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
2264 return MSVCR120_cbrt(x
);
2267 /*********************************************************************
2270 double CDECL
MSVCR120_exp2(double x
)
2279 /*********************************************************************
2280 * exp2f (MSVCR120.@)
2282 float CDECL
MSVCR120_exp2f(float x
)
2287 return MSVCR120_exp2(x
);
2291 /*********************************************************************
2292 * exp2l (MSVCR120.@)
2294 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
2296 return MSVCR120_exp2(x
);
2299 /*********************************************************************
2302 double CDECL
MSVCR120_log2(double x
)
2307 return log(x
) / log(2);
2311 /*********************************************************************
2312 * log2f (MSVCR120.@)
2314 float CDECL
MSVCR120_log2f(float x
)
2319 return MSVCR120_log2(x
);
2323 /*********************************************************************
2324 * log2l (MSVCR120.@)
2326 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
2328 return MSVCR120_log2(x
);
2331 /*********************************************************************
2334 double CDECL
MSVCR120_rint(double x
)
2339 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
2343 /*********************************************************************
2344 * rintf (MSVCR120.@)
2346 float CDECL
MSVCR120_rintf(float x
)
2351 return MSVCR120_rint(x
);
2355 /*********************************************************************
2356 * rintl (MSVCR120.@)
2358 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
2360 return MSVCR120_rint(x
);
2363 /*********************************************************************
2364 * lrint (MSVCR120.@)
2366 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
2371 return MSVCR120_rint(x
);
2375 /*********************************************************************
2376 * lrintf (MSVCR120.@)
2378 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
2383 return MSVCR120_lrint(x
);
2387 /*********************************************************************
2388 * lrintl (MSVCR120.@)
2390 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
2392 return MSVCR120_lrint(x
);
2395 /*********************************************************************
2396 * llrint (MSVCR120.@)
2398 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
2403 return MSVCR120_rint(x
);
2407 /*********************************************************************
2408 * llrintf (MSVCR120.@)
2410 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
2415 return MSVCR120_llrint(x
);
2419 /*********************************************************************
2420 * rintl (MSVCR120.@)
2422 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
2424 return MSVCR120_llrint(x
);
2427 /*********************************************************************
2428 * round (MSVCR120.@)
2430 double CDECL
MSVCR120_round(double x
)
2435 return MSVCR120_rint(x
);
2439 /*********************************************************************
2440 * roundf (MSVCR120.@)
2442 float CDECL
MSVCR120_roundf(float x
)
2447 return MSVCR120_round(x
);
2451 /*********************************************************************
2452 * roundl (MSVCR120.@)
2454 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
2456 return MSVCR120_round(x
);
2459 /*********************************************************************
2460 * lround (MSVCR120.@)
2462 MSVCRT_long CDECL
MSVCR120_lround(double x
)
2467 return MSVCR120_round(x
);
2471 /*********************************************************************
2472 * lroundf (MSVCR120.@)
2474 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
2479 return MSVCR120_lround(x
);
2483 /*********************************************************************
2484 * lroundl (MSVCR120.@)
2486 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
2488 return MSVCR120_lround(x
);
2491 /*********************************************************************
2492 * llround (MSVCR120.@)
2494 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
2499 return MSVCR120_round(x
);
2503 /*********************************************************************
2504 * llroundf (MSVCR120.@)
2506 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
2508 #ifdef HAVE_LLROUNDF
2511 return MSVCR120_llround(x
);
2515 /*********************************************************************
2516 * roundl (MSVCR120.@)
2518 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
2520 return MSVCR120_llround(x
);
2523 /*********************************************************************
2524 * trunc (MSVCR120.@)
2526 double CDECL
MSVCR120_trunc(double x
)
2531 return (x
> 0) ? floor(x
) : ceil(x
);
2535 /*********************************************************************
2536 * truncf (MSVCR120.@)
2538 float CDECL
MSVCR120_truncf(float x
)
2543 return MSVCR120_trunc(x
);
2547 /*********************************************************************
2548 * truncl (MSVCR120.@)
2550 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
2552 return MSVCR120_trunc(x
);
2555 /*********************************************************************
2556 * _dclass (MSVCR120.@)
2558 short CDECL
MSVCR120__dclass(double x
)
2560 switch (MSVCRT__fpclass(x
)) {
2561 case MSVCRT__FPCLASS_QNAN
:
2562 case MSVCRT__FPCLASS_SNAN
:
2563 return MSVCRT_FP_NAN
;
2564 case MSVCRT__FPCLASS_NINF
:
2565 case MSVCRT__FPCLASS_PINF
:
2566 return MSVCRT_FP_INFINITE
;
2567 case MSVCRT__FPCLASS_ND
:
2568 case MSVCRT__FPCLASS_PD
:
2569 return MSVCRT_FP_SUBNORMAL
;
2570 case MSVCRT__FPCLASS_NN
:
2571 case MSVCRT__FPCLASS_PN
:
2573 return MSVCRT_FP_NORMAL
;
2574 case MSVCRT__FPCLASS_NZ
:
2575 case MSVCRT__FPCLASS_PZ
:
2576 return MSVCRT_FP_ZERO
;
2580 /*********************************************************************
2581 * _fdclass (MSVCR120.@)
2583 short CDECL
MSVCR120__fdclass(float x
)
2585 return MSVCR120__dclass(x
);
2588 /*********************************************************************
2589 * _ldclass (MSVCR120.@)
2591 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
2593 return MSVCR120__dclass(x
);
2596 /*********************************************************************
2597 * _dtest (MSVCR120.@)
2599 short CDECL
MSVCR120__dtest(double *x
)
2601 return MSVCR120__dclass(*x
);
2604 /*********************************************************************
2605 * _fdtest (MSVCR120.@)
2607 short CDECL
MSVCR120__fdtest(float *x
)
2609 return MSVCR120__dclass(*x
);
2612 /*********************************************************************
2613 * _ldtest (MSVCR120.@)
2615 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
2617 return MSVCR120__dclass(*x
);
2620 /*********************************************************************
2623 float CDECL
MSVCR120_erff(float x
)
2628 FIXME( "not implemented\n" );
2633 /*********************************************************************
2636 double CDECL
MSVCR120_erf(double x
)
2641 FIXME( "not implemented\n" );
2646 /*********************************************************************
2649 LDOUBLE CDECL
MSVCR120_erfl(LDOUBLE x
)
2651 return MSVCR120_erf(x
);
2654 /*********************************************************************
2655 * fmaxf (MSVCR120.@)
2657 float CDECL
MSVCR120_fmaxf(float x
, float y
)
2664 return signbit(x
) ? y
: x
;
2668 /*********************************************************************
2671 double CDECL
MSVCR120_fmax(double x
, double y
)
2678 return signbit(x
) ? y
: x
;
2682 /*********************************************************************
2683 * _fdsign (MSVCR120.@)
2685 int CDECL
MSVCR120__fdsign(float x
)
2687 return signbit(x
) ? 0x8000 : 0;
2690 /*********************************************************************
2691 * _dsign (MSVCR120.@)
2693 int CDECL
MSVCR120__dsign(double x
)
2695 return signbit(x
) ? 0x8000 : 0;
2699 /*********************************************************************
2700 * _dpcomp (MSVCR120.@)
2702 int CDECL
MSVCR120__dpcomp(double x
, double y
)
2704 if(isnan(x
) || isnan(y
))
2707 if(x
== y
) return 2;
2708 return x
< y
? 1 : 4;
2711 /*********************************************************************
2712 * _fdpcomp (MSVCR120.@)
2714 int CDECL
MSVCR120__fdpcomp(float x
, float y
)
2716 return MSVCR120__dpcomp(x
, y
);
2719 /*********************************************************************
2720 * fminf (MSVCR120.@)
2722 float CDECL
MSVCR120_fminf(float x
, float y
)
2729 return signbit(x
) ? x
: y
;
2733 /*********************************************************************
2736 double CDECL
MSVCR120_fmin(double x
, double y
)
2743 return signbit(x
) ? x
: y
;
2747 /*********************************************************************
2748 * asinh (MSVCR120.@)
2750 double CDECL
MSVCR120_asinh(double x
)
2755 FIXME( "not implemented\n" );
2760 /*********************************************************************
2761 * asinhf (MSVCR120.@)
2763 float CDECL
MSVCR120_asinhf(float x
)
2768 FIXME( "not implemented\n" );
2773 /*********************************************************************
2774 * asinhl (MSVCR120.@)
2776 LDOUBLE CDECL
MSVCR120_asinhl(LDOUBLE x
)
2778 return MSVCR120_asinh(x
);