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)
53 typedef int (CDECL
*MSVCRT_matherr_func
)(struct MSVCRT__exception
*);
54 typedef double LDOUBLE
; /* long double is just a double */
56 static MSVCRT_matherr_func MSVCRT_default_matherr_func
= NULL
;
58 static BOOL sse2_supported
;
59 static BOOL sse2_enabled
;
61 void msvcrt_init_math(void)
63 sse2_supported
= sse2_enabled
= IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE
);
66 /*********************************************************************
67 * _set_SSE2_enable (MSVCRT.@)
69 int CDECL
MSVCRT__set_SSE2_enable(int flag
)
71 sse2_enabled
= flag
&& sse2_supported
;
75 #if defined(__x86_64__) || defined(__arm__)
77 /*********************************************************************
78 * _chgsignf (MSVCRT.@)
80 float CDECL
MSVCRT__chgsignf( float num
)
82 /* FIXME: +-infinity,Nan not tested */
86 /*********************************************************************
87 * _copysignf (MSVCRT.@)
89 float CDECL
MSVCRT__copysignf( float num
, float sign
)
91 /* FIXME: Behaviour for Nan/Inf? */
93 return num
< 0.0 ? num
: -num
;
94 return num
< 0.0 ? -num
: num
;
97 /*********************************************************************
100 int CDECL
MSVCRT__finitef( float num
)
102 return finitef(num
) != 0; /* See comment for _isnan() */
105 /*********************************************************************
108 INT CDECL
MSVCRT__isnanf( float num
)
110 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
111 * Do the same, as the result may be used in calculations
113 return isnanf(num
) != 0;
116 /*********************************************************************
119 float CDECL
MSVCRT__logbf( float num
)
121 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
125 /*********************************************************************
126 * _nextafterf (MSVCRT.@)
128 float CDECL
MSVCRT__nextafterf( float num
, float next
)
130 if (!finitef(num
) || !finitef(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
131 return nextafterf( num
, next
);
134 /*********************************************************************
135 * MSVCRT_acosf (MSVCRT.@)
137 float CDECL
MSVCRT_acosf( float x
)
139 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
140 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
141 * asin() uses a similar construction. This is bad because as x gets nearer to
142 * 1 the error in the expression "1 - x^2" can get relatively large due to
143 * cancellation. The sqrt() makes things worse. A safer way to calculate
144 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
145 return atan2f(sqrtf((1 - x
) * (1 + x
)), x
);
148 /*********************************************************************
149 * MSVCRT_asinf (MSVCRT.@)
151 float CDECL
MSVCRT_asinf( float x
)
153 if (x
< -1.0 || x
> 1.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
154 return atan2f(x
, sqrtf((1 - x
) * (1 + x
)));
157 /*********************************************************************
158 * MSVCRT_atanf (MSVCRT.@)
160 float CDECL
MSVCRT_atanf( float x
)
162 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
166 /*********************************************************************
167 * MSVCRT_atan2f (MSVCRT.@)
169 float CDECL
MSVCRT_atan2f( float x
, float y
)
171 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
175 /*********************************************************************
176 * MSVCRT_cosf (MSVCRT.@)
178 float CDECL
MSVCRT_cosf( float x
)
180 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
184 /*********************************************************************
185 * MSVCRT_coshf (MSVCRT.@)
187 float CDECL
MSVCRT_coshf( float x
)
189 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
193 /*********************************************************************
194 * MSVCRT_expf (MSVCRT.@)
196 float CDECL
MSVCRT_expf( float x
)
198 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
202 /*********************************************************************
203 * MSVCRT_fmodf (MSVCRT.@)
205 float CDECL
MSVCRT_fmodf( float x
, float y
)
207 if (!finitef(x
) || !finitef(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
211 /*********************************************************************
212 * MSVCRT_logf (MSVCRT.@)
214 float CDECL
MSVCRT_logf( float x
)
216 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
217 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
221 /*********************************************************************
222 * MSVCRT_log10f (MSVCRT.@)
224 float CDECL
MSVCRT_log10f( float x
)
226 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
227 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
231 /*********************************************************************
232 * MSVCRT_powf (MSVCRT.@)
234 float CDECL
MSVCRT_powf( float x
, float y
)
236 /* FIXME: If x < 0 and y is not integral, set EDOM */
238 if (!finitef(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
242 /*********************************************************************
243 * MSVCRT_sinf (MSVCRT.@)
245 float CDECL
MSVCRT_sinf( float x
)
247 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
251 /*********************************************************************
252 * MSVCRT_sinhf (MSVCRT.@)
254 float CDECL
MSVCRT_sinhf( float x
)
256 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
260 /*********************************************************************
261 * MSVCRT_sqrtf (MSVCRT.@)
263 float CDECL
MSVCRT_sqrtf( float x
)
265 if (x
< 0.0 || !finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
269 /*********************************************************************
270 * MSVCRT_tanf (MSVCRT.@)
272 float CDECL
MSVCRT_tanf( float x
)
274 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
278 /*********************************************************************
279 * MSVCRT_tanhf (MSVCRT.@)
281 float CDECL
MSVCRT_tanhf( float x
)
283 if (!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
287 /*********************************************************************
290 float CDECL
MSVCRT_ceilf( float x
)
295 /*********************************************************************
298 float CDECL
MSVCRT_fabsf( float x
)
303 /*********************************************************************
306 float CDECL
MSVCRT_floorf( float x
)
311 /*********************************************************************
314 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
316 return frexpf( x
, exp
);
319 /*********************************************************************
322 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
324 if (!finitef(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
325 return ldexpf(num
, power
);
328 /*********************************************************************
331 double CDECL
MSVCRT_modff( float x
, float *iptr
)
333 return modff( x
, iptr
);
338 /*********************************************************************
339 * MSVCRT_acos (MSVCRT.@)
341 double CDECL
MSVCRT_acos( double x
)
343 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
344 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
345 * asin() uses a similar construction. This is bad because as x gets nearer to
346 * 1 the error in the expression "1 - x^2" can get relatively large due to
347 * cancellation. The sqrt() makes things worse. A safer way to calculate
348 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
349 return atan2(sqrt((1 - x
) * (1 + x
)), x
);
352 /*********************************************************************
353 * MSVCRT_asin (MSVCRT.@)
355 double CDECL
MSVCRT_asin( double x
)
357 if (x
< -1.0 || x
> 1.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
358 return atan2(x
, sqrt((1 - x
) * (1 + x
)));
361 /*********************************************************************
362 * MSVCRT_atan (MSVCRT.@)
364 double CDECL
MSVCRT_atan( double x
)
366 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
370 /*********************************************************************
371 * MSVCRT_atan2 (MSVCRT.@)
373 double CDECL
MSVCRT_atan2( double x
, double y
)
375 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
379 /*********************************************************************
380 * MSVCRT_cos (MSVCRT.@)
382 double CDECL
MSVCRT_cos( double x
)
384 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
388 /*********************************************************************
389 * MSVCRT_cosh (MSVCRT.@)
391 double CDECL
MSVCRT_cosh( double x
)
393 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
397 /*********************************************************************
398 * MSVCRT_exp (MSVCRT.@)
400 double CDECL
MSVCRT_exp( double x
)
402 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
406 /*********************************************************************
407 * MSVCRT_fmod (MSVCRT.@)
409 double CDECL
MSVCRT_fmod( double x
, double y
)
411 if (!isfinite(x
) || !isfinite(y
)) *MSVCRT__errno() = MSVCRT_EDOM
;
415 /*********************************************************************
416 * MSVCRT_log (MSVCRT.@)
418 double CDECL
MSVCRT_log( double x
)
420 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
421 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
425 /*********************************************************************
426 * MSVCRT_log10 (MSVCRT.@)
428 double CDECL
MSVCRT_log10( double x
)
430 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
431 if (x
== 0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
435 /*********************************************************************
436 * MSVCRT_pow (MSVCRT.@)
438 double CDECL
MSVCRT_pow( double x
, double y
)
440 /* FIXME: If x < 0 and y is not integral, set EDOM */
442 if (!isfinite(z
)) *MSVCRT__errno() = MSVCRT_EDOM
;
446 /*********************************************************************
447 * MSVCRT_sin (MSVCRT.@)
449 double CDECL
MSVCRT_sin( double x
)
451 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
455 /*********************************************************************
456 * MSVCRT_sinh (MSVCRT.@)
458 double CDECL
MSVCRT_sinh( double x
)
460 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
464 /*********************************************************************
465 * MSVCRT_sqrt (MSVCRT.@)
467 double CDECL
MSVCRT_sqrt( double x
)
469 if (x
< 0.0 || !isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
473 /*********************************************************************
474 * MSVCRT_tan (MSVCRT.@)
476 double CDECL
MSVCRT_tan( double x
)
478 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
482 /*********************************************************************
483 * MSVCRT_tanh (MSVCRT.@)
485 double CDECL
MSVCRT_tanh( double x
)
487 if (!isfinite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
492 #if defined(__GNUC__) && defined(__i386__)
494 #define FPU_DOUBLE(var) double var; \
495 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
496 #define FPU_DOUBLES(var1,var2) double var1,var2; \
497 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
498 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
500 /*********************************************************************
503 double CDECL
_CIacos(void)
506 return MSVCRT_acos(x
);
509 /*********************************************************************
512 double CDECL
_CIasin(void)
515 return MSVCRT_asin(x
);
518 /*********************************************************************
521 double CDECL
_CIatan(void)
524 return MSVCRT_atan(x
);
527 /*********************************************************************
528 * _CIatan2 (MSVCRT.@)
530 double CDECL
_CIatan2(void)
533 return MSVCRT_atan2(x
,y
);
536 /*********************************************************************
539 double CDECL
_CIcos(void)
542 return MSVCRT_cos(x
);
545 /*********************************************************************
548 double CDECL
_CIcosh(void)
551 return MSVCRT_cosh(x
);
554 /*********************************************************************
557 double CDECL
_CIexp(void)
560 return MSVCRT_exp(x
);
563 /*********************************************************************
566 double CDECL
_CIfmod(void)
569 return MSVCRT_fmod(x
,y
);
572 /*********************************************************************
575 double CDECL
_CIlog(void)
578 return MSVCRT_log(x
);
581 /*********************************************************************
582 * _CIlog10 (MSVCRT.@)
584 double CDECL
_CIlog10(void)
587 return MSVCRT_log10(x
);
590 /*********************************************************************
593 double CDECL
_CIpow(void)
596 return MSVCRT_pow(x
,y
);
599 /*********************************************************************
602 double CDECL
_CIsin(void)
605 return MSVCRT_sin(x
);
608 /*********************************************************************
611 double CDECL
_CIsinh(void)
614 return MSVCRT_sinh(x
);
617 /*********************************************************************
620 double CDECL
_CIsqrt(void)
623 return MSVCRT_sqrt(x
);
626 /*********************************************************************
629 double CDECL
_CItan(void)
632 return MSVCRT_tan(x
);
635 /*********************************************************************
638 double CDECL
_CItanh(void)
641 return MSVCRT_tanh(x
);
644 /*********************************************************************
647 LONGLONG CDECL
MSVCRT__ftol(void)
653 #endif /* defined(__GNUC__) && defined(__i386__) */
655 /*********************************************************************
656 * _fpclass (MSVCRT.@)
658 int CDECL
MSVCRT__fpclass(double num
)
660 #if defined(HAVE_FPCLASS) || defined(fpclass)
661 switch (fpclass( num
))
664 case FP_SNAN
: return MSVCRT__FPCLASS_SNAN
;
667 case FP_QNAN
: return MSVCRT__FPCLASS_QNAN
;
670 case FP_NINF
: return MSVCRT__FPCLASS_NINF
;
673 case FP_PINF
: return MSVCRT__FPCLASS_PINF
;
676 case FP_NDENORM
: return MSVCRT__FPCLASS_ND
;
679 case FP_PDENORM
: return MSVCRT__FPCLASS_PD
;
682 case FP_NZERO
: return MSVCRT__FPCLASS_NZ
;
685 case FP_PZERO
: return MSVCRT__FPCLASS_PZ
;
688 case FP_NNORM
: return MSVCRT__FPCLASS_NN
;
691 case FP_PNORM
: return MSVCRT__FPCLASS_PN
;
693 default: return MSVCRT__FPCLASS_PN
;
695 #elif defined (fpclassify)
696 switch (fpclassify( num
))
698 case FP_NAN
: return MSVCRT__FPCLASS_QNAN
;
699 case FP_INFINITE
: return signbit(num
) ? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
700 case FP_SUBNORMAL
: return signbit(num
) ?MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
701 case FP_ZERO
: return signbit(num
) ? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
703 return signbit(num
) ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
706 return MSVCRT__FPCLASS_QNAN
;
707 return num
== 0.0 ? MSVCRT__FPCLASS_PZ
: (num
< 0 ? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
);
711 /*********************************************************************
714 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
717 return (num
<< shift
) | (num
>> (32-shift
));
720 /*********************************************************************
723 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
726 return (num
<< shift
) | (num
>> (32-shift
));
729 /*********************************************************************
732 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
735 return (num
>> shift
) | (num
<< (32-shift
));
738 /*********************************************************************
741 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
744 return (num
>> shift
) | (num
<< (32-shift
));
747 /*********************************************************************
750 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
753 return (num
<< shift
) | (num
>> (64-shift
));
756 /*********************************************************************
759 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
762 return (num
>> shift
) | (num
<< (64-shift
));
765 /*********************************************************************
768 int CDECL
MSVCRT_abs( int n
)
770 return n
>= 0 ? n
: -n
;
773 /*********************************************************************
776 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
778 return n
>= 0 ? n
: -n
;
781 /*********************************************************************
784 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
786 return n
>= 0 ? n
: -n
;
789 /*********************************************************************
792 __int64 CDECL
_abs64( __int64 n
)
794 return n
>= 0 ? n
: -n
;
797 /*********************************************************************
800 double CDECL
MSVCRT__logb(double num
)
802 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
806 /*********************************************************************
809 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
811 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
812 return ldexp(num
, power
);
815 /*********************************************************************
818 double CDECL
_hypot(double x
, double y
)
820 /* FIXME: errno handling */
821 return hypot( x
, y
);
824 /*********************************************************************
827 float CDECL
MSVCRT__hypotf(float x
, float y
)
829 /* FIXME: errno handling */
830 return hypotf( x
, y
);
833 /*********************************************************************
836 double CDECL
MSVCRT_ceil( double x
)
841 /*********************************************************************
844 double CDECL
MSVCRT_floor( double x
)
849 /*********************************************************************
852 double CDECL
MSVCRT_fabs( double x
)
857 /*********************************************************************
860 double CDECL
MSVCRT_frexp( double x
, int *exp
)
862 return frexp( x
, exp
);
865 /*********************************************************************
868 double CDECL
MSVCRT_modf( double x
, double *iptr
)
870 return modf( x
, iptr
);
873 /*********************************************************************
874 * _matherr (MSVCRT.@)
876 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
879 TRACE("(%p = %d, %s, %g %g %g)\n",e
, e
->type
, e
->name
, e
->arg1
, e
->arg2
,
883 if (MSVCRT_default_matherr_func
)
884 return MSVCRT_default_matherr_func(e
);
885 ERR(":Unhandled math error!\n");
889 /*********************************************************************
890 * __setusermatherr (MSVCRT.@)
892 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
894 MSVCRT_default_matherr_func
= func
;
895 TRACE(":new matherr handler %p\n", func
);
898 /**********************************************************************
899 * _statusfp2 (MSVCRT.@)
901 * Not exported by native msvcrt, added in msvcr80.
903 #if defined(__i386__) || defined(__x86_64__)
904 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
908 unsigned long fpword
;
912 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
914 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
915 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
916 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
917 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
918 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
919 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
923 if (!sse2_sw
) return;
927 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
929 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
930 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
931 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
932 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
933 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
934 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
939 FIXME( "not implemented\n" );
944 /**********************************************************************
945 * _statusfp (MSVCRT.@)
947 unsigned int CDECL
_statusfp(void)
949 #if defined(__i386__) || defined(__x86_64__)
950 unsigned int x86_sw
, sse2_sw
;
952 _statusfp2( &x86_sw
, &sse2_sw
);
953 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
954 return x86_sw
| sse2_sw
;
956 FIXME( "not implemented\n" );
961 /*********************************************************************
962 * _clearfp (MSVCRT.@)
964 unsigned int CDECL
_clearfp(void)
966 unsigned int flags
= 0;
967 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
968 unsigned long fpword
;
970 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
971 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
972 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
973 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
974 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
975 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
976 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
980 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
981 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
982 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
983 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
984 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
985 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
986 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
988 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
991 FIXME( "not implemented\n" );
996 /*********************************************************************
997 * __fpecode (MSVCRT.@)
999 int * CDECL
__fpecode(void)
1001 return &msvcrt_get_thread_data()->fpecode
;
1004 /*********************************************************************
1007 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1009 double z
= ldexp(num
,exp
);
1012 *MSVCRT__errno() = MSVCRT_ERANGE
;
1013 else if (z
== 0 && signbit(z
))
1014 z
= 0.0; /* Convert -0 -> +0 */
1018 /*********************************************************************
1021 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1023 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1026 /*********************************************************************
1027 * _chgsign (MSVCRT.@)
1029 double CDECL
MSVCRT__chgsign(double num
)
1031 /* FIXME: +-infinity,Nan not tested */
1035 /*********************************************************************
1036 * __control87_2 (MSVCRT.@)
1038 * Not exported by native msvcrt, added in msvcr80.
1040 #if defined(__i386__) || defined(__x86_64__)
1041 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1042 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1045 unsigned long fpword
;
1050 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1052 /* Convert into mask constants */
1054 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1055 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1056 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1057 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1058 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1059 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1060 switch (fpword
& 0xc00)
1062 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1063 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1064 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1066 switch (fpword
& 0x300)
1068 case 0x0: flags
|= MSVCRT__PC_24
; break;
1069 case 0x200: flags
|= MSVCRT__PC_53
; break;
1070 case 0x300: flags
|= MSVCRT__PC_64
; break;
1072 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1074 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1077 flags
= (flags
& ~mask
) | (newval
& mask
);
1079 /* Convert (masked) value back to fp word */
1081 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1082 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1083 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1084 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1085 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1086 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1087 switch (flags
& MSVCRT__MCW_RC
)
1089 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1090 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1091 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1093 switch (flags
& MSVCRT__MCW_PC
)
1095 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1096 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1097 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1099 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1101 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1106 if (!sse2_cw
) return 1;
1110 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1112 /* Convert into mask constants */
1114 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1115 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1116 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1117 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1118 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1119 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1120 switch (fpword
& 0x6000)
1122 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1123 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1124 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1126 switch (fpword
& 0x8040)
1128 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1129 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1130 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1133 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1136 flags
= (flags
& ~mask
) | (newval
& mask
);
1138 /* Convert (masked) value back to fp word */
1140 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1141 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1142 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1143 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1144 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1145 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1146 switch (flags
& MSVCRT__MCW_RC
)
1148 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1149 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1150 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1152 switch (flags
& MSVCRT__MCW_DN
)
1154 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1155 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1156 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1158 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1166 FIXME( "not implemented\n" );
1172 /*********************************************************************
1173 * _control87 (MSVCRT.@)
1175 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1177 #if defined(__i386__) || defined(__x86_64__)
1178 unsigned int x86_cw
, sse2_cw
;
1180 __control87_2( newval
, mask
, &x86_cw
, &sse2_cw
);
1182 if ((x86_cw
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) x86_cw
|= MSVCRT__EM_AMBIGUOUS
;
1185 FIXME( "not implemented\n" );
1190 /*********************************************************************
1191 * _controlfp (MSVCRT.@)
1193 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
1195 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
1198 /*********************************************************************
1199 * _set_controlfp (MSVCRT.@)
1201 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
1203 _controlfp( newval
, mask
);
1206 /*********************************************************************
1207 * _controlfp_s (MSVCRT.@)
1209 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
1211 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
1212 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
1215 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
1217 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
1218 return MSVCRT_EINVAL
;
1220 val
= _controlfp( newval
, mask
);
1221 if (cur
) *cur
= val
;
1225 /*********************************************************************
1226 * _copysign (MSVCRT.@)
1228 double CDECL
MSVCRT__copysign(double num
, double sign
)
1230 /* FIXME: Behaviour for Nan/Inf? */
1232 return num
< 0.0 ? num
: -num
;
1233 return num
< 0.0 ? -num
: num
;
1236 /*********************************************************************
1237 * _finite (MSVCRT.@)
1239 int CDECL
MSVCRT__finite(double num
)
1241 return isfinite(num
) != 0; /* See comment for _isnan() */
1244 /*********************************************************************
1245 * _fpreset (MSVCRT.@)
1247 void CDECL
_fpreset(void)
1249 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1250 const unsigned int x86_cw
= 0x27f;
1251 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
1254 const unsigned long sse2_cw
= 0x1f80;
1255 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
1258 FIXME( "not implemented\n" );
1262 /*********************************************************************
1265 INT CDECL
MSVCRT__isnan(double num
)
1267 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1268 * Do the same, as the result may be used in calculations
1270 return isnan(num
) != 0;
1273 /*********************************************************************
1276 double CDECL
MSVCRT__j0(double num
)
1278 /* FIXME: errno handling */
1282 /*********************************************************************
1285 double CDECL
MSVCRT__j1(double num
)
1287 /* FIXME: errno handling */
1291 /*********************************************************************
1294 double CDECL
MSVCRT__jn(int n
, double num
)
1296 /* FIXME: errno handling */
1300 /*********************************************************************
1303 double CDECL
MSVCRT__y0(double num
)
1306 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1308 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1310 *MSVCRT__errno() = MSVCRT_EDOM
;
1316 /*********************************************************************
1319 double CDECL
MSVCRT__y1(double num
)
1322 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1324 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1326 *MSVCRT__errno() = MSVCRT_EDOM
;
1332 /*********************************************************************
1335 double CDECL
MSVCRT__yn(int order
, double num
)
1338 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1339 retval
= yn(order
,num
);
1340 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
1342 *MSVCRT__errno() = MSVCRT_EDOM
;
1348 /*********************************************************************
1349 * _nextafter (MSVCRT.@)
1351 double CDECL
MSVCRT__nextafter(double num
, double next
)
1354 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
1355 retval
= nextafter(num
,next
);
1359 /*********************************************************************
1362 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
1365 thread_data_t
*data
= msvcrt_get_thread_data();
1366 /* FIXME: check better for overflow (native supports over 300 chars) */
1367 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
1368 * 4 for exponent and one for
1369 * terminating '\0' */
1370 if (!data
->efcvt_buffer
)
1371 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1378 /* handle cases with zero ndigits or less */
1380 if( prec
< 1) prec
= 2;
1381 len
= snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
1382 /* take the decimal "point away */
1384 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
1385 /* take the exponential "e" out */
1386 data
->efcvt_buffer
[ prec
] = '\0';
1387 /* read the exponent */
1388 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
1390 /* adjust for some border cases */
1391 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
1393 /* handle cases with zero ndigits or less */
1395 if( data
->efcvt_buffer
[ 0] >= '5')
1397 data
->efcvt_buffer
[ 0] = '\0';
1399 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
1400 return data
->efcvt_buffer
;
1403 /*********************************************************************
1404 * _ecvt_s (MSVCRT.@)
1406 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
1410 const char infret
[] = "1#INF";
1412 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
1413 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
1414 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
1415 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1416 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
1418 /* special case - inf */
1419 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
1421 memset(buffer
, '0', ndigits
);
1422 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
1423 buffer
[ndigits
] = '\0';
1425 if(number
== -HUGE_VAL
)
1431 /* handle cases with zero ndigits or less */
1433 if( prec
< 1) prec
= 2;
1434 result
= MSVCRT_malloc(prec
+ 7);
1441 len
= snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
1442 /* take the decimal "point away */
1444 memmove( result
+ 1, result
+ 2, len
- 1 );
1445 /* take the exponential "e" out */
1446 result
[ prec
] = '\0';
1447 /* read the exponent */
1448 sscanf( result
+ prec
+ 1, "%d", decpt
);
1450 /* adjust for some border cases */
1451 if( result
[0] == '0')/* value is zero */
1453 /* handle cases with zero ndigits or less */
1455 if( result
[ 0] >= '5')
1459 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
1460 MSVCRT_free( result
);
1464 /***********************************************************************
1467 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
1469 thread_data_t
*data
= msvcrt_get_thread_data();
1470 int stop
, dec1
, dec2
;
1471 char *ptr1
, *ptr2
, *first
;
1472 char buf
[80]; /* ought to be enough */
1474 if (!data
->efcvt_buffer
)
1475 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
1483 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1485 ptr2
= data
->efcvt_buffer
;
1490 /* For numbers below the requested resolution, work out where
1491 the decimal point will be rather than finding it in the string */
1492 if (number
< 1.0 && number
> 0.0) {
1493 dec2
= log10(number
+ 1e-10);
1494 if (-dec2
<= ndigits
) dec2
= 0;
1497 /* If requested digits is zero or less, we will need to truncate
1498 * the returned string */
1500 stop
= strlen(buf
) + ndigits
;
1505 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1506 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1507 if (!first
) first
= ptr2
;
1508 if ((ptr1
- buf
) < stop
) {
1519 while (*ptr1
== '0') { /* Process leading zeroes */
1524 while (*ptr1
!= '\0') {
1525 if (!first
) first
= ptr2
;
1532 /* We never found a non-zero digit, then our number is either
1533 * smaller than the requested precision, or 0.0 */
1538 first
= data
->efcvt_buffer
;
1543 *decpt
= dec2
? dec2
: dec1
;
1547 /***********************************************************************
1548 * _fcvt_s (MSVCRT.@)
1550 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
1552 int stop
, dec1
, dec2
;
1553 char *ptr1
, *ptr2
, *first
;
1554 char buf
[80]; /* ought to be enough */
1556 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
1558 *MSVCRT__errno() = MSVCRT_EINVAL
;
1559 return MSVCRT_EINVAL
;
1568 snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
1575 /* For numbers below the requested resolution, work out where
1576 the decimal point will be rather than finding it in the string */
1577 if (number
< 1.0 && number
> 0.0) {
1578 dec2
= log10(number
+ 1e-10);
1579 if (-dec2
<= ndigits
) dec2
= 0;
1582 /* If requested digits is zero or less, we will need to truncate
1583 * the returned string */
1585 stop
= strlen(buf
) + ndigits
;
1590 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
1591 while (*ptr1
!= '\0' && *ptr1
!= '.') {
1592 if (!first
) first
= ptr2
;
1593 if ((ptr1
- buf
) < stop
) {
1607 while (*ptr1
== '0') { /* Process leading zeroes */
1608 if (number
== 0.0 && size
> 1) {
1616 while (*ptr1
!= '\0') {
1617 if (!first
) first
= ptr2
;
1627 /* We never found a non-zero digit, then our number is either
1628 * smaller than the requested precision, or 0.0 */
1629 if (!first
&& (number
<= 0.0))
1632 *decpt
= dec2
? dec2
: dec1
;
1636 /***********************************************************************
1639 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
1642 *MSVCRT__errno() = MSVCRT_EINVAL
;
1647 *MSVCRT__errno() = MSVCRT_ERANGE
;
1651 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
1655 /***********************************************************************
1656 * _gcvt_s (MSVCRT.@)
1658 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
1663 *MSVCRT__errno() = MSVCRT_EINVAL
;
1664 return MSVCRT_EINVAL
;
1667 if( digits
<0 || digits
>=size
) {
1671 *MSVCRT__errno() = MSVCRT_ERANGE
;
1672 return MSVCRT_ERANGE
;
1675 len
= MSVCRT__scprintf("%.*g", digits
, number
);
1678 *MSVCRT__errno() = MSVCRT_ERANGE
;
1679 return MSVCRT_ERANGE
;
1682 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
1686 #include <stdlib.h> /* div_t, ldiv_t */
1688 /*********************************************************************
1691 * [i386] Windows binary compatible - returns the struct in eax/edx.
1694 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
1696 div_t dt
= div(num
,denom
);
1697 return ((unsigned __int64
)dt
.rem
<< 32) | (unsigned int)dt
.quot
;
1700 /*********************************************************************
1703 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1705 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
1707 div_t dt
= div(num
,denom
);
1715 #endif /* ifdef __i386__ */
1718 /*********************************************************************
1721 * [i386] Windows binary compatible - returns the struct in eax/edx.
1724 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1726 ldiv_t ldt
= ldiv(num
,denom
);
1727 return ((unsigned __int64
)ldt
.rem
<< 32) | (MSVCRT_ulong
)ldt
.quot
;
1730 /*********************************************************************
1733 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1735 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
1737 ldiv_t result
= ldiv(num
,denom
);
1740 ret
.quot
= result
.quot
;
1741 ret
.rem
= result
.rem
;
1745 #endif /* ifdef __i386__ */
1749 /*********************************************************************
1750 * _adjust_fdiv (MSVCRT.@)
1751 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1753 int MSVCRT__adjust_fdiv
= 0;
1755 /***********************************************************************
1756 * _adj_fdiv_m16i (MSVCRT.@)
1759 * I _think_ this function is intended to work around the Pentium
1762 void __stdcall
_adj_fdiv_m16i( short arg
)
1764 TRACE("(): stub\n");
1767 /***********************************************************************
1768 * _adj_fdiv_m32 (MSVCRT.@)
1771 * I _think_ this function is intended to work around the Pentium
1774 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
1776 TRACE("(): stub\n");
1779 /***********************************************************************
1780 * _adj_fdiv_m32i (MSVCRT.@)
1783 * I _think_ this function is intended to work around the Pentium
1786 void __stdcall
_adj_fdiv_m32i( int arg
)
1788 TRACE("(): stub\n");
1791 /***********************************************************************
1792 * _adj_fdiv_m64 (MSVCRT.@)
1795 * I _think_ this function is intended to work around the Pentium
1798 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
1800 TRACE("(): stub\n");
1803 /***********************************************************************
1804 * _adj_fdiv_r (MSVCRT.@)
1806 * This function is likely to have the wrong number of arguments.
1809 * I _think_ this function is intended to work around the Pentium
1812 void _adj_fdiv_r(void)
1814 TRACE("(): stub\n");
1817 /***********************************************************************
1818 * _adj_fdivr_m16i (MSVCRT.@)
1821 * I _think_ this function is intended to work around the Pentium
1824 void __stdcall
_adj_fdivr_m16i( short arg
)
1826 TRACE("(): stub\n");
1829 /***********************************************************************
1830 * _adj_fdivr_m32 (MSVCRT.@)
1833 * I _think_ this function is intended to work around the Pentium
1836 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
1838 TRACE("(): stub\n");
1841 /***********************************************************************
1842 * _adj_fdivr_m32i (MSVCRT.@)
1845 * I _think_ this function is intended to work around the Pentium
1848 void __stdcall
_adj_fdivr_m32i( int arg
)
1850 TRACE("(): stub\n");
1853 /***********************************************************************
1854 * _adj_fdivr_m64 (MSVCRT.@)
1857 * I _think_ this function is intended to work around the Pentium
1860 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
1862 TRACE("(): stub\n");
1865 /***********************************************************************
1866 * _adj_fpatan (MSVCRT.@)
1868 * This function is likely to have the wrong number of arguments.
1871 * I _think_ this function is intended to work around the Pentium
1874 void _adj_fpatan(void)
1876 TRACE("(): stub\n");
1879 /***********************************************************************
1880 * _adj_fprem (MSVCRT.@)
1882 * This function is likely to have the wrong number of arguments.
1885 * I _think_ this function is intended to work around the Pentium
1888 void _adj_fprem(void)
1890 TRACE("(): stub\n");
1893 /***********************************************************************
1894 * _adj_fprem1 (MSVCRT.@)
1896 * This function is likely to have the wrong number of arguments.
1899 * I _think_ this function is intended to work around the Pentium
1902 void _adj_fprem1(void)
1904 TRACE("(): stub\n");
1907 /***********************************************************************
1908 * _adj_fptan (MSVCRT.@)
1910 * This function is likely to have the wrong number of arguments.
1913 * I _think_ this function is intended to work around the Pentium
1916 void _adj_fptan(void)
1918 TRACE("(): stub\n");
1921 /***********************************************************************
1922 * _safe_fdiv (MSVCRT.@)
1924 * This function is likely to have the wrong number of arguments.
1927 * I _think_ this function is intended to work around the Pentium
1930 void _safe_fdiv(void)
1932 TRACE("(): stub\n");
1935 /***********************************************************************
1936 * _safe_fdivr (MSVCRT.@)
1938 * This function is likely to have the wrong number of arguments.
1941 * I _think_ this function is intended to work around the Pentium
1944 void _safe_fdivr(void)
1946 TRACE("(): stub\n");
1949 /***********************************************************************
1950 * _safe_fprem (MSVCRT.@)
1952 * This function is likely to have the wrong number of arguments.
1955 * I _think_ this function is intended to work around the Pentium
1958 void _safe_fprem(void)
1960 TRACE("(): stub\n");
1963 /***********************************************************************
1964 * _safe_fprem1 (MSVCRT.@)
1967 * This function is likely to have the wrong number of arguments.
1970 * I _think_ this function is intended to work around the Pentium
1973 void _safe_fprem1(void)
1975 TRACE("(): stub\n");
1978 /***********************************************************************
1979 * __libm_sse2_acos (MSVCRT.@)
1981 void __cdecl
__libm_sse2_acos(void)
1984 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
1986 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
1989 /***********************************************************************
1990 * __libm_sse2_acosf (MSVCRT.@)
1992 void __cdecl
__libm_sse2_acosf(void)
1995 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
1997 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2000 /***********************************************************************
2001 * __libm_sse2_asin (MSVCRT.@)
2003 void __cdecl
__libm_sse2_asin(void)
2006 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2008 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2011 /***********************************************************************
2012 * __libm_sse2_asinf (MSVCRT.@)
2014 void __cdecl
__libm_sse2_asinf(void)
2017 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2019 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2022 /***********************************************************************
2023 * __libm_sse2_atan (MSVCRT.@)
2025 void __cdecl
__libm_sse2_atan(void)
2028 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2030 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2033 /***********************************************************************
2034 * __libm_sse2_atan2 (MSVCRT.@)
2036 void __cdecl
__libm_sse2_atan2(void)
2039 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2040 d1
= atan2( d1
, d2
);
2041 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2044 /***********************************************************************
2045 * __libm_sse2_atanf (MSVCRT.@)
2047 void __cdecl
__libm_sse2_atanf(void)
2050 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2052 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2055 /***********************************************************************
2056 * __libm_sse2_cos (MSVCRT.@)
2058 void __cdecl
__libm_sse2_cos(void)
2061 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2063 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2066 /***********************************************************************
2067 * __libm_sse2_cosf (MSVCRT.@)
2069 void __cdecl
__libm_sse2_cosf(void)
2072 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2074 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2077 /***********************************************************************
2078 * __libm_sse2_exp (MSVCRT.@)
2080 void __cdecl
__libm_sse2_exp(void)
2083 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2085 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2088 /***********************************************************************
2089 * __libm_sse2_expf (MSVCRT.@)
2091 void __cdecl
__libm_sse2_expf(void)
2094 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2096 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2099 /***********************************************************************
2100 * __libm_sse2_log (MSVCRT.@)
2102 void __cdecl
__libm_sse2_log(void)
2105 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2107 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2110 /***********************************************************************
2111 * __libm_sse2_log10 (MSVCRT.@)
2113 void __cdecl
__libm_sse2_log10(void)
2116 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2118 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2121 /***********************************************************************
2122 * __libm_sse2_log10f (MSVCRT.@)
2124 void __cdecl
__libm_sse2_log10f(void)
2127 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2129 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2132 /***********************************************************************
2133 * __libm_sse2_logf (MSVCRT.@)
2135 void __cdecl
__libm_sse2_logf(void)
2138 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2140 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2143 /***********************************************************************
2144 * __libm_sse2_pow (MSVCRT.@)
2146 void __cdecl
__libm_sse2_pow(void)
2149 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
2151 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
2154 /***********************************************************************
2155 * __libm_sse2_powf (MSVCRT.@)
2157 void __cdecl
__libm_sse2_powf(void)
2160 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
2161 f1
= powf( f1
, f2
);
2162 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
2165 /***********************************************************************
2166 * __libm_sse2_sin (MSVCRT.@)
2168 void __cdecl
__libm_sse2_sin(void)
2171 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2173 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2176 /***********************************************************************
2177 * __libm_sse2_sinf (MSVCRT.@)
2179 void __cdecl
__libm_sse2_sinf(void)
2182 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2184 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2187 /***********************************************************************
2188 * __libm_sse2_tan (MSVCRT.@)
2190 void __cdecl
__libm_sse2_tan(void)
2193 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2195 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2198 /***********************************************************************
2199 * __libm_sse2_tanf (MSVCRT.@)
2201 void __cdecl
__libm_sse2_tanf(void)
2204 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
2206 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
2209 /***********************************************************************
2210 * __libm_sse2_sqrt_precise (MSVCR110.@)
2212 void __cdecl
__libm_sse2_sqrt_precise(void)
2215 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
2217 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
2220 #endif /* __i386__ */
2222 /*********************************************************************
2225 double CDECL
MSVCR120_cbrt(double x
)
2230 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
2234 /*********************************************************************
2235 * cbrtf (MSVCR120.@)
2237 float CDECL
MSVCR120_cbrtf(float x
)
2242 return MSVCR120_cbrt(x
);
2246 /*********************************************************************
2247 * cbrtl (MSVCR120.@)
2249 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
2251 return MSVCR120_cbrt(x
);
2254 /*********************************************************************
2257 double CDECL
MSVCR120_exp2(double x
)
2266 /*********************************************************************
2267 * exp2f (MSVCR120.@)
2269 float CDECL
MSVCR120_exp2f(float x
)
2274 return MSVCR120_exp2(x
);
2278 /*********************************************************************
2279 * exp2l (MSVCR120.@)
2281 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
2283 return MSVCR120_exp2(x
);
2286 /*********************************************************************
2289 double CDECL
MSVCR120_log2(double x
)
2294 return log(x
) / log(2);
2298 /*********************************************************************
2299 * log2f (MSVCR120.@)
2301 float CDECL
MSVCR120_log2f(float x
)
2306 return MSVCR120_log2(x
);
2310 /*********************************************************************
2311 * log2l (MSVCR120.@)
2313 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
2315 return MSVCR120_log2(x
);
2318 /*********************************************************************
2321 double CDECL
MSVCR120_rint(double x
)
2326 return x
>= 0 ? floor(x
+ 0.5) : ceil(x
- 0.5);
2330 /*********************************************************************
2331 * rintf (MSVCR120.@)
2333 float CDECL
MSVCR120_rintf(float x
)
2338 return MSVCR120_rint(x
);
2342 /*********************************************************************
2343 * rintl (MSVCR120.@)
2345 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
2347 return MSVCR120_rint(x
);
2350 /*********************************************************************
2351 * lrint (MSVCR120.@)
2353 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
2358 return MSVCR120_rint(x
);
2362 /*********************************************************************
2363 * lrintf (MSVCR120.@)
2365 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
2370 return MSVCR120_lrint(x
);
2374 /*********************************************************************
2375 * lrintl (MSVCR120.@)
2377 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
2379 return MSVCR120_lrint(x
);
2382 /*********************************************************************
2383 * llrint (MSVCR120.@)
2385 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
2390 return MSVCR120_rint(x
);
2394 /*********************************************************************
2395 * llrintf (MSVCR120.@)
2397 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
2402 return MSVCR120_llrint(x
);
2406 /*********************************************************************
2407 * rintl (MSVCR120.@)
2409 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
2411 return MSVCR120_llrint(x
);
2414 /*********************************************************************
2415 * round (MSVCR120.@)
2417 double CDECL
MSVCR120_round(double x
)
2422 return MSVCR120_rint(x
);
2426 /*********************************************************************
2427 * roundf (MSVCR120.@)
2429 float CDECL
MSVCR120_roundf(float x
)
2434 return MSVCR120_round(x
);
2438 /*********************************************************************
2439 * roundl (MSVCR120.@)
2441 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
2443 return MSVCR120_round(x
);
2446 /*********************************************************************
2447 * lround (MSVCR120.@)
2449 MSVCRT_long CDECL
MSVCR120_lround(double x
)
2454 return MSVCR120_round(x
);
2458 /*********************************************************************
2459 * lroundf (MSVCR120.@)
2461 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
2466 return MSVCR120_lround(x
);
2470 /*********************************************************************
2471 * lroundl (MSVCR120.@)
2473 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
2475 return MSVCR120_lround(x
);
2478 /*********************************************************************
2479 * llround (MSVCR120.@)
2481 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
2486 return MSVCR120_round(x
);
2490 /*********************************************************************
2491 * llroundf (MSVCR120.@)
2493 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
2495 #ifdef HAVE_LLROUNDF
2498 return MSVCR120_llround(x
);
2502 /*********************************************************************
2503 * roundl (MSVCR120.@)
2505 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
2507 return MSVCR120_llround(x
);
2510 /*********************************************************************
2511 * trunc (MSVCR120.@)
2513 double CDECL
MSVCR120_trunc(double x
)
2518 return (x
> 0) ? floor(x
) : ceil(x
);
2522 /*********************************************************************
2523 * truncf (MSVCR120.@)
2525 float CDECL
MSVCR120_truncf(float x
)
2530 return MSVCR120_trunc(x
);
2534 /*********************************************************************
2535 * truncl (MSVCR120.@)
2537 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
2539 return MSVCR120_trunc(x
);
2542 /*********************************************************************
2543 * _dclass (MSVCR120.@)
2545 short CDECL
MSVCR120__dclass(double x
)
2547 switch (MSVCRT__fpclass(x
)) {
2548 case MSVCRT__FPCLASS_QNAN
:
2549 case MSVCRT__FPCLASS_SNAN
:
2550 return MSVCRT_FP_NAN
;
2551 case MSVCRT__FPCLASS_NINF
:
2552 case MSVCRT__FPCLASS_PINF
:
2553 return MSVCRT_FP_INFINITE
;
2554 case MSVCRT__FPCLASS_ND
:
2555 case MSVCRT__FPCLASS_PD
:
2556 return MSVCRT_FP_SUBNORMAL
;
2557 case MSVCRT__FPCLASS_NN
:
2558 case MSVCRT__FPCLASS_PN
:
2560 return MSVCRT_FP_NORMAL
;
2561 case MSVCRT__FPCLASS_NZ
:
2562 case MSVCRT__FPCLASS_PZ
:
2563 return MSVCRT_FP_ZERO
;
2567 /*********************************************************************
2568 * _fdclass (MSVCR120.@)
2570 short CDECL
MSVCR120__fdclass(float x
)
2572 return MSVCR120__dclass(x
);
2575 /*********************************************************************
2576 * _ldclass (MSVCR120.@)
2578 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
2580 return MSVCR120__dclass(x
);
2583 /*********************************************************************
2584 * _dtest (MSVCR120.@)
2586 short CDECL
MSVCR120__dtest(double *x
)
2588 return MSVCR120__dclass(*x
);
2591 /*********************************************************************
2592 * _fdtest (MSVCR120.@)
2594 short CDECL
MSVCR120__fdtest(float *x
)
2596 return MSVCR120__dclass(*x
);
2599 /*********************************************************************
2600 * _ldtest (MSVCR120.@)
2602 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
2604 return MSVCR120__dclass(*x
);