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_modff( float x
, float *iptr
)
338 return modff( x
, iptr
);
343 /*********************************************************************
344 * MSVCRT_acos (MSVCRT.@)
346 double CDECL
MSVCRT_acos( double x
)
348 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
349 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
350 * asin() uses a similar construction. This is bad because as x gets nearer to
351 * 1 the error in the expression "1 - x^2" can get relatively large due to
352 * cancellation. The sqrt() makes things worse. A safer way to calculate
353 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
354 return atan2(sqrt((1 - x
) * (1 + x
)), x
);
357 /*********************************************************************
358 * MSVCRT_asin (MSVCRT.@)
360 double CDECL
MSVCRT_asin( double x
)
362 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
363 return atan2(x
, sqrt((1 - x
) * (1 + x
)));
366 /*********************************************************************
367 * MSVCRT_atan (MSVCRT.@)
369 double CDECL
MSVCRT_atan( double x
)
371 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
375 /*********************************************************************
376 * MSVCRT_atan2 (MSVCRT.@)
378 double CDECL
MSVCRT_atan2( double x
, double y
)
380 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
384 /*********************************************************************
385 * MSVCRT_cos (MSVCRT.@)
387 double CDECL
MSVCRT_cos( double x
)
389 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
393 /*********************************************************************
394 * MSVCRT_cosh (MSVCRT.@)
396 double CDECL
MSVCRT_cosh( double x
)
398 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
402 /*********************************************************************
403 * MSVCRT_exp (MSVCRT.@)
405 double CDECL
MSVCRT_exp( double x
)
407 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
411 /*********************************************************************
412 * MSVCRT_fmod (MSVCRT.@)
414 double CDECL
MSVCRT_fmod( double x
, double y
)
416 if (!isfinite(x
) || !isfinite(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
420 /*********************************************************************
421 * MSVCRT_log (MSVCRT.@)
423 double CDECL
MSVCRT_log( double x
)
425 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
426 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
430 /*********************************************************************
431 * MSVCRT_log10 (MSVCRT.@)
433 double CDECL
MSVCRT_log10( double x
)
435 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
436 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
440 /*********************************************************************
441 * MSVCRT_pow (MSVCRT.@)
443 double CDECL
MSVCRT_pow( double x
, double y
)
445 /* FIXME: If x < 0 and y is not integral, set EDOM */
447 if (!isfinite(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
451 /*********************************************************************
452 * MSVCRT_sin (MSVCRT.@)
454 double CDECL
MSVCRT_sin( double x
)
456 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
460 /*********************************************************************
461 * MSVCRT_sinh (MSVCRT.@)
463 double CDECL
MSVCRT_sinh( double x
)
465 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
469 /*********************************************************************
470 * MSVCRT_sqrt (MSVCRT.@)
472 double CDECL
MSVCRT_sqrt( double x
)
474 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
478 /*********************************************************************
479 * MSVCRT_tan (MSVCRT.@)
481 double CDECL
MSVCRT_tan( double x
)
483 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
487 /*********************************************************************
488 * MSVCRT_tanh (MSVCRT.@)
490 double CDECL
MSVCRT_tanh( double x
)
492 if (isnan(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
497 #if defined(__GNUC__) && defined(__i386__)
499 #define FPU_DOUBLE(var) double var; \
500 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
501 #define FPU_DOUBLES(var1,var2) double var1,var2; \
502 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
503 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
505 /*********************************************************************
508 double CDECL
_CIacos(void)
511 return MSVCRT_acos(x
);
514 /*********************************************************************
517 double CDECL
_CIasin(void)
520 return MSVCRT_asin(x
);
523 /*********************************************************************
526 double CDECL
_CIatan(void)
529 return MSVCRT_atan(x
);
532 /*********************************************************************
533 * _CIatan2 (MSVCRT.@)
535 double CDECL
_CIatan2(void)
538 return MSVCRT_atan2(x
,y
);
541 /*********************************************************************
544 double CDECL
_CIcos(void)
547 return MSVCRT_cos(x
);
550 /*********************************************************************
553 double CDECL
_CIcosh(void)
556 return MSVCRT_cosh(x
);
559 /*********************************************************************
562 double CDECL
_CIexp(void)
565 return MSVCRT_exp(x
);
568 /*********************************************************************
571 double CDECL
_CIfmod(void)
574 return MSVCRT_fmod(x
,y
);
577 /*********************************************************************
580 double CDECL
_CIlog(void)
583 return MSVCRT_log(x
);
586 /*********************************************************************
587 * _CIlog10 (MSVCRT.@)
589 double CDECL
_CIlog10(void)
592 return MSVCRT_log10(x
);
595 /*********************************************************************
598 double CDECL
_CIpow(void)
601 return MSVCRT_pow(x
,y
);
604 /*********************************************************************
607 double CDECL
_CIsin(void)
610 return MSVCRT_sin(x
);
613 /*********************************************************************
616 double CDECL
_CIsinh(void)
619 return MSVCRT_sinh(x
);
622 /*********************************************************************
625 double CDECL
_CIsqrt(void)
628 return MSVCRT_sqrt(x
);
631 /*********************************************************************
634 double CDECL
_CItan(void)
637 return MSVCRT_tan(x
);
640 /*********************************************************************
643 double CDECL
_CItanh(void)
646 return MSVCRT_tanh(x
);
649 /*********************************************************************
652 LONGLONG CDECL
MSVCRT__ftol(void)
658 #endif /* defined(__GNUC__) && defined(__i386__) */
660 /*********************************************************************
661 * _fpclass (MSVCRT.@)
663 int CDECL
MSVCRT__fpclass(double num
)
665 #if defined(HAVE_FPCLASS) || defined(fpclass)
666 switch (fpclass( num
))
669 case FP_SNAN
: return MSVCRT__FPCLASS_SNAN
;
672 case FP_QNAN
: return MSVCRT__FPCLASS_QNAN
;
675 case FP_NINF
: return MSVCRT__FPCLASS_NINF
;
678 case FP_PINF
: return MSVCRT__FPCLASS_PINF
;
681 case FP_NDENORM
: return MSVCRT__FPCLASS_ND
;
684 case FP_PDENORM
: return MSVCRT__FPCLASS_PD
;
687 case FP_NZERO
: return MSVCRT__FPCLASS_NZ
;
690 case FP_PZERO
: return MSVCRT__FPCLASS_PZ
;
693 case FP_NNORM
: return MSVCRT__FPCLASS_NN
;
696 case FP_PNORM
: return MSVCRT__FPCLASS_PN
;
698 default: return MSVCRT__FPCLASS_PN
;
700 #elif defined (fpclassify)
701 switch (fpclassify( num
))
703 case FP_NAN
: return MSVCRT__FPCLASS_QNAN
;
704 case FP_INFINITE
: return signbit(num
) ? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
705 case FP_SUBNORMAL
: return signbit(num
) ?MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
706 case FP_ZERO
: return signbit(num
) ? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
708 return signbit(num
) ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
711 return MSVCRT__FPCLASS_QNAN
;
712 return num
== 0.0 ? MSVCRT__FPCLASS_PZ
: (num
< 0 ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
);
716 /*********************************************************************
719 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
722 return (num
<< shift
) | (num
>> (32-shift
));
725 /*********************************************************************
728 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
731 return (num
<< shift
) | (num
>> (32-shift
));
734 /*********************************************************************
737 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
740 return (num
>> shift
) | (num
<< (32-shift
));
743 /*********************************************************************
746 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
749 return (num
>> shift
) | (num
<< (32-shift
));
752 /*********************************************************************
755 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
758 return (num
<< shift
) | (num
>> (64-shift
));
761 /*********************************************************************
764 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
767 return (num
>> shift
) | (num
<< (64-shift
));
770 /*********************************************************************
773 int CDECL
MSVCRT_abs( int n
)
775 return n
>= 0 ? n
: -n
;
778 /*********************************************************************
781 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
783 return n
>= 0 ? n
: -n
;
786 /*********************************************************************
789 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
791 return n
>= 0 ? n
: -n
;
794 /*********************************************************************
797 __int64 CDECL
_abs64( __int64 n
)
799 return n
>= 0 ? n
: -n
;
802 /*********************************************************************
805 double CDECL
MSVCRT__logb(double num
)
807 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
811 /*********************************************************************
814 double CDECL
_hypot(double x
, double y
)
816 /* FIXME: errno handling */
817 return hypot( x
, y
);
820 /*********************************************************************
823 float CDECL
MSVCRT__hypotf(float x
, float y
)
825 /* FIXME: errno handling */
826 return hypotf( x
, y
);
829 /*********************************************************************
832 double CDECL
MSVCRT_ceil( double x
)
837 /*********************************************************************
840 double CDECL
MSVCRT_floor( double x
)
845 /*********************************************************************
848 double CDECL
MSVCRT_fabs( double x
)
853 /*********************************************************************
856 double CDECL
MSVCRT_frexp( double x
, int *exp
)
858 return frexp( x
, exp
);
861 /*********************************************************************
864 double CDECL
MSVCRT_modf( double x
, double *iptr
)
866 return modf( x
, iptr
);
869 /*********************************************************************
870 * _matherr (MSVCRT.@)
872 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
875 TRACE("(%p = %d, %s, %g %g %g)\n",e
, e
->type
, e
->name
, e
->arg1
, e
->arg2
,
879 if (MSVCRT_default_matherr_func
)
880 return MSVCRT_default_matherr_func(e
);
881 ERR(":Unhandled math error!\n");
885 /*********************************************************************
886 * __setusermatherr (MSVCRT.@)
888 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
890 MSVCRT_default_matherr_func
= func
;
891 TRACE(":new matherr handler %p\n", func
);
894 /**********************************************************************
895 * _statusfp2 (MSVCRT.@)
897 * Not exported by native msvcrt, added in msvcr80.
899 #if defined(__i386__) || defined(__x86_64__)
900 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
904 unsigned long fpword
;
908 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
910 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
911 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
912 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
913 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
914 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
915 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
919 if (!sse2_sw
) return;
923 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
925 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
926 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
927 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
928 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
929 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
930 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
935 FIXME( "not implemented\n" );
940 /**********************************************************************
941 * _statusfp (MSVCRT.@)
943 unsigned int CDECL
_statusfp(void)
945 #if defined(__i386__) || defined(__x86_64__)
946 unsigned int x86_sw
, sse2_sw
;
948 _statusfp2( &x86_sw
, &sse2_sw
);
949 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
950 return x86_sw
| sse2_sw
;
952 FIXME( "not implemented\n" );
957 /*********************************************************************
958 * _clearfp (MSVCRT.@)
960 unsigned int CDECL
_clearfp(void)
962 unsigned int flags
= 0;
963 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
964 unsigned long fpword
;
966 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
967 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
968 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
969 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
970 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
971 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
972 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
976 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
977 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
978 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
979 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
980 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
981 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
982 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
984 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
987 FIXME( "not implemented\n" );
992 /*********************************************************************
993 * __fpecode (MSVCRT.@)
995 int * CDECL
__fpecode(void)
997 return &msvcrt_get_thread_data()->fpecode
;
1000 /*********************************************************************
1003 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1005 double z
= ldexp(num
,exp
);
1008 *MSVCRT__errno() = MSVCRT_ERANGE
;
1009 else if (z
== 0 && signbit(z
))
1010 z
= 0.0; /* Convert -0 -> +0 */
1014 /*********************************************************************
1017 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1019 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1022 /*********************************************************************
1023 * _chgsign (MSVCRT.@)
1025 double CDECL
MSVCRT__chgsign(double num
)
1027 /* FIXME: +-infinity,Nan not tested */
1031 /*********************************************************************
1032 * __control87_2 (MSVCRT.@)
1034 * Not exported by native msvcrt, added in msvcr80.
1036 #if defined(__i386__) || defined(__x86_64__)
1037 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1038 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1041 unsigned long fpword
;
1046 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1048 /* Convert into mask constants */
1050 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1051 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1052 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1053 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1054 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1055 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1056 switch (fpword
& 0xc00)
1058 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1059 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1060 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1062 switch (fpword
& 0x300)
1064 case 0x0: flags
|= MSVCRT__PC_24
; break;
1065 case 0x200: flags
|= MSVCRT__PC_53
; break;
1066 case 0x300: flags
|= MSVCRT__PC_64
; break;
1068 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1070 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1073 flags
= (flags
& ~mask
) | (newval
& mask
);
1075 /* Convert (masked) value back to fp word */
1077 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1078 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1079 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1080 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1081 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1082 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1083 switch (flags
& MSVCRT__MCW_RC
)
1085 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1086 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1087 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1089 switch (flags
& MSVCRT__MCW_PC
)
1091 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1092 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1093 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1095 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1097 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1102 if (!sse2_cw
) return 1;
1106 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1108 /* Convert into mask constants */
1110 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1111 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1112 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1113 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1114 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1115 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1116 switch (fpword
& 0x6000)
1118 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1119 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1120 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1122 switch (fpword
& 0x8040)
1124 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1125 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1126 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1129 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1132 flags
= (flags
& ~mask
) | (newval
& mask
);
1134 /* Convert (masked) value back to fp word */
1136 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1137 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1138 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1139 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1140 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1141 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1142 switch (flags
& MSVCRT__MCW_RC
)
1144 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1145 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1146 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1148 switch (flags
& MSVCRT__MCW_DN
)
1150 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1151 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1152 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1154 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1162 FIXME( "not implemented\n" );
1168 /*********************************************************************
1169 * _control87 (MSVCRT.@)
1171 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1173 #if defined(__i386__) || defined(__x86_64__)
1174 unsigned int x86_cw
, sse2_cw
;
1176 __control87_2( newval
, mask
, &x86_cw
, &sse2_cw
);
1178 if ((x86_cw
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) x86_cw
|= MSVCRT__EM_AMBIGUOUS
;
1181 FIXME( "not implemented\n" );
1186 /*********************************************************************
1187 * _controlfp (MSVCRT.@)
1189 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
1191 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
1194 /*********************************************************************
1195 * _set_controlfp (MSVCRT.@)
1197 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
1199 _controlfp( newval
, mask
);
1202 /*********************************************************************
1203 * _controlfp_s (MSVCRT.@)
1205 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
1207 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
1208 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
1211 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
1213 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
1214 return MSVCRT_EINVAL
;
1216 val
= _controlfp( newval
, mask
);
1217 if (cur
) *cur
= val
;
1221 /*********************************************************************
1222 * _copysign (MSVCRT.@)
1224 double CDECL
MSVCRT__copysign(double num
, double sign
)
1227 return signbit(num
) ? num
: -num
;
1228 return signbit(num
) ? -num
: num
;
1231 /*********************************************************************
1232 * _finite (MSVCRT.@)
1234 int CDECL
MSVCRT__finite(double num
)
1236 return isfinite(num
) != 0; /* See comment for _isnan() */
1239 /*********************************************************************
1240 * _fpreset (MSVCRT.@)
1242 void CDECL
_fpreset(void)
1244 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1245 const unsigned int x86_cw
= 0x27f;
1246 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
1249 const unsigned long sse2_cw
= 0x1f80;
1250 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
1253 FIXME( "not implemented\n" );
1257 /*********************************************************************
1260 INT CDECL
MSVCRT__isnan(double num
)
1262 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1263 * Do the same, as the result may be used in calculations
1265 return isnan(num
) != 0;
1268 /*********************************************************************
1271 double CDECL
MSVCRT__j0(double num
)
1273 /* FIXME: errno handling */
1277 /*********************************************************************
1280 double CDECL
MSVCRT__j1(double num
)
1282 /* FIXME: errno handling */
1286 /*********************************************************************
1289 double CDECL
MSVCRT__jn(int n
, double num
)
1291 /* FIXME: errno handling */
1295 /*********************************************************************
1298 double CDECL
MSVCRT__y0(double num
)
1301 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1303 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1305 *MSVCRT__errno() = MSVCRT_EDOM
;
1311 /*********************************************************************
1314 double CDECL
MSVCRT__y1(double num
)
1317 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1319 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1321 *MSVCRT__errno() = MSVCRT_EDOM
;
1327 /*********************************************************************
1330 double CDECL
MSVCRT__yn(int order
, double num
)
1333 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1334 retval
= yn(order
,num
);
1335 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1337 *MSVCRT__errno() = MSVCRT_EDOM
;
1343 /*********************************************************************
1344 * _nextafter (MSVCRT.@)
1346 double CDECL
MSVCRT__nextafter(double num
, double next
)
1349 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1350 retval
= nextafter(num
,next
);
1354 /*********************************************************************
1357 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
1360 thread_data_t
*data
= msvcrt_get_thread_data();
1361 /* FIXME: check better for overflow (native supports over 300 chars) */
1362 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
1363 * 4 for exponent and one for
1364 * terminating '\0' */
1365 if (!data
->efcvt_buffer
)
1366 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1373 /* handle cases with zero ndigits or less */
1375 if( prec
< 1) prec
= 2;
1376 len
= snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
1377 /* take the decimal "point away */
1379 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
1380 /* take the exponential "e" out */
1381 data
->efcvt_buffer
[ prec
] = '\0';
1382 /* read the exponent */
1383 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
1385 /* adjust for some border cases */
1386 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
1388 /* handle cases with zero ndigits or less */
1390 if( data
->efcvt_buffer
[ 0] >= '5')
1392 data
->efcvt_buffer
[ 0] = '\0';
1394 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
1395 return data
->efcvt_buffer
;
1398 /*********************************************************************
1399 * _ecvt_s (MSVCRT.@)
1401 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
1405 const char infret
[] = "1#INF";
1407 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
1408 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
1409 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
1410 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1411 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1413 /* special case - inf */
1414 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
1416 memset(buffer
, '0', ndigits
);
1417 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
1418 buffer
[ndigits
] = '\0';
1420 if(number
== -HUGE_VAL
)
1426 /* handle cases with zero ndigits or less */
1428 if( prec
< 1) prec
= 2;
1429 result
= MSVCRT_malloc(prec
+ 7);
1436 len
= snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
1437 /* take the decimal "point away */
1439 memmove( result
+ 1, result
+ 2, len
- 1 );
1440 /* take the exponential "e" out */
1441 result
[ prec
] = '\0';
1442 /* read the exponent */
1443 sscanf( result
+ prec
+ 1, "%d", decpt
);
1445 /* adjust for some border cases */
1446 if( result
[0] == '0')/* value is zero */
1448 /* handle cases with zero ndigits or less */
1450 if( result
[ 0] >= '5')
1454 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
1455 MSVCRT_free( result
);
1459 /***********************************************************************
1462 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
1464 thread_data_t
*data
= msvcrt_get_thread_data();
1465 int stop
, dec1
, dec2
;
1466 char *ptr1
, *ptr2
, *first
;
1467 char buf
[80]; /* ought to be enough */
1469 if (!data
->efcvt_buffer
)
1470 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1478 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1480 ptr2
= data
->efcvt_buffer
;
1485 /* For numbers below the requested resolution, work out where
1486 the decimal point will be rather than finding it in the string */
1487 if (number
< 1.0 && number
> 0.0) {
1488 dec2
= log10(number
+ 1e-10);
1489 if (-dec2
<= ndigits
) dec2
= 0;
1492 /* If requested digits is zero or less, we will need to truncate
1493 * the returned string */
1495 stop
= strlen(buf
) + ndigits
;
1500 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1501 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1502 if (!first
) first
= ptr2
;
1503 if ((ptr1
- buf
) < stop
) {
1514 while (*ptr1
== '0') { /* Process leading zeroes */
1519 while (*ptr1
!= '\0') {
1520 if (!first
) first
= ptr2
;
1527 /* We never found a non-zero digit, then our number is either
1528 * smaller than the requested precision, or 0.0 */
1533 first
= data
->efcvt_buffer
;
1538 *decpt
= dec2
? dec2
: dec1
;
1542 /***********************************************************************
1543 * _fcvt_s (MSVCRT.@)
1545 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
1547 int stop
, dec1
, dec2
;
1548 char *ptr1
, *ptr2
, *first
;
1549 char buf
[80]; /* ought to be enough */
1551 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
1553 *MSVCRT__errno() = MSVCRT_EINVAL
;
1554 return MSVCRT_EINVAL
;
1563 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1570 /* For numbers below the requested resolution, work out where
1571 the decimal point will be rather than finding it in the string */
1572 if (number
< 1.0 && number
> 0.0) {
1573 dec2
= log10(number
+ 1e-10);
1574 if (-dec2
<= ndigits
) dec2
= 0;
1577 /* If requested digits is zero or less, we will need to truncate
1578 * the returned string */
1580 stop
= strlen(buf
) + ndigits
;
1585 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1586 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1587 if (!first
) first
= ptr2
;
1588 if ((ptr1
- buf
) < stop
) {
1602 while (*ptr1
== '0') { /* Process leading zeroes */
1603 if (number
== 0.0 && size
> 1) {
1611 while (*ptr1
!= '\0') {
1612 if (!first
) first
= ptr2
;
1622 /* We never found a non-zero digit, then our number is either
1623 * smaller than the requested precision, or 0.0 */
1624 if (!first
&& (number
<= 0.0))
1627 *decpt
= dec2
? dec2
: dec1
;
1631 /***********************************************************************
1634 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
1637 *MSVCRT__errno() = MSVCRT_EINVAL
;
1642 *MSVCRT__errno() = MSVCRT_ERANGE
;
1646 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
1650 /***********************************************************************
1651 * _gcvt_s (MSVCRT.@)
1653 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
1658 *MSVCRT__errno() = MSVCRT_EINVAL
;
1659 return MSVCRT_EINVAL
;
1662 if( digits
<0 || digits
>=size
) {
1666 *MSVCRT__errno() = MSVCRT_ERANGE
;
1667 return MSVCRT_ERANGE
;
1670 len
= MSVCRT__scprintf("%.*g", digits
, number
);
1673 *MSVCRT__errno() = MSVCRT_ERANGE
;
1674 return MSVCRT_ERANGE
;
1677 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
1681 #include <stdlib.h> /* div_t, ldiv_t */
1683 /*********************************************************************
1686 * [i386] Windows binary compatible - returns the struct in eax/edx.
1689 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
1691 div_t dt
= div(num
,denom
);
1692 return ((unsigned __int64
)dt
.rem
<< 32) | (unsigned int)dt
.quot
;
1695 /*********************************************************************
1698 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1700 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
1702 div_t dt
= div(num
,denom
);
1710 #endif /* ifdef __i386__ */
1713 /*********************************************************************
1716 * [i386] Windows binary compatible - returns the struct in eax/edx.
1719 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1721 ldiv_t ldt
= ldiv(num
,denom
);
1722 return ((unsigned __int64
)ldt
.rem
<< 32) | (MSVCRT_ulong
)ldt
.quot
;
1725 /*********************************************************************
1728 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1730 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1732 ldiv_t result
= ldiv(num
,denom
);
1735 ret
.quot
= result
.quot
;
1736 ret
.rem
= result
.rem
;
1740 #endif /* ifdef __i386__ */
1744 /*********************************************************************
1745 * _adjust_fdiv (MSVCRT.@)
1746 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1748 int MSVCRT__adjust_fdiv
= 0;
1750 /***********************************************************************
1751 * _adj_fdiv_m16i (MSVCRT.@)
1754 * I _think_ this function is intended to work around the Pentium
1757 void __stdcall
_adj_fdiv_m16i( short arg
)
1759 TRACE("(): stub\n");
1762 /***********************************************************************
1763 * _adj_fdiv_m32 (MSVCRT.@)
1766 * I _think_ this function is intended to work around the Pentium
1769 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
1771 TRACE("(): stub\n");
1774 /***********************************************************************
1775 * _adj_fdiv_m32i (MSVCRT.@)
1778 * I _think_ this function is intended to work around the Pentium
1781 void __stdcall
_adj_fdiv_m32i( int arg
)
1783 TRACE("(): stub\n");
1786 /***********************************************************************
1787 * _adj_fdiv_m64 (MSVCRT.@)
1790 * I _think_ this function is intended to work around the Pentium
1793 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
1795 TRACE("(): stub\n");
1798 /***********************************************************************
1799 * _adj_fdiv_r (MSVCRT.@)
1801 * This function is likely to have the wrong number of arguments.
1804 * I _think_ this function is intended to work around the Pentium
1807 void _adj_fdiv_r(void)
1809 TRACE("(): stub\n");
1812 /***********************************************************************
1813 * _adj_fdivr_m16i (MSVCRT.@)
1816 * I _think_ this function is intended to work around the Pentium
1819 void __stdcall
_adj_fdivr_m16i( short arg
)
1821 TRACE("(): stub\n");
1824 /***********************************************************************
1825 * _adj_fdivr_m32 (MSVCRT.@)
1828 * I _think_ this function is intended to work around the Pentium
1831 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
1833 TRACE("(): stub\n");
1836 /***********************************************************************
1837 * _adj_fdivr_m32i (MSVCRT.@)
1840 * I _think_ this function is intended to work around the Pentium
1843 void __stdcall
_adj_fdivr_m32i( int arg
)
1845 TRACE("(): stub\n");
1848 /***********************************************************************
1849 * _adj_fdivr_m64 (MSVCRT.@)
1852 * I _think_ this function is intended to work around the Pentium
1855 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
1857 TRACE("(): stub\n");
1860 /***********************************************************************
1861 * _adj_fpatan (MSVCRT.@)
1863 * This function is likely to have the wrong number of arguments.
1866 * I _think_ this function is intended to work around the Pentium
1869 void _adj_fpatan(void)
1871 TRACE("(): stub\n");
1874 /***********************************************************************
1875 * _adj_fprem (MSVCRT.@)
1877 * This function is likely to have the wrong number of arguments.
1880 * I _think_ this function is intended to work around the Pentium
1883 void _adj_fprem(void)
1885 TRACE("(): stub\n");
1888 /***********************************************************************
1889 * _adj_fprem1 (MSVCRT.@)
1891 * This function is likely to have the wrong number of arguments.
1894 * I _think_ this function is intended to work around the Pentium
1897 void _adj_fprem1(void)
1899 TRACE("(): stub\n");
1902 /***********************************************************************
1903 * _adj_fptan (MSVCRT.@)
1905 * This function is likely to have the wrong number of arguments.
1908 * I _think_ this function is intended to work around the Pentium
1911 void _adj_fptan(void)
1913 TRACE("(): stub\n");
1916 /***********************************************************************
1917 * _safe_fdiv (MSVCRT.@)
1919 * This function is likely to have the wrong number of arguments.
1922 * I _think_ this function is intended to work around the Pentium
1925 void _safe_fdiv(void)
1927 TRACE("(): stub\n");
1930 /***********************************************************************
1931 * _safe_fdivr (MSVCRT.@)
1933 * This function is likely to have the wrong number of arguments.
1936 * I _think_ this function is intended to work around the Pentium
1939 void _safe_fdivr(void)
1941 TRACE("(): stub\n");
1944 /***********************************************************************
1945 * _safe_fprem (MSVCRT.@)
1947 * This function is likely to have the wrong number of arguments.
1950 * I _think_ this function is intended to work around the Pentium
1953 void _safe_fprem(void)
1955 TRACE("(): stub\n");
1958 /***********************************************************************
1959 * _safe_fprem1 (MSVCRT.@)
1962 * This function is likely to have the wrong number of arguments.
1965 * I _think_ this function is intended to work around the Pentium
1968 void _safe_fprem1(void)
1970 TRACE("(): stub\n");
1973 /***********************************************************************
1974 * __libm_sse2_acos (MSVCRT.@)
1976 void __cdecl
MSVCRT___libm_sse2_acos(void)
1979 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
1981 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
1984 /***********************************************************************
1985 * __libm_sse2_acosf (MSVCRT.@)
1987 void __cdecl
MSVCRT___libm_sse2_acosf(void)
1990 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
1992 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
1995 /***********************************************************************
1996 * __libm_sse2_asin (MSVCRT.@)
1998 void __cdecl
MSVCRT___libm_sse2_asin(void)
2001 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2003 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2006 /***********************************************************************
2007 * __libm_sse2_asinf (MSVCRT.@)
2009 void __cdecl
MSVCRT___libm_sse2_asinf(void)
2012 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2014 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2017 /***********************************************************************
2018 * __libm_sse2_atan (MSVCRT.@)
2020 void __cdecl
MSVCRT___libm_sse2_atan(void)
2023 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2025 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2028 /***********************************************************************
2029 * __libm_sse2_atan2 (MSVCRT.@)
2031 void __cdecl
MSVCRT___libm_sse2_atan2(void)
2034 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2035 d1
= atan2( d1
, d2
);
2036 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2039 /***********************************************************************
2040 * __libm_sse2_atanf (MSVCRT.@)
2042 void __cdecl
MSVCRT___libm_sse2_atanf(void)
2045 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2047 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2050 /***********************************************************************
2051 * __libm_sse2_cos (MSVCRT.@)
2053 void __cdecl
MSVCRT___libm_sse2_cos(void)
2056 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2058 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2061 /***********************************************************************
2062 * __libm_sse2_cosf (MSVCRT.@)
2064 void __cdecl
MSVCRT___libm_sse2_cosf(void)
2067 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2069 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2072 /***********************************************************************
2073 * __libm_sse2_exp (MSVCRT.@)
2075 void __cdecl
MSVCRT___libm_sse2_exp(void)
2078 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2080 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2083 /***********************************************************************
2084 * __libm_sse2_expf (MSVCRT.@)
2086 void __cdecl
MSVCRT___libm_sse2_expf(void)
2089 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2091 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2094 /***********************************************************************
2095 * __libm_sse2_log (MSVCRT.@)
2097 void __cdecl
MSVCRT___libm_sse2_log(void)
2100 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2102 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2105 /***********************************************************************
2106 * __libm_sse2_log10 (MSVCRT.@)
2108 void __cdecl
MSVCRT___libm_sse2_log10(void)
2111 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2113 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2116 /***********************************************************************
2117 * __libm_sse2_log10f (MSVCRT.@)
2119 void __cdecl
MSVCRT___libm_sse2_log10f(void)
2122 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2124 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2127 /***********************************************************************
2128 * __libm_sse2_logf (MSVCRT.@)
2130 void __cdecl
MSVCRT___libm_sse2_logf(void)
2133 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2135 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2138 /***********************************************************************
2139 * __libm_sse2_pow (MSVCRT.@)
2141 void __cdecl
MSVCRT___libm_sse2_pow(void)
2144 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2146 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2149 /***********************************************************************
2150 * __libm_sse2_powf (MSVCRT.@)
2152 void __cdecl
MSVCRT___libm_sse2_powf(void)
2155 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
2156 f1
= powf( f1
, f2
);
2157 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
2160 /***********************************************************************
2161 * __libm_sse2_sin (MSVCRT.@)
2163 void __cdecl
MSVCRT___libm_sse2_sin(void)
2166 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2168 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2171 /***********************************************************************
2172 * __libm_sse2_sinf (MSVCRT.@)
2174 void __cdecl
MSVCRT___libm_sse2_sinf(void)
2177 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2179 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2182 /***********************************************************************
2183 * __libm_sse2_tan (MSVCRT.@)
2185 void __cdecl
MSVCRT___libm_sse2_tan(void)
2188 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2190 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2193 /***********************************************************************
2194 * __libm_sse2_tanf (MSVCRT.@)
2196 void __cdecl
MSVCRT___libm_sse2_tanf(void)
2199 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2201 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2204 /***********************************************************************
2205 * __libm_sse2_sqrt_precise (MSVCR110.@)
2207 void __cdecl
MSVCRT___libm_sse2_sqrt_precise(void)
2210 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2212 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2215 #endif /* __i386__ */
2217 /*********************************************************************
2220 double CDECL
MSVCR120_cbrt(double x
)
2225 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
2229 /*********************************************************************
2230 * cbrtf (MSVCR120.@)
2232 float CDECL
MSVCR120_cbrtf(float x
)
2237 return MSVCR120_cbrt(x
);
2241 /*********************************************************************
2242 * cbrtl (MSVCR120.@)
2244 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
2246 return MSVCR120_cbrt(x
);
2249 /*********************************************************************
2252 double CDECL
MSVCR120_exp2(double x
)
2261 /*********************************************************************
2262 * exp2f (MSVCR120.@)
2264 float CDECL
MSVCR120_exp2f(float x
)
2269 return MSVCR120_exp2(x
);
2273 /*********************************************************************
2274 * exp2l (MSVCR120.@)
2276 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
2278 return MSVCR120_exp2(x
);
2281 /*********************************************************************
2284 double CDECL
MSVCR120_log2(double x
)
2289 return log(x
) / log(2);
2293 /*********************************************************************
2294 * log2f (MSVCR120.@)
2296 float CDECL
MSVCR120_log2f(float x
)
2301 return MSVCR120_log2(x
);
2305 /*********************************************************************
2306 * log2l (MSVCR120.@)
2308 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
2310 return MSVCR120_log2(x
);
2313 /*********************************************************************
2316 double CDECL
MSVCR120_rint(double x
)
2321 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
2325 /*********************************************************************
2326 * rintf (MSVCR120.@)
2328 float CDECL
MSVCR120_rintf(float x
)
2333 return MSVCR120_rint(x
);
2337 /*********************************************************************
2338 * rintl (MSVCR120.@)
2340 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
2342 return MSVCR120_rint(x
);
2345 /*********************************************************************
2346 * lrint (MSVCR120.@)
2348 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
2353 return MSVCR120_rint(x
);
2357 /*********************************************************************
2358 * lrintf (MSVCR120.@)
2360 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
2365 return MSVCR120_lrint(x
);
2369 /*********************************************************************
2370 * lrintl (MSVCR120.@)
2372 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
2374 return MSVCR120_lrint(x
);
2377 /*********************************************************************
2378 * llrint (MSVCR120.@)
2380 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
2385 return MSVCR120_rint(x
);
2389 /*********************************************************************
2390 * llrintf (MSVCR120.@)
2392 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
2397 return MSVCR120_llrint(x
);
2401 /*********************************************************************
2402 * rintl (MSVCR120.@)
2404 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
2406 return MSVCR120_llrint(x
);
2409 /*********************************************************************
2410 * round (MSVCR120.@)
2412 double CDECL
MSVCR120_round(double x
)
2417 return MSVCR120_rint(x
);
2421 /*********************************************************************
2422 * roundf (MSVCR120.@)
2424 float CDECL
MSVCR120_roundf(float x
)
2429 return MSVCR120_round(x
);
2433 /*********************************************************************
2434 * roundl (MSVCR120.@)
2436 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
2438 return MSVCR120_round(x
);
2441 /*********************************************************************
2442 * lround (MSVCR120.@)
2444 MSVCRT_long CDECL
MSVCR120_lround(double x
)
2449 return MSVCR120_round(x
);
2453 /*********************************************************************
2454 * lroundf (MSVCR120.@)
2456 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
2461 return MSVCR120_lround(x
);
2465 /*********************************************************************
2466 * lroundl (MSVCR120.@)
2468 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
2470 return MSVCR120_lround(x
);
2473 /*********************************************************************
2474 * llround (MSVCR120.@)
2476 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
2481 return MSVCR120_round(x
);
2485 /*********************************************************************
2486 * llroundf (MSVCR120.@)
2488 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
2490 #ifdef HAVE_LLROUNDF
2493 return MSVCR120_llround(x
);
2497 /*********************************************************************
2498 * roundl (MSVCR120.@)
2500 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
2502 return MSVCR120_llround(x
);
2505 /*********************************************************************
2506 * trunc (MSVCR120.@)
2508 double CDECL
MSVCR120_trunc(double x
)
2513 return (x
> 0) ? floor(x
) : ceil(x
);
2517 /*********************************************************************
2518 * truncf (MSVCR120.@)
2520 float CDECL
MSVCR120_truncf(float x
)
2525 return MSVCR120_trunc(x
);
2529 /*********************************************************************
2530 * truncl (MSVCR120.@)
2532 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
2534 return MSVCR120_trunc(x
);
2537 /*********************************************************************
2538 * _dclass (MSVCR120.@)
2540 short CDECL
MSVCR120__dclass(double x
)
2542 switch (MSVCRT__fpclass(x
)) {
2543 case MSVCRT__FPCLASS_QNAN
:
2544 case MSVCRT__FPCLASS_SNAN
:
2545 return MSVCRT_FP_NAN
;
2546 case MSVCRT__FPCLASS_NINF
:
2547 case MSVCRT__FPCLASS_PINF
:
2548 return MSVCRT_FP_INFINITE
;
2549 case MSVCRT__FPCLASS_ND
:
2550 case MSVCRT__FPCLASS_PD
:
2551 return MSVCRT_FP_SUBNORMAL
;
2552 case MSVCRT__FPCLASS_NN
:
2553 case MSVCRT__FPCLASS_PN
:
2555 return MSVCRT_FP_NORMAL
;
2556 case MSVCRT__FPCLASS_NZ
:
2557 case MSVCRT__FPCLASS_PZ
:
2558 return MSVCRT_FP_ZERO
;
2562 /*********************************************************************
2563 * _fdclass (MSVCR120.@)
2565 short CDECL
MSVCR120__fdclass(float x
)
2567 return MSVCR120__dclass(x
);
2570 /*********************************************************************
2571 * _ldclass (MSVCR120.@)
2573 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
2575 return MSVCR120__dclass(x
);
2578 /*********************************************************************
2579 * _dtest (MSVCR120.@)
2581 short CDECL
MSVCR120__dtest(double *x
)
2583 return MSVCR120__dclass(*x
);
2586 /*********************************************************************
2587 * _fdtest (MSVCR120.@)
2589 short CDECL
MSVCR120__fdtest(float *x
)
2591 return MSVCR120__dclass(*x
);
2594 /*********************************************************************
2595 * _ldtest (MSVCR120.@)
2597 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
2599 return MSVCR120__dclass(*x
);
2602 /*********************************************************************
2605 float CDECL
MSVCR120_erff(float x
)
2610 FIXME( "not implemented\n" );
2615 /*********************************************************************
2618 double CDECL
MSVCR120_erf(double x
)
2623 FIXME( "not implemented\n" );
2628 /*********************************************************************
2631 LDOUBLE CDECL
MSVCR120_erfl(LDOUBLE x
)
2633 return MSVCR120_erf(x
);
2636 /*********************************************************************
2637 * fmaxf (MSVCR120.@)
2639 float CDECL
MSVCR120_fmaxf(float x
, float y
)
2646 return signbit(x
) ? y
: x
;
2650 /*********************************************************************
2653 double CDECL
MSVCR120_fmax(double x
, double y
)
2660 return signbit(x
) ? y
: x
;
2664 /*********************************************************************
2665 * _fdsign (MSVCR120.@)
2667 int CDECL
MSVCR120__fdsign(float x
)
2669 return signbit(x
) ? 0x8000 : 0;
2672 /*********************************************************************
2673 * _dsign (MSVCR120.@)
2675 int CDECL
MSVCR120__dsign(double x
)
2677 return signbit(x
) ? 0x8000 : 0;
2681 /*********************************************************************
2682 * _dpcomp (MSVCR120.@)
2684 int CDECL
MSVCR120__dpcomp(double x
, double y
)
2686 if(isnan(x
) || isnan(y
))
2689 if(x
== y
) return 2;
2690 return x
< y
? 1 : 4;
2693 /*********************************************************************
2694 * _fdpcomp (MSVCR120.@)
2696 int CDECL
MSVCR120__fdpcomp(float x
, float y
)
2698 return MSVCR120__dpcomp(x
, y
);
2701 /*********************************************************************
2702 * fminf (MSVCR120.@)
2704 float CDECL
MSVCR120_fminf(float x
, float y
)
2711 return signbit(x
) ? x
: y
;
2715 /*********************************************************************
2718 double CDECL
MSVCR120_fmin(double x
, double y
)
2725 return signbit(x
) ? x
: y
;
2729 /*********************************************************************
2730 * asinh (MSVCR120.@)
2732 double CDECL
MSVCR120_asinh(double x
)
2737 FIXME( "not implemented\n" );
2742 /*********************************************************************
2743 * asinhf (MSVCR120.@)
2745 float CDECL
MSVCR120_asinhf(float x
)
2750 FIXME( "not implemented\n" );
2755 /*********************************************************************
2756 * asinhl (MSVCR120.@)
2758 LDOUBLE CDECL
MSVCR120_asinhl(LDOUBLE x
)
2760 return MSVCR120_asinh(x
);
2763 /*********************************************************************
2765 * scalbn (MSVCR120.@)
2766 * scalbln (MSVCR120.@)
2768 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
2770 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2771 return ldexp(num
, power
);
2774 /*********************************************************************
2775 * _scalbf (MSVCRT.@)
2776 * scalbnf (MSVCR120.@)
2777 * scalblnf (MSVCR120.@)
2779 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
2781 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2782 return ldexpf(num
, power
);
2785 /*********************************************************************
2786 * scalbnl (MSVCR120.@)
2787 * scalblnl (MSVCR120.@)
2789 LDOUBLE CDECL
MSVCR120_scalbnl(LDOUBLE num
, MSVCRT_long power
)
2791 return MSVCRT__scalb(num
, power
);
2794 /*********************************************************************
2795 * remainder (MSVCR120.@)
2797 double CDECL
MSVCR120_remainder(double x
, double y
)
2799 #ifdef HAVE_REMAINDER
2800 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2801 if(!finite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2802 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
2803 return remainder(x
, y
);
2805 FIXME( "not implemented\n" );
2810 /*********************************************************************
2811 * remainderf (MSVCR120.@)
2813 float CDECL
MSVCR120_remainderf(float x
, float y
)
2815 #ifdef HAVE_REMAINDERF
2816 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
2817 if(!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2818 if(isnanf(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
2819 return remainderf(x
, y
);
2821 FIXME( "not implemented\n" );
2826 /*********************************************************************
2827 * remainderl (MSVCR120.@)
2829 LDOUBLE CDECL
MSVCR120_remainderl(LDOUBLE x
, LDOUBLE y
)
2831 return MSVCR120_remainder(x
, y
);