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
;
76 #if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
78 /*********************************************************************
79 * _chgsignf (MSVCRT.@)
81 float CDECL
MSVCRT__chgsignf( float num
)
83 /* FIXME: +-infinity,Nan not tested */
87 /*********************************************************************
88 * _copysignf (MSVCRT.@)
90 float CDECL
MSVCRT__copysignf( float num
, float sign
)
93 return signbit(num
) ? num
: -num
;
94 return signbit(num
) ? -num
: num
;
98 #if defined(__x86_64__) || defined(__arm__)
100 /*********************************************************************
101 * _finitef (MSVCRT.@)
103 int CDECL
MSVCRT__finitef( float num
)
105 return finitef(num
) != 0; /* See comment for _isnan() */
108 /*********************************************************************
111 INT CDECL
MSVCRT__isnanf( float num
)
113 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
114 * Do the same, as the result may be used in calculations
116 return isnanf(num
) != 0;
119 /*********************************************************************
122 float CDECL
MSVCRT__logbf( float num
)
124 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
128 /*********************************************************************
129 * _nextafterf (MSVCRT.@)
131 float CDECL
MSVCRT__nextafterf( float num
, float next
)
133 if (!finitef(num
) || !finitef(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
134 return nextafterf( num
, next
);
137 /*********************************************************************
138 * MSVCRT_acosf (MSVCRT.@)
140 float CDECL
MSVCRT_acosf( float x
)
142 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
143 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
144 * asin() uses a similar construction. This is bad because as x gets nearer to
145 * 1 the error in the expression "1 - x^2" can get relatively large due to
146 * cancellation. The sqrt() makes things worse. A safer way to calculate
147 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
148 return atan2f(sqrtf((1 - x
) * (1 + x
)), x
);
151 /*********************************************************************
152 * MSVCRT_asinf (MSVCRT.@)
154 float CDECL
MSVCRT_asinf( float x
)
156 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
157 return atan2f(x
, sqrtf((1 - x
) * (1 + x
)));
160 /*********************************************************************
161 * MSVCRT_atanf (MSVCRT.@)
163 float CDECL
MSVCRT_atanf( float x
)
165 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
169 /*********************************************************************
170 * MSVCRT_atan2f (MSVCRT.@)
172 float CDECL
MSVCRT_atan2f( float x
, float y
)
174 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
178 /*********************************************************************
179 * MSVCRT_cosf (MSVCRT.@)
181 float CDECL
MSVCRT_cosf( float x
)
183 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
187 /*********************************************************************
188 * MSVCRT_coshf (MSVCRT.@)
190 float CDECL
MSVCRT_coshf( float x
)
192 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
196 /*********************************************************************
197 * MSVCRT_expf (MSVCRT.@)
199 float CDECL
MSVCRT_expf( float x
)
201 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
205 /*********************************************************************
206 * MSVCRT_fmodf (MSVCRT.@)
208 float CDECL
MSVCRT_fmodf( float x
, float y
)
210 if (!finitef(x
) || !finitef(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
214 /*********************************************************************
215 * MSVCRT_logf (MSVCRT.@)
217 float CDECL
MSVCRT_logf( float x
)
219 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
220 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
224 /*********************************************************************
225 * MSVCRT_log10f (MSVCRT.@)
227 float CDECL
MSVCRT_log10f( float x
)
229 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
230 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
234 /*********************************************************************
235 * MSVCRT_powf (MSVCRT.@)
237 float CDECL
MSVCRT_powf( float x
, float y
)
239 /* FIXME: If x < 0 and y is not integral, set EDOM */
241 if (!finitef(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
245 /*********************************************************************
246 * MSVCRT_sinf (MSVCRT.@)
248 float CDECL
MSVCRT_sinf( float x
)
250 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
254 /*********************************************************************
255 * MSVCRT_sinhf (MSVCRT.@)
257 float CDECL
MSVCRT_sinhf( float x
)
259 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
263 /*********************************************************************
264 * MSVCRT_sqrtf (MSVCRT.@)
266 float CDECL
MSVCRT_sqrtf( float x
)
268 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
272 /*********************************************************************
273 * MSVCRT_tanf (MSVCRT.@)
275 float CDECL
MSVCRT_tanf( float x
)
277 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
281 /*********************************************************************
282 * MSVCRT_tanhf (MSVCRT.@)
284 float CDECL
MSVCRT_tanhf( float x
)
286 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
290 /*********************************************************************
293 float CDECL
MSVCRT_ceilf( float x
)
298 /*********************************************************************
301 float CDECL
MSVCRT_fabsf( float x
)
306 /*********************************************************************
309 float CDECL
MSVCRT_floorf( float x
)
314 /*********************************************************************
317 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
319 return frexpf( x
, exp
);
322 /*********************************************************************
325 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
327 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
328 return ldexpf(num
, power
);
331 /*********************************************************************
334 double CDECL
MSVCRT_modff( float x
, float *iptr
)
336 return modff( x
, iptr
);
341 /*********************************************************************
342 * MSVCRT_acos (MSVCRT.@)
344 double CDECL
MSVCRT_acos( double x
)
346 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
347 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
348 * asin() uses a similar construction. This is bad because as x gets nearer to
349 * 1 the error in the expression "1 - x^2" can get relatively large due to
350 * cancellation. The sqrt() makes things worse. A safer way to calculate
351 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
352 return atan2(sqrt((1 - x
) * (1 + x
)), x
);
355 /*********************************************************************
356 * MSVCRT_asin (MSVCRT.@)
358 double CDECL
MSVCRT_asin( double x
)
360 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
361 return atan2(x
, sqrt((1 - x
) * (1 + x
)));
364 /*********************************************************************
365 * MSVCRT_atan (MSVCRT.@)
367 double CDECL
MSVCRT_atan( double x
)
369 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
373 /*********************************************************************
374 * MSVCRT_atan2 (MSVCRT.@)
376 double CDECL
MSVCRT_atan2( double x
, double y
)
378 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
382 /*********************************************************************
383 * MSVCRT_cos (MSVCRT.@)
385 double CDECL
MSVCRT_cos( double x
)
387 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
391 /*********************************************************************
392 * MSVCRT_cosh (MSVCRT.@)
394 double CDECL
MSVCRT_cosh( double x
)
396 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
400 /*********************************************************************
401 * MSVCRT_exp (MSVCRT.@)
403 double CDECL
MSVCRT_exp( double x
)
405 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
409 /*********************************************************************
410 * MSVCRT_fmod (MSVCRT.@)
412 double CDECL
MSVCRT_fmod( double x
, double y
)
414 if (!isfinite(x
) || !isfinite(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
418 /*********************************************************************
419 * MSVCRT_log (MSVCRT.@)
421 double CDECL
MSVCRT_log( double x
)
423 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
424 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
428 /*********************************************************************
429 * MSVCRT_log10 (MSVCRT.@)
431 double CDECL
MSVCRT_log10( double x
)
433 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
434 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
438 /*********************************************************************
439 * MSVCRT_pow (MSVCRT.@)
441 double CDECL
MSVCRT_pow( double x
, double y
)
443 /* FIXME: If x < 0 and y is not integral, set EDOM */
445 if (!isfinite(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
449 /*********************************************************************
450 * MSVCRT_sin (MSVCRT.@)
452 double CDECL
MSVCRT_sin( double x
)
454 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
458 /*********************************************************************
459 * MSVCRT_sinh (MSVCRT.@)
461 double CDECL
MSVCRT_sinh( double x
)
463 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
467 /*********************************************************************
468 * MSVCRT_sqrt (MSVCRT.@)
470 double CDECL
MSVCRT_sqrt( double x
)
472 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
476 /*********************************************************************
477 * MSVCRT_tan (MSVCRT.@)
479 double CDECL
MSVCRT_tan( double x
)
481 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
485 /*********************************************************************
486 * MSVCRT_tanh (MSVCRT.@)
488 double CDECL
MSVCRT_tanh( double x
)
490 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
495 #if defined(__GNUC__) && defined(__i386__)
497 #define FPU_DOUBLE(var) double var; \
498 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
499 #define FPU_DOUBLES(var1,var2) double var1,var2; \
500 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
501 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
503 /*********************************************************************
506 double CDECL
_CIacos(void)
509 return MSVCRT_acos(x
);
512 /*********************************************************************
515 double CDECL
_CIasin(void)
518 return MSVCRT_asin(x
);
521 /*********************************************************************
524 double CDECL
_CIatan(void)
527 return MSVCRT_atan(x
);
530 /*********************************************************************
531 * _CIatan2 (MSVCRT.@)
533 double CDECL
_CIatan2(void)
536 return MSVCRT_atan2(x
,y
);
539 /*********************************************************************
542 double CDECL
_CIcos(void)
545 return MSVCRT_cos(x
);
548 /*********************************************************************
551 double CDECL
_CIcosh(void)
554 return MSVCRT_cosh(x
);
557 /*********************************************************************
560 double CDECL
_CIexp(void)
563 return MSVCRT_exp(x
);
566 /*********************************************************************
569 double CDECL
_CIfmod(void)
572 return MSVCRT_fmod(x
,y
);
575 /*********************************************************************
578 double CDECL
_CIlog(void)
581 return MSVCRT_log(x
);
584 /*********************************************************************
585 * _CIlog10 (MSVCRT.@)
587 double CDECL
_CIlog10(void)
590 return MSVCRT_log10(x
);
593 /*********************************************************************
596 double CDECL
_CIpow(void)
599 return MSVCRT_pow(x
,y
);
602 /*********************************************************************
605 double CDECL
_CIsin(void)
608 return MSVCRT_sin(x
);
611 /*********************************************************************
614 double CDECL
_CIsinh(void)
617 return MSVCRT_sinh(x
);
620 /*********************************************************************
623 double CDECL
_CIsqrt(void)
626 return MSVCRT_sqrt(x
);
629 /*********************************************************************
632 double CDECL
_CItan(void)
635 return MSVCRT_tan(x
);
638 /*********************************************************************
641 double CDECL
_CItanh(void)
644 return MSVCRT_tanh(x
);
647 /*********************************************************************
650 LONGLONG CDECL
MSVCRT__ftol(void)
656 #endif /* defined(__GNUC__) && defined(__i386__) */
658 /*********************************************************************
659 * _fpclass (MSVCRT.@)
661 int CDECL
MSVCRT__fpclass(double num
)
663 #if defined(HAVE_FPCLASS) || defined(fpclass)
664 switch (fpclass( num
))
667 case FP_SNAN
: return MSVCRT__FPCLASS_SNAN
;
670 case FP_QNAN
: return MSVCRT__FPCLASS_QNAN
;
673 case FP_NINF
: return MSVCRT__FPCLASS_NINF
;
676 case FP_PINF
: return MSVCRT__FPCLASS_PINF
;
679 case FP_NDENORM
: return MSVCRT__FPCLASS_ND
;
682 case FP_PDENORM
: return MSVCRT__FPCLASS_PD
;
685 case FP_NZERO
: return MSVCRT__FPCLASS_NZ
;
688 case FP_PZERO
: return MSVCRT__FPCLASS_PZ
;
691 case FP_NNORM
: return MSVCRT__FPCLASS_NN
;
694 case FP_PNORM
: return MSVCRT__FPCLASS_PN
;
696 default: return MSVCRT__FPCLASS_PN
;
698 #elif defined (fpclassify)
699 switch (fpclassify( num
))
701 case FP_NAN
: return MSVCRT__FPCLASS_QNAN
;
702 case FP_INFINITE
: return signbit(num
) ? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
703 case FP_SUBNORMAL
: return signbit(num
) ?MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
704 case FP_ZERO
: return signbit(num
) ? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
706 return signbit(num
) ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
709 return MSVCRT__FPCLASS_QNAN
;
710 return num
== 0.0 ? MSVCRT__FPCLASS_PZ
: (num
< 0 ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
);
714 /*********************************************************************
717 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
720 return (num
<< shift
) | (num
>> (32-shift
));
723 /*********************************************************************
726 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
729 return (num
<< shift
) | (num
>> (32-shift
));
732 /*********************************************************************
735 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
738 return (num
>> shift
) | (num
<< (32-shift
));
741 /*********************************************************************
744 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
747 return (num
>> shift
) | (num
<< (32-shift
));
750 /*********************************************************************
753 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
756 return (num
<< shift
) | (num
>> (64-shift
));
759 /*********************************************************************
762 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
765 return (num
>> shift
) | (num
<< (64-shift
));
768 /*********************************************************************
771 int CDECL
MSVCRT_abs( int n
)
773 return n
>= 0 ? n
: -n
;
776 /*********************************************************************
779 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
781 return n
>= 0 ? n
: -n
;
784 /*********************************************************************
787 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
789 return n
>= 0 ? n
: -n
;
792 /*********************************************************************
795 __int64 CDECL
_abs64( __int64 n
)
797 return n
>= 0 ? n
: -n
;
800 /*********************************************************************
803 double CDECL
MSVCRT__logb(double num
)
805 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
809 /*********************************************************************
812 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
814 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
815 return ldexp(num
, power
);
818 /*********************************************************************
821 double CDECL
_hypot(double x
, double y
)
823 /* FIXME: errno handling */
824 return hypot( x
, y
);
827 /*********************************************************************
830 float CDECL
MSVCRT__hypotf(float x
, float y
)
832 /* FIXME: errno handling */
833 return hypotf( x
, y
);
836 /*********************************************************************
839 double CDECL
MSVCRT_ceil( double x
)
844 /*********************************************************************
847 double CDECL
MSVCRT_floor( double x
)
852 /*********************************************************************
855 double CDECL
MSVCRT_fabs( double x
)
860 /*********************************************************************
863 double CDECL
MSVCRT_frexp( double x
, int *exp
)
865 return frexp( x
, exp
);
868 /*********************************************************************
871 double CDECL
MSVCRT_modf( double x
, double *iptr
)
873 return modf( x
, iptr
);
876 /*********************************************************************
877 * _matherr (MSVCRT.@)
879 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
882 TRACE("(%p = %d, %s, %g %g %g)\n",e
, e
->type
, e
->name
, e
->arg1
, e
->arg2
,
886 if (MSVCRT_default_matherr_func
)
887 return MSVCRT_default_matherr_func(e
);
888 ERR(":Unhandled math error!\n");
892 /*********************************************************************
893 * __setusermatherr (MSVCRT.@)
895 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
897 MSVCRT_default_matherr_func
= func
;
898 TRACE(":new matherr handler %p\n", func
);
901 /**********************************************************************
902 * _statusfp2 (MSVCRT.@)
904 * Not exported by native msvcrt, added in msvcr80.
906 #if defined(__i386__) || defined(__x86_64__)
907 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
911 unsigned long fpword
;
915 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
917 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
918 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
919 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
920 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
921 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
922 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
926 if (!sse2_sw
) return;
930 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
932 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
933 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
934 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
935 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
936 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
937 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
942 FIXME( "not implemented\n" );
947 /**********************************************************************
948 * _statusfp (MSVCRT.@)
950 unsigned int CDECL
_statusfp(void)
952 #if defined(__i386__) || defined(__x86_64__)
953 unsigned int x86_sw
, sse2_sw
;
955 _statusfp2( &x86_sw
, &sse2_sw
);
956 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
957 return x86_sw
| sse2_sw
;
959 FIXME( "not implemented\n" );
964 /*********************************************************************
965 * _clearfp (MSVCRT.@)
967 unsigned int CDECL
_clearfp(void)
969 unsigned int flags
= 0;
970 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
971 unsigned long fpword
;
973 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
974 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
975 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
976 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
977 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
978 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
979 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
983 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
984 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
985 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
986 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
987 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
988 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
989 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
991 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
994 FIXME( "not implemented\n" );
999 /*********************************************************************
1000 * __fpecode (MSVCRT.@)
1002 int * CDECL
__fpecode(void)
1004 return &msvcrt_get_thread_data()->fpecode
;
1007 /*********************************************************************
1010 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1012 double z
= ldexp(num
,exp
);
1015 *MSVCRT__errno() = MSVCRT_ERANGE
;
1016 else if (z
== 0 && signbit(z
))
1017 z
= 0.0; /* Convert -0 -> +0 */
1021 /*********************************************************************
1024 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1026 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1029 /*********************************************************************
1030 * _chgsign (MSVCRT.@)
1032 double CDECL
MSVCRT__chgsign(double num
)
1034 /* FIXME: +-infinity,Nan not tested */
1038 /*********************************************************************
1039 * __control87_2 (MSVCRT.@)
1041 * Not exported by native msvcrt, added in msvcr80.
1043 #if defined(__i386__) || defined(__x86_64__)
1044 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1045 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1048 unsigned long fpword
;
1053 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1055 /* Convert into mask constants */
1057 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1058 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1059 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1060 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1061 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1062 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1063 switch (fpword
& 0xc00)
1065 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1066 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1067 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1069 switch (fpword
& 0x300)
1071 case 0x0: flags
|= MSVCRT__PC_24
; break;
1072 case 0x200: flags
|= MSVCRT__PC_53
; break;
1073 case 0x300: flags
|= MSVCRT__PC_64
; break;
1075 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1077 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1080 flags
= (flags
& ~mask
) | (newval
& mask
);
1082 /* Convert (masked) value back to fp word */
1084 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1085 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1086 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1087 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1088 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1089 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1090 switch (flags
& MSVCRT__MCW_RC
)
1092 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1093 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1094 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1096 switch (flags
& MSVCRT__MCW_PC
)
1098 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1099 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1100 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1102 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1104 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1109 if (!sse2_cw
) return 1;
1113 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1115 /* Convert into mask constants */
1117 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1118 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1119 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1120 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1121 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1122 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1123 switch (fpword
& 0x6000)
1125 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1126 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1127 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1129 switch (fpword
& 0x8040)
1131 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1132 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1133 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1136 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1139 flags
= (flags
& ~mask
) | (newval
& mask
);
1141 /* Convert (masked) value back to fp word */
1143 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1144 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1145 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1146 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1147 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1148 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1149 switch (flags
& MSVCRT__MCW_RC
)
1151 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1152 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1153 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1155 switch (flags
& MSVCRT__MCW_DN
)
1157 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1158 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1159 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1161 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1169 FIXME( "not implemented\n" );
1175 /*********************************************************************
1176 * _control87 (MSVCRT.@)
1178 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1180 #if defined(__i386__) || defined(__x86_64__)
1181 unsigned int x86_cw
, sse2_cw
;
1183 __control87_2( newval
, mask
, &x86_cw
, &sse2_cw
);
1185 if ((x86_cw
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) x86_cw
|= MSVCRT__EM_AMBIGUOUS
;
1188 FIXME( "not implemented\n" );
1193 /*********************************************************************
1194 * _controlfp (MSVCRT.@)
1196 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
1198 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
1201 /*********************************************************************
1202 * _set_controlfp (MSVCRT.@)
1204 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
1206 _controlfp( newval
, mask
);
1209 /*********************************************************************
1210 * _controlfp_s (MSVCRT.@)
1212 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
1214 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
1215 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
1218 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
1220 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
1221 return MSVCRT_EINVAL
;
1223 val
= _controlfp( newval
, mask
);
1224 if (cur
) *cur
= val
;
1228 /*********************************************************************
1229 * _copysign (MSVCRT.@)
1231 double CDECL
MSVCRT__copysign(double num
, double sign
)
1234 return signbit(num
) ? num
: -num
;
1235 return signbit(num
) ? -num
: num
;
1238 /*********************************************************************
1239 * _finite (MSVCRT.@)
1241 int CDECL
MSVCRT__finite(double num
)
1243 return isfinite(num
) != 0; /* See comment for _isnan() */
1246 /*********************************************************************
1247 * _fpreset (MSVCRT.@)
1249 void CDECL
_fpreset(void)
1251 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1252 const unsigned int x86_cw
= 0x27f;
1253 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
1256 const unsigned long sse2_cw
= 0x1f80;
1257 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
1260 FIXME( "not implemented\n" );
1264 /*********************************************************************
1267 INT CDECL
MSVCRT__isnan(double num
)
1269 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1270 * Do the same, as the result may be used in calculations
1272 return isnan(num
) != 0;
1275 /*********************************************************************
1278 double CDECL
MSVCRT__j0(double num
)
1280 /* FIXME: errno handling */
1284 /*********************************************************************
1287 double CDECL
MSVCRT__j1(double num
)
1289 /* FIXME: errno handling */
1293 /*********************************************************************
1296 double CDECL
MSVCRT__jn(int n
, double num
)
1298 /* FIXME: errno handling */
1302 /*********************************************************************
1305 double CDECL
MSVCRT__y0(double num
)
1308 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1310 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1312 *MSVCRT__errno() = MSVCRT_EDOM
;
1318 /*********************************************************************
1321 double CDECL
MSVCRT__y1(double num
)
1324 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1326 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1328 *MSVCRT__errno() = MSVCRT_EDOM
;
1334 /*********************************************************************
1337 double CDECL
MSVCRT__yn(int order
, double num
)
1340 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1341 retval
= yn(order
,num
);
1342 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1344 *MSVCRT__errno() = MSVCRT_EDOM
;
1350 /*********************************************************************
1351 * _nextafter (MSVCRT.@)
1353 double CDECL
MSVCRT__nextafter(double num
, double next
)
1356 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1357 retval
= nextafter(num
,next
);
1361 /*********************************************************************
1364 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
1367 thread_data_t
*data
= msvcrt_get_thread_data();
1368 /* FIXME: check better for overflow (native supports over 300 chars) */
1369 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
1370 * 4 for exponent and one for
1371 * terminating '\0' */
1372 if (!data
->efcvt_buffer
)
1373 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1380 /* handle cases with zero ndigits or less */
1382 if( prec
< 1) prec
= 2;
1383 len
= snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
1384 /* take the decimal "point away */
1386 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
1387 /* take the exponential "e" out */
1388 data
->efcvt_buffer
[ prec
] = '\0';
1389 /* read the exponent */
1390 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
1392 /* adjust for some border cases */
1393 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
1395 /* handle cases with zero ndigits or less */
1397 if( data
->efcvt_buffer
[ 0] >= '5')
1399 data
->efcvt_buffer
[ 0] = '\0';
1401 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
1402 return data
->efcvt_buffer
;
1405 /*********************************************************************
1406 * _ecvt_s (MSVCRT.@)
1408 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
1412 const char infret
[] = "1#INF";
1414 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
1415 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
1416 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
1417 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1418 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1420 /* special case - inf */
1421 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
1423 memset(buffer
, '0', ndigits
);
1424 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
1425 buffer
[ndigits
] = '\0';
1427 if(number
== -HUGE_VAL
)
1433 /* handle cases with zero ndigits or less */
1435 if( prec
< 1) prec
= 2;
1436 result
= MSVCRT_malloc(prec
+ 7);
1443 len
= snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
1444 /* take the decimal "point away */
1446 memmove( result
+ 1, result
+ 2, len
- 1 );
1447 /* take the exponential "e" out */
1448 result
[ prec
] = '\0';
1449 /* read the exponent */
1450 sscanf( result
+ prec
+ 1, "%d", decpt
);
1452 /* adjust for some border cases */
1453 if( result
[0] == '0')/* value is zero */
1455 /* handle cases with zero ndigits or less */
1457 if( result
[ 0] >= '5')
1461 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
1462 MSVCRT_free( result
);
1466 /***********************************************************************
1469 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
1471 thread_data_t
*data
= msvcrt_get_thread_data();
1472 int stop
, dec1
, dec2
;
1473 char *ptr1
, *ptr2
, *first
;
1474 char buf
[80]; /* ought to be enough */
1476 if (!data
->efcvt_buffer
)
1477 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1485 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1487 ptr2
= data
->efcvt_buffer
;
1492 /* For numbers below the requested resolution, work out where
1493 the decimal point will be rather than finding it in the string */
1494 if (number
< 1.0 && number
> 0.0) {
1495 dec2
= log10(number
+ 1e-10);
1496 if (-dec2
<= ndigits
) dec2
= 0;
1499 /* If requested digits is zero or less, we will need to truncate
1500 * the returned string */
1502 stop
= strlen(buf
) + ndigits
;
1507 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1508 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1509 if (!first
) first
= ptr2
;
1510 if ((ptr1
- buf
) < stop
) {
1521 while (*ptr1
== '0') { /* Process leading zeroes */
1526 while (*ptr1
!= '\0') {
1527 if (!first
) first
= ptr2
;
1534 /* We never found a non-zero digit, then our number is either
1535 * smaller than the requested precision, or 0.0 */
1540 first
= data
->efcvt_buffer
;
1545 *decpt
= dec2
? dec2
: dec1
;
1549 /***********************************************************************
1550 * _fcvt_s (MSVCRT.@)
1552 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
1554 int stop
, dec1
, dec2
;
1555 char *ptr1
, *ptr2
, *first
;
1556 char buf
[80]; /* ought to be enough */
1558 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
1560 *MSVCRT__errno() = MSVCRT_EINVAL
;
1561 return MSVCRT_EINVAL
;
1570 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1577 /* For numbers below the requested resolution, work out where
1578 the decimal point will be rather than finding it in the string */
1579 if (number
< 1.0 && number
> 0.0) {
1580 dec2
= log10(number
+ 1e-10);
1581 if (-dec2
<= ndigits
) dec2
= 0;
1584 /* If requested digits is zero or less, we will need to truncate
1585 * the returned string */
1587 stop
= strlen(buf
) + ndigits
;
1592 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1593 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1594 if (!first
) first
= ptr2
;
1595 if ((ptr1
- buf
) < stop
) {
1609 while (*ptr1
== '0') { /* Process leading zeroes */
1610 if (number
== 0.0 && size
> 1) {
1618 while (*ptr1
!= '\0') {
1619 if (!first
) first
= ptr2
;
1629 /* We never found a non-zero digit, then our number is either
1630 * smaller than the requested precision, or 0.0 */
1631 if (!first
&& (number
<= 0.0))
1634 *decpt
= dec2
? dec2
: dec1
;
1638 /***********************************************************************
1641 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
1644 *MSVCRT__errno() = MSVCRT_EINVAL
;
1649 *MSVCRT__errno() = MSVCRT_ERANGE
;
1653 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
1657 /***********************************************************************
1658 * _gcvt_s (MSVCRT.@)
1660 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
1665 *MSVCRT__errno() = MSVCRT_EINVAL
;
1666 return MSVCRT_EINVAL
;
1669 if( digits
<0 || digits
>=size
) {
1673 *MSVCRT__errno() = MSVCRT_ERANGE
;
1674 return MSVCRT_ERANGE
;
1677 len
= MSVCRT__scprintf("%.*g", digits
, number
);
1680 *MSVCRT__errno() = MSVCRT_ERANGE
;
1681 return MSVCRT_ERANGE
;
1684 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
1688 #include <stdlib.h> /* div_t, ldiv_t */
1690 /*********************************************************************
1693 * [i386] Windows binary compatible - returns the struct in eax/edx.
1696 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
1698 div_t dt
= div(num
,denom
);
1699 return ((unsigned __int64
)dt
.rem
<< 32) | (unsigned int)dt
.quot
;
1702 /*********************************************************************
1705 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1707 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
1709 div_t dt
= div(num
,denom
);
1717 #endif /* ifdef __i386__ */
1720 /*********************************************************************
1723 * [i386] Windows binary compatible - returns the struct in eax/edx.
1726 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1728 ldiv_t ldt
= ldiv(num
,denom
);
1729 return ((unsigned __int64
)ldt
.rem
<< 32) | (MSVCRT_ulong
)ldt
.quot
;
1732 /*********************************************************************
1735 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1737 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1739 ldiv_t result
= ldiv(num
,denom
);
1742 ret
.quot
= result
.quot
;
1743 ret
.rem
= result
.rem
;
1747 #endif /* ifdef __i386__ */
1751 /*********************************************************************
1752 * _adjust_fdiv (MSVCRT.@)
1753 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1755 int MSVCRT__adjust_fdiv
= 0;
1757 /***********************************************************************
1758 * _adj_fdiv_m16i (MSVCRT.@)
1761 * I _think_ this function is intended to work around the Pentium
1764 void __stdcall
_adj_fdiv_m16i( short arg
)
1766 TRACE("(): stub\n");
1769 /***********************************************************************
1770 * _adj_fdiv_m32 (MSVCRT.@)
1773 * I _think_ this function is intended to work around the Pentium
1776 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
1778 TRACE("(): stub\n");
1781 /***********************************************************************
1782 * _adj_fdiv_m32i (MSVCRT.@)
1785 * I _think_ this function is intended to work around the Pentium
1788 void __stdcall
_adj_fdiv_m32i( int arg
)
1790 TRACE("(): stub\n");
1793 /***********************************************************************
1794 * _adj_fdiv_m64 (MSVCRT.@)
1797 * I _think_ this function is intended to work around the Pentium
1800 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
1802 TRACE("(): stub\n");
1805 /***********************************************************************
1806 * _adj_fdiv_r (MSVCRT.@)
1808 * This function is likely to have the wrong number of arguments.
1811 * I _think_ this function is intended to work around the Pentium
1814 void _adj_fdiv_r(void)
1816 TRACE("(): stub\n");
1819 /***********************************************************************
1820 * _adj_fdivr_m16i (MSVCRT.@)
1823 * I _think_ this function is intended to work around the Pentium
1826 void __stdcall
_adj_fdivr_m16i( short arg
)
1828 TRACE("(): stub\n");
1831 /***********************************************************************
1832 * _adj_fdivr_m32 (MSVCRT.@)
1835 * I _think_ this function is intended to work around the Pentium
1838 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
1840 TRACE("(): stub\n");
1843 /***********************************************************************
1844 * _adj_fdivr_m32i (MSVCRT.@)
1847 * I _think_ this function is intended to work around the Pentium
1850 void __stdcall
_adj_fdivr_m32i( int arg
)
1852 TRACE("(): stub\n");
1855 /***********************************************************************
1856 * _adj_fdivr_m64 (MSVCRT.@)
1859 * I _think_ this function is intended to work around the Pentium
1862 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
1864 TRACE("(): stub\n");
1867 /***********************************************************************
1868 * _adj_fpatan (MSVCRT.@)
1870 * This function is likely to have the wrong number of arguments.
1873 * I _think_ this function is intended to work around the Pentium
1876 void _adj_fpatan(void)
1878 TRACE("(): stub\n");
1881 /***********************************************************************
1882 * _adj_fprem (MSVCRT.@)
1884 * This function is likely to have the wrong number of arguments.
1887 * I _think_ this function is intended to work around the Pentium
1890 void _adj_fprem(void)
1892 TRACE("(): stub\n");
1895 /***********************************************************************
1896 * _adj_fprem1 (MSVCRT.@)
1898 * This function is likely to have the wrong number of arguments.
1901 * I _think_ this function is intended to work around the Pentium
1904 void _adj_fprem1(void)
1906 TRACE("(): stub\n");
1909 /***********************************************************************
1910 * _adj_fptan (MSVCRT.@)
1912 * This function is likely to have the wrong number of arguments.
1915 * I _think_ this function is intended to work around the Pentium
1918 void _adj_fptan(void)
1920 TRACE("(): stub\n");
1923 /***********************************************************************
1924 * _safe_fdiv (MSVCRT.@)
1926 * This function is likely to have the wrong number of arguments.
1929 * I _think_ this function is intended to work around the Pentium
1932 void _safe_fdiv(void)
1934 TRACE("(): stub\n");
1937 /***********************************************************************
1938 * _safe_fdivr (MSVCRT.@)
1940 * This function is likely to have the wrong number of arguments.
1943 * I _think_ this function is intended to work around the Pentium
1946 void _safe_fdivr(void)
1948 TRACE("(): stub\n");
1951 /***********************************************************************
1952 * _safe_fprem (MSVCRT.@)
1954 * This function is likely to have the wrong number of arguments.
1957 * I _think_ this function is intended to work around the Pentium
1960 void _safe_fprem(void)
1962 TRACE("(): stub\n");
1965 /***********************************************************************
1966 * _safe_fprem1 (MSVCRT.@)
1969 * This function is likely to have the wrong number of arguments.
1972 * I _think_ this function is intended to work around the Pentium
1975 void _safe_fprem1(void)
1977 TRACE("(): stub\n");
1980 /***********************************************************************
1981 * __libm_sse2_acos (MSVCRT.@)
1983 void __cdecl
__libm_sse2_acos(void)
1986 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
1988 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
1991 /***********************************************************************
1992 * __libm_sse2_acosf (MSVCRT.@)
1994 void __cdecl
__libm_sse2_acosf(void)
1997 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
1999 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2002 /***********************************************************************
2003 * __libm_sse2_asin (MSVCRT.@)
2005 void __cdecl
__libm_sse2_asin(void)
2008 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2010 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2013 /***********************************************************************
2014 * __libm_sse2_asinf (MSVCRT.@)
2016 void __cdecl
__libm_sse2_asinf(void)
2019 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2021 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2024 /***********************************************************************
2025 * __libm_sse2_atan (MSVCRT.@)
2027 void __cdecl
__libm_sse2_atan(void)
2030 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2032 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2035 /***********************************************************************
2036 * __libm_sse2_atan2 (MSVCRT.@)
2038 void __cdecl
__libm_sse2_atan2(void)
2041 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2042 d1
= atan2( d1
, d2
);
2043 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2046 /***********************************************************************
2047 * __libm_sse2_atanf (MSVCRT.@)
2049 void __cdecl
__libm_sse2_atanf(void)
2052 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2054 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2057 /***********************************************************************
2058 * __libm_sse2_cos (MSVCRT.@)
2060 void __cdecl
__libm_sse2_cos(void)
2063 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2065 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2068 /***********************************************************************
2069 * __libm_sse2_cosf (MSVCRT.@)
2071 void __cdecl
__libm_sse2_cosf(void)
2074 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2076 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2079 /***********************************************************************
2080 * __libm_sse2_exp (MSVCRT.@)
2082 void __cdecl
__libm_sse2_exp(void)
2085 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2087 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2090 /***********************************************************************
2091 * __libm_sse2_expf (MSVCRT.@)
2093 void __cdecl
__libm_sse2_expf(void)
2096 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2098 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2101 /***********************************************************************
2102 * __libm_sse2_log (MSVCRT.@)
2104 void __cdecl
__libm_sse2_log(void)
2107 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2109 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2112 /***********************************************************************
2113 * __libm_sse2_log10 (MSVCRT.@)
2115 void __cdecl
__libm_sse2_log10(void)
2118 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2120 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2123 /***********************************************************************
2124 * __libm_sse2_log10f (MSVCRT.@)
2126 void __cdecl
__libm_sse2_log10f(void)
2129 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2131 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2134 /***********************************************************************
2135 * __libm_sse2_logf (MSVCRT.@)
2137 void __cdecl
__libm_sse2_logf(void)
2140 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2142 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2145 /***********************************************************************
2146 * __libm_sse2_pow (MSVCRT.@)
2148 void __cdecl
__libm_sse2_pow(void)
2151 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2153 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2156 /***********************************************************************
2157 * __libm_sse2_powf (MSVCRT.@)
2159 void __cdecl
__libm_sse2_powf(void)
2162 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
2163 f1
= powf( f1
, f2
);
2164 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
2167 /***********************************************************************
2168 * __libm_sse2_sin (MSVCRT.@)
2170 void __cdecl
__libm_sse2_sin(void)
2173 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2175 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2178 /***********************************************************************
2179 * __libm_sse2_sinf (MSVCRT.@)
2181 void __cdecl
__libm_sse2_sinf(void)
2184 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2186 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2189 /***********************************************************************
2190 * __libm_sse2_tan (MSVCRT.@)
2192 void __cdecl
__libm_sse2_tan(void)
2195 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2197 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2200 /***********************************************************************
2201 * __libm_sse2_tanf (MSVCRT.@)
2203 void __cdecl
__libm_sse2_tanf(void)
2206 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2208 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2211 /***********************************************************************
2212 * __libm_sse2_sqrt_precise (MSVCR110.@)
2214 void __cdecl
__libm_sse2_sqrt_precise(void)
2217 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2219 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2222 #endif /* __i386__ */
2224 /*********************************************************************
2227 double CDECL
MSVCR120_cbrt(double x
)
2232 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
2236 /*********************************************************************
2237 * cbrtf (MSVCR120.@)
2239 float CDECL
MSVCR120_cbrtf(float x
)
2244 return MSVCR120_cbrt(x
);
2248 /*********************************************************************
2249 * cbrtl (MSVCR120.@)
2251 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
2253 return MSVCR120_cbrt(x
);
2256 /*********************************************************************
2259 double CDECL
MSVCR120_exp2(double x
)
2268 /*********************************************************************
2269 * exp2f (MSVCR120.@)
2271 float CDECL
MSVCR120_exp2f(float x
)
2276 return MSVCR120_exp2(x
);
2280 /*********************************************************************
2281 * exp2l (MSVCR120.@)
2283 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
2285 return MSVCR120_exp2(x
);
2288 /*********************************************************************
2291 double CDECL
MSVCR120_log2(double x
)
2296 return log(x
) / log(2);
2300 /*********************************************************************
2301 * log2f (MSVCR120.@)
2303 float CDECL
MSVCR120_log2f(float x
)
2308 return MSVCR120_log2(x
);
2312 /*********************************************************************
2313 * log2l (MSVCR120.@)
2315 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
2317 return MSVCR120_log2(x
);
2320 /*********************************************************************
2323 double CDECL
MSVCR120_rint(double x
)
2328 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
2332 /*********************************************************************
2333 * rintf (MSVCR120.@)
2335 float CDECL
MSVCR120_rintf(float x
)
2340 return MSVCR120_rint(x
);
2344 /*********************************************************************
2345 * rintl (MSVCR120.@)
2347 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
2349 return MSVCR120_rint(x
);
2352 /*********************************************************************
2353 * lrint (MSVCR120.@)
2355 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
2360 return MSVCR120_rint(x
);
2364 /*********************************************************************
2365 * lrintf (MSVCR120.@)
2367 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
2372 return MSVCR120_lrint(x
);
2376 /*********************************************************************
2377 * lrintl (MSVCR120.@)
2379 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
2381 return MSVCR120_lrint(x
);
2384 /*********************************************************************
2385 * llrint (MSVCR120.@)
2387 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
2392 return MSVCR120_rint(x
);
2396 /*********************************************************************
2397 * llrintf (MSVCR120.@)
2399 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
2404 return MSVCR120_llrint(x
);
2408 /*********************************************************************
2409 * rintl (MSVCR120.@)
2411 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
2413 return MSVCR120_llrint(x
);
2416 /*********************************************************************
2417 * round (MSVCR120.@)
2419 double CDECL
MSVCR120_round(double x
)
2424 return MSVCR120_rint(x
);
2428 /*********************************************************************
2429 * roundf (MSVCR120.@)
2431 float CDECL
MSVCR120_roundf(float x
)
2436 return MSVCR120_round(x
);
2440 /*********************************************************************
2441 * roundl (MSVCR120.@)
2443 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
2445 return MSVCR120_round(x
);
2448 /*********************************************************************
2449 * lround (MSVCR120.@)
2451 MSVCRT_long CDECL
MSVCR120_lround(double x
)
2456 return MSVCR120_round(x
);
2460 /*********************************************************************
2461 * lroundf (MSVCR120.@)
2463 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
2468 return MSVCR120_lround(x
);
2472 /*********************************************************************
2473 * lroundl (MSVCR120.@)
2475 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
2477 return MSVCR120_lround(x
);
2480 /*********************************************************************
2481 * llround (MSVCR120.@)
2483 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
2488 return MSVCR120_round(x
);
2492 /*********************************************************************
2493 * llroundf (MSVCR120.@)
2495 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
2497 #ifdef HAVE_LLROUNDF
2500 return MSVCR120_llround(x
);
2504 /*********************************************************************
2505 * roundl (MSVCR120.@)
2507 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
2509 return MSVCR120_llround(x
);
2512 /*********************************************************************
2513 * trunc (MSVCR120.@)
2515 double CDECL
MSVCR120_trunc(double x
)
2520 return (x
> 0) ? floor(x
) : ceil(x
);
2524 /*********************************************************************
2525 * truncf (MSVCR120.@)
2527 float CDECL
MSVCR120_truncf(float x
)
2532 return MSVCR120_trunc(x
);
2536 /*********************************************************************
2537 * truncl (MSVCR120.@)
2539 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
2541 return MSVCR120_trunc(x
);
2544 /*********************************************************************
2545 * _dclass (MSVCR120.@)
2547 short CDECL
MSVCR120__dclass(double x
)
2549 switch (MSVCRT__fpclass(x
)) {
2550 case MSVCRT__FPCLASS_QNAN
:
2551 case MSVCRT__FPCLASS_SNAN
:
2552 return MSVCRT_FP_NAN
;
2553 case MSVCRT__FPCLASS_NINF
:
2554 case MSVCRT__FPCLASS_PINF
:
2555 return MSVCRT_FP_INFINITE
;
2556 case MSVCRT__FPCLASS_ND
:
2557 case MSVCRT__FPCLASS_PD
:
2558 return MSVCRT_FP_SUBNORMAL
;
2559 case MSVCRT__FPCLASS_NN
:
2560 case MSVCRT__FPCLASS_PN
:
2562 return MSVCRT_FP_NORMAL
;
2563 case MSVCRT__FPCLASS_NZ
:
2564 case MSVCRT__FPCLASS_PZ
:
2565 return MSVCRT_FP_ZERO
;
2569 /*********************************************************************
2570 * _fdclass (MSVCR120.@)
2572 short CDECL
MSVCR120__fdclass(float x
)
2574 return MSVCR120__dclass(x
);
2577 /*********************************************************************
2578 * _ldclass (MSVCR120.@)
2580 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
2582 return MSVCR120__dclass(x
);
2585 /*********************************************************************
2586 * _dtest (MSVCR120.@)
2588 short CDECL
MSVCR120__dtest(double *x
)
2590 return MSVCR120__dclass(*x
);
2593 /*********************************************************************
2594 * _fdtest (MSVCR120.@)
2596 short CDECL
MSVCR120__fdtest(float *x
)
2598 return MSVCR120__dclass(*x
);
2601 /*********************************************************************
2602 * _ldtest (MSVCR120.@)
2604 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
2606 return MSVCR120__dclass(*x
);