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 * For functions copied from musl (http://www.musl-libc.org/):
22 * ====================================================
23 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
25 * Developed at SunPro, a Sun Microsystems, Inc. business.
26 * Permission to use, copy, modify, and distribute this
27 * software is freely granted, provided that this notice
29 * ====================================================
33 #include "wine/port.h"
36 #define __USE_ISOC9X 1
37 #define __USE_ISOC99 1
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
51 #define finite(x) isfinite(x)
54 #define finitef(x) isfinite(x)
57 /* FIXME: Does not work with -NAN and -0. */
59 #define signbit(x) ((x) < 0)
62 #define _DOMAIN 1 /* domain error in argument */
63 #define _SING 2 /* singularity */
64 #define _OVERFLOW 3 /* range overflow */
65 #define _UNDERFLOW 4 /* range underflow */
67 typedef int (CDECL
*MSVCRT_matherr_func
)(struct MSVCRT__exception
*);
68 typedef double LDOUBLE
; /* long double is just a double */
70 static MSVCRT_matherr_func MSVCRT_default_matherr_func
= NULL
;
72 static BOOL sse2_supported
;
73 static BOOL sse2_enabled
;
75 void msvcrt_init_math(void)
77 sse2_supported
= sse2_enabled
= IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE
);
80 /* Copied from musl: src/internal/libm.h */
81 static inline float fp_barrierf(float x
)
87 /*********************************************************************
90 int CDECL
MSVCRT__matherr(struct MSVCRT__exception
*e
)
96 static double math_error(int type
, const char *name
, double arg1
, double arg2
, double retval
)
98 struct MSVCRT__exception exception
= {type
, (char *)name
, arg1
, arg2
, retval
};
100 TRACE("(%d, %s, %g, %g, %g)\n", type
, debugstr_a(name
), arg1
, arg2
, retval
);
102 if (MSVCRT_default_matherr_func
&& MSVCRT_default_matherr_func(&exception
))
103 return exception
.retval
;
108 *MSVCRT__errno() = MSVCRT_EDOM
;
112 *MSVCRT__errno() = MSVCRT_ERANGE
;
115 /* don't set errno */
118 ERR("Unhandled math error!\n");
121 return exception
.retval
;
124 /*********************************************************************
125 * __setusermatherr (MSVCRT.@)
127 void CDECL
MSVCRT___setusermatherr(MSVCRT_matherr_func func
)
129 MSVCRT_default_matherr_func
= func
;
130 TRACE("new matherr handler %p\n", func
);
133 /*********************************************************************
134 * _set_SSE2_enable (MSVCRT.@)
136 int CDECL
MSVCRT__set_SSE2_enable(int flag
)
138 sse2_enabled
= flag
&& sse2_supported
;
144 /*********************************************************************
145 * _get_FMA3_enable (UCRTBASE.@)
147 int CDECL
MSVCRT__get_FMA3_enable(void)
155 /*********************************************************************
156 * _set_FMA3_enable (MSVCR120.@)
158 int CDECL
MSVCRT__set_FMA3_enable(int flag
)
160 FIXME("(%x) stub\n", flag
);
166 #if !defined(__i386__) || _MSVCR_VER>=120
168 /*********************************************************************
169 * _chgsignf (MSVCRT.@)
171 float CDECL
MSVCRT__chgsignf( float num
)
173 /* FIXME: +-infinity,Nan not tested */
177 /*********************************************************************
178 * _copysignf (MSVCRT.@)
180 float CDECL
MSVCRT__copysignf( float num
, float sign
)
183 return signbit(num
) ? num
: -num
;
184 return signbit(num
) ? -num
: num
;
187 /*********************************************************************
188 * _nextafterf (MSVCRT.@)
190 float CDECL
MSVCRT__nextafterf( float num
, float next
)
192 if (!finitef(num
) || !finitef(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
193 return nextafterf( num
, next
);
196 /*********************************************************************
199 float CDECL
MSVCRT__logbf( float num
)
201 float ret
= logbf(num
);
202 if (isnan(num
)) return math_error(_DOMAIN
, "_logbf", num
, 0, ret
);
203 if (!num
) return math_error(_SING
, "_logbf", num
, 0, ret
);
211 /*********************************************************************
212 * _fpclassf (MSVCRT.@)
214 int CDECL
MSVCRT__fpclassf( float num
)
216 union { float f
; UINT32 i
; } u
= { num
};
217 int e
= u
.i
>> 23 & 0xff;
223 if (u
.i
<< 1) return s
? MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
224 return s
? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
226 if (u
.i
<< 9) return ((u
.i
>> 22) & 1) ? MSVCRT__FPCLASS_QNAN
: MSVCRT__FPCLASS_SNAN
;
227 return s
? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
229 return s
? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
233 /*********************************************************************
234 * _finitef (MSVCRT.@)
236 int CDECL
MSVCRT__finitef( float num
)
238 union { float f
; UINT32 i
; } u
= { num
};
239 return (u
.i
& 0x7fffffff) < 0x7f800000;
242 /*********************************************************************
245 INT CDECL
MSVCRT__isnanf( float num
)
247 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
248 * Do the same, as the result may be used in calculations
250 return isnan(num
) != 0;
253 /*********************************************************************
254 * MSVCRT_acosf (MSVCRT.@)
256 * Copied from musl: src/math/acosf.c
258 static float acosf_R(float z
)
260 static const float pS0
= 1.6666586697e-01,
261 pS1
= -4.2743422091e-02,
262 pS2
= -8.6563630030e-03,
263 qS1
= -7.0662963390e-01;
266 p
= z
* (pS0
+ z
* (pS1
+ z
* pS2
));
271 float CDECL
MSVCRT_acosf( float x
)
273 static const float pio2_hi
= 1.5707962513e+00,
274 pio2_lo
= 7.5497894159e-08;
276 float z
, w
, s
, c
, df
;
279 hx
= *(unsigned int*)&x
;
280 ix
= hx
& 0x7fffffff;
281 /* |x| >= 1 or nan */
282 if (ix
>= 0x3f800000) {
283 if (ix
== 0x3f800000) {
285 return 2 * pio2_lo
+ 2 * pio2_hi
+ 7.5231638453e-37;
288 if (MSVCRT__isnanf(x
)) return x
;
289 return math_error(_DOMAIN
, "acosf", x
, 0, 0 / (x
- x
));
292 if (ix
< 0x3f000000) {
293 if (ix
<= 0x32800000) /* |x| < 2**-26 */
294 return pio2_lo
+ pio2_hi
+ 7.5231638453e-37;
295 return pio2_hi
- (x
- (pio2_lo
- x
* acosf_R(x
* x
)));
301 w
= acosf_R(z
) * s
- pio2_lo
;
302 return 2 * (pio2_hi
- (s
+ w
));
307 hx
= *(unsigned int*)&s
& 0xfffff000;
309 c
= (z
- df
* df
) / (s
+ df
);
310 w
= acosf_R(z
) * s
+ c
;
314 /*********************************************************************
315 * MSVCRT_asinf (MSVCRT.@)
317 * Copied from musl: src/math/asinf.c
319 static float asinf_R(float z
)
321 /* coefficients for R(x^2) */
322 static const float pS0
= 1.6666586697e-01,
323 pS1
= -4.2743422091e-02,
324 pS2
= -8.6563630030e-03,
325 qS1
= -7.0662963390e-01;
328 p
= z
* (pS0
+ z
* (pS1
+ z
* pS2
));
333 float CDECL
MSVCRT_asinf( float x
)
335 static const double pio2
= 1.570796326794896558e+00;
341 hx
= *(unsigned int*)&x
;
342 ix
= hx
& 0x7fffffff;
343 if (ix
>= 0x3f800000) { /* |x| >= 1 */
344 if (ix
== 0x3f800000) /* |x| == 1 */
345 return x
* pio2
+ 7.5231638453e-37; /* asin(+-1) = +-pi/2 with inexact */
346 if (MSVCRT__isnanf(x
)) return x
;
347 return math_error(_DOMAIN
, "asinf", x
, 0, 0 / (x
- x
));
349 if (ix
< 0x3f000000) { /* |x| < 0.5 */
350 /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
351 if (ix
< 0x39800000 && ix
>= 0x00800000)
353 return x
+ x
* asinf_R(x
* x
);
356 z
= (1 - fabsf(x
)) * 0.5f
;
358 x
= pio2
- 2 * (s
+ s
* asinf_R(z
));
364 /*********************************************************************
365 * MSVCRT_atanf (MSVCRT.@)
367 * Copied from musl: src/math/atanf.c
369 float CDECL
MSVCRT_atanf( float x
)
371 static const float atanhi
[] = {
377 static const float atanlo
[] = {
383 static const float aT
[] = {
392 unsigned int ix
, sign
;
396 if (MSVCRT__isnanf(x
)) return math_error(_DOMAIN
, "atanf", x
, 0, x
);
399 ix
= *(unsigned int*)&x
;
402 if (ix
>= 0x4c800000) { /* if |x| >= 2**26 */
403 if (MSVCRT__isnanf(x
))
405 z
= atanhi
[3] + 7.5231638453e-37;
406 return sign
? -z
: z
;
408 if (ix
< 0x3ee00000) { /* |x| < 0.4375 */
409 if (ix
< 0x39800000) { /* |x| < 2**-12 */
411 /* raise underflow for subnormal x */
418 if (ix
< 0x3f980000) { /* |x| < 1.1875 */
419 if (ix
< 0x3f300000) { /* 7/16 <= |x| < 11/16 */
421 x
= (2.0f
* x
- 1.0f
) / (2.0f
+ x
);
422 } else { /* 11/16 <= |x| < 19/16 */
424 x
= (x
- 1.0f
) / (x
+ 1.0f
);
427 if (ix
< 0x401c0000) { /* |x| < 2.4375 */
429 x
= (x
- 1.5f
) / (1.0f
+ 1.5f
* x
);
430 } else { /* 2.4375 <= |x| < 2**26 */
436 /* end of argument reduction */
439 /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
440 s1
= z
* (aT
[0] + w
* (aT
[2] + w
* aT
[4]));
441 s2
= w
* (aT
[1] + w
* aT
[3]);
443 return x
- x
* (s1
+ s2
);
444 z
= atanhi
[id
] - ((x
* (s1
+ s2
) - atanlo
[id
]) - x
);
445 return sign
? -z
: z
;
448 /*********************************************************************
449 * MSVCRT_atan2f (MSVCRT.@)
451 * Copied from musl: src/math/atan2f.c
453 float CDECL
MSVCRT_atan2f( float y
, float x
)
455 static const float pi
= 3.1415927410e+00,
456 pi_lo
= -8.7422776573e-08;
459 unsigned int m
, ix
, iy
;
461 if (MSVCRT__isnanf(x
) || MSVCRT__isnanf(y
))
463 ix
= *(unsigned int*)&x
;
464 iy
= *(unsigned int*)&y
;
465 if (ix
== 0x3f800000) /* x=1.0 */
467 m
= ((iy
>> 31) & 1) | ((ix
>> 30) & 2); /* 2*sign(x)+sign(y) */
475 case 1: return y
; /* atan(+-0,+anything)=+-0 */
476 case 2: return pi
; /* atan(+0,-anything) = pi */
477 case 3: return -pi
; /* atan(-0,-anything) =-pi */
482 return m
& 1 ? -pi
/ 2 : pi
/ 2;
484 if (ix
== 0x7f800000) {
485 if (iy
== 0x7f800000) {
487 case 0: return pi
/ 4; /* atan(+INF,+INF) */
488 case 1: return -pi
/ 4; /* atan(-INF,+INF) */
489 case 2: return 3 * pi
/ 4; /*atan(+INF,-INF)*/
490 case 3: return -3 * pi
/ 4; /*atan(-INF,-INF)*/
494 case 0: return 0.0f
; /* atan(+...,+INF) */
495 case 1: return -0.0f
; /* atan(-...,+INF) */
496 case 2: return pi
; /* atan(+...,-INF) */
497 case 3: return -pi
; /* atan(-...,-INF) */
502 if (ix
+ (26 << 23) < iy
|| iy
== 0x7f800000)
503 return m
& 1 ? -pi
/ 2 : pi
/ 2;
505 /* z = atan(|y/x|) with correct underflow */
506 if ((m
& 2) && iy
+ (26 << 23) < ix
) /*|y/x| < 0x1p-26, x < 0 */
509 z
= atanf(fabsf(y
/ x
));
511 case 0: return z
; /* atan(+,+) */
512 case 1: return -z
; /* atan(-,+) */
513 case 2: return pi
- (z
- pi_lo
); /* atan(+,-) */
514 default: /* case 3 */
515 return (z
- pi_lo
) - pi
; /* atan(-,-) */
519 /*********************************************************************
520 * MSVCRT_cosf (MSVCRT.@)
522 float CDECL
MSVCRT_cosf( float x
)
525 if (!finitef(x
)) return math_error(_DOMAIN
, "cosf", x
, 0, ret
);
529 /*********************************************************************
530 * MSVCRT_coshf (MSVCRT.@)
532 float CDECL
MSVCRT_coshf( float x
)
534 float ret
= coshf(x
);
535 if (isnan(x
)) return math_error(_DOMAIN
, "coshf", x
, 0, ret
);
539 /*********************************************************************
540 * MSVCRT_expf (MSVCRT.@)
542 float CDECL
MSVCRT_expf( float x
)
545 if (isnan(x
)) return math_error(_DOMAIN
, "expf", x
, 0, ret
);
546 if (finitef(x
) && !ret
) return math_error(_UNDERFLOW
, "expf", x
, 0, ret
);
547 if (finitef(x
) && !finitef(ret
)) return math_error(_OVERFLOW
, "expf", x
, 0, ret
);
551 /*********************************************************************
552 * MSVCRT_fmodf (MSVCRT.@)
554 float CDECL
MSVCRT_fmodf( float x
, float y
)
556 float ret
= fmodf(x
, y
);
557 if (!finitef(x
) || !finitef(y
)) return math_error(_DOMAIN
, "fmodf", x
, 0, ret
);
561 /*********************************************************************
562 * MSVCRT_logf (MSVCRT.@)
564 float CDECL
MSVCRT_logf( float x
)
567 if (x
< 0.0) return math_error(_DOMAIN
, "logf", x
, 0, ret
);
568 if (x
== 0.0) return math_error(_SING
, "logf", x
, 0, ret
);
572 /*********************************************************************
573 * MSVCRT_log10f (MSVCRT.@)
575 float CDECL
MSVCRT_log10f( float x
)
577 float ret
= log10f(x
);
578 if (x
< 0.0) return math_error(_DOMAIN
, "log10f", x
, 0, ret
);
579 if (x
== 0.0) return math_error(_SING
, "log10f", x
, 0, ret
);
583 /*********************************************************************
584 * MSVCRT_powf (MSVCRT.@)
586 float CDECL
MSVCRT_powf( float x
, float y
)
589 if (x
< 0 && y
!= floorf(y
)) return math_error(_DOMAIN
, "powf", x
, y
, z
);
590 if (!x
&& finitef(y
) && y
< 0) return math_error(_SING
, "powf", x
, y
, z
);
591 if (finitef(x
) && finitef(y
) && !finitef(z
)) return math_error(_OVERFLOW
, "powf", x
, y
, z
);
592 if (x
&& finitef(x
) && finitef(y
) && !z
) return math_error(_UNDERFLOW
, "powf", x
, y
, z
);
596 /*********************************************************************
597 * MSVCRT_sinf (MSVCRT.@)
599 float CDECL
MSVCRT_sinf( float x
)
602 if (!finitef(x
)) return math_error(_DOMAIN
, "sinf", x
, 0, ret
);
606 /*********************************************************************
607 * MSVCRT_sinhf (MSVCRT.@)
609 float CDECL
MSVCRT_sinhf( float x
)
611 float ret
= sinhf(x
);
612 if (isnan(x
)) return math_error(_DOMAIN
, "sinhf", x
, 0, ret
);
616 /*********************************************************************
617 * MSVCRT_sqrtf (MSVCRT.@)
619 * Copied from musl: src/math/sqrtf.c
621 float CDECL
MSVCRT_sqrtf( float x
)
623 static const float tiny
= 1.0e-30;
626 int sign
= 0x80000000;
632 /* take care of Inf and NaN */
633 if ((ix
& 0x7f800000) == 0x7f800000 && (ix
== 0x7f800000 || ix
& 0x7fffff))
636 /* take care of zero */
638 if ((ix
& ~sign
) == 0)
639 return x
; /* sqrt(+-0) = +-0 */
640 return math_error(_DOMAIN
, "sqrtf", x
, 0, (x
- x
) / (x
- x
)); /* sqrt(-ve) = sNaN */
644 if (m
== 0) { /* subnormal x */
645 for (i
= 0; (ix
& 0x00800000) == 0; i
++)
649 m
-= 127; /* unbias exponent */
650 ix
= (ix
& 0x007fffff) | 0x00800000;
651 if (m
& 1) /* odd m, double x to make it even */
653 m
>>= 1; /* m = [m/2] */
655 /* generate sqrt(x) bit by bit */
657 q
= s
= 0; /* q = sqrt(x) */
658 r
= 0x01000000; /* r = moving bit from right to left */
671 /* use floating add to find out rounding direction */
673 z
= 1.0f
- tiny
; /* raise inexact flag */
682 ix
= (q
>> 1) + 0x3f000000;
683 r
= ix
+ ((unsigned int)m
<< 23);
688 /*********************************************************************
689 * MSVCRT_tanf (MSVCRT.@)
691 float CDECL
MSVCRT_tanf( float x
)
694 if (!finitef(x
)) return math_error(_DOMAIN
, "tanf", x
, 0, ret
);
698 /*********************************************************************
699 * MSVCRT_tanhf (MSVCRT.@)
701 float CDECL
MSVCRT_tanhf( float x
)
703 float ret
= tanhf(x
);
704 if (!finitef(x
)) return math_error(_DOMAIN
, "tanhf", x
, 0, ret
);
708 /*********************************************************************
711 float CDECL
MSVCRT_ceilf( float x
)
716 /*********************************************************************
719 float CDECL
MSVCRT_fabsf( float x
)
724 /*********************************************************************
727 float CDECL
MSVCRT_floorf( float x
)
732 /*********************************************************************
735 float CDECL
MSVCRT_frexpf( float x
, int *exp
)
737 return frexpf( x
, exp
);
740 /*********************************************************************
743 float CDECL
MSVCRT_modff( float x
, float *iptr
)
745 return modff( x
, iptr
);
750 /*********************************************************************
751 * MSVCRT_acos (MSVCRT.@)
753 * Copied from musl: src/math/acos.c
755 static double acos_R(double z
)
757 static const double pS0
= 1.66666666666666657415e-01,
758 pS1
= -3.25565818622400915405e-01,
759 pS2
= 2.01212532134862925881e-01,
760 pS3
= -4.00555345006794114027e-02,
761 pS4
= 7.91534994289814532176e-04,
762 pS5
= 3.47933107596021167570e-05,
763 qS1
= -2.40339491173441421878e+00,
764 qS2
= 2.02094576023350569471e+00,
765 qS3
= -6.88283971605453293030e-01,
766 qS4
= 7.70381505559019352791e-02;
769 p
= z
* (pS0
+ z
* (pS1
+ z
* (pS2
+ z
* (pS3
+ z
* (pS4
+ z
* pS5
)))));
770 q
= 1.0 + z
* (qS1
+ z
* (qS2
+ z
* (qS3
+ z
* qS4
)));
774 double CDECL
MSVCRT_acos( double x
)
776 static const double pio2_hi
= 1.57079632679489655800e+00,
777 pio2_lo
= 6.12323399573676603587e-17;
779 double z
, w
, s
, c
, df
;
783 hx
= *(ULONGLONG
*)&x
>> 32;
784 ix
= hx
& 0x7fffffff;
785 /* |x| >= 1 or nan */
786 if (ix
>= 0x3ff00000) {
789 lx
= *(ULONGLONG
*)&x
;
790 if (((ix
- 0x3ff00000) | lx
) == 0) {
791 /* acos(1)=0, acos(-1)=pi */
793 return 2 * pio2_hi
+ 7.5231638452626401e-37;
796 if (isnan(x
)) return x
;
797 return math_error(_DOMAIN
, "acos", x
, 0, 0 / (x
- x
));
800 if (ix
< 0x3fe00000) {
801 if (ix
<= 0x3c600000) /* |x| < 2**-57 */
802 return pio2_hi
+ 7.5231638452626401e-37;
803 return pio2_hi
- (x
- (pio2_lo
- x
* acos_R(x
* x
)));
809 w
= acos_R(z
) * s
- pio2_lo
;
810 return 2 * (pio2_hi
- (s
+ w
));
816 llx
= (*(ULONGLONG
*)&df
>> 32) << 32;
818 c
= (z
- df
* df
) / (s
+ df
);
819 w
= acos_R(z
) * s
+ c
;
823 /*********************************************************************
824 * MSVCRT_asin (MSVCRT.@)
826 * Copied from musl: src/math/asin.c
828 static double asin_R(double z
)
830 /* coefficients for R(x^2) */
831 static const double pS0
= 1.66666666666666657415e-01,
832 pS1
= -3.25565818622400915405e-01,
833 pS2
= 2.01212532134862925881e-01,
834 pS3
= -4.00555345006794114027e-02,
835 pS4
= 7.91534994289814532176e-04,
836 pS5
= 3.47933107596021167570e-05,
837 qS1
= -2.40339491173441421878e+00,
838 qS2
= 2.02094576023350569471e+00,
839 qS3
= -6.88283971605453293030e-01,
840 qS4
= 7.70381505559019352791e-02;
843 p
= z
* (pS0
+ z
* (pS1
+ z
* (pS2
+ z
* (pS3
+ z
* (pS4
+ z
* pS5
)))));
844 q
= 1.0 + z
* (qS1
+ z
* (qS2
+ z
* (qS3
+ z
* qS4
)));
848 double CDECL
MSVCRT_asin( double x
)
850 static const double pio2_hi
= 1.57079632679489655800e+00,
851 pio2_lo
= 6.12323399573676603587e-17;
857 hx
= *(ULONGLONG
*)&x
>> 32;
858 ix
= hx
& 0x7fffffff;
859 /* |x| >= 1 or nan */
860 if (ix
>= 0x3ff00000) {
862 lx
= *(ULONGLONG
*)&x
;
863 if (((ix
- 0x3ff00000) | lx
) == 0)
864 /* asin(1) = +-pi/2 with inexact */
865 return x
* pio2_hi
+ 7.5231638452626401e-37;
866 if (isnan(x
)) return x
;
867 return math_error(_DOMAIN
, "asin", x
, 0, 0 / (x
- x
));
870 if (ix
< 0x3fe00000) {
871 /* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
872 if (ix
< 0x3e500000 && ix
>= 0x00100000)
874 return x
+ x
* asin_R(x
* x
);
877 z
= (1 - fabs(x
)) * 0.5;
880 if (ix
>= 0x3fef3333) { /* if |x| > 0.975 */
881 x
= pio2_hi
- (2 * (s
+ s
* r
) - pio2_lo
);
886 llx
= (*(ULONGLONG
*)&f
>> 32) << 32;
888 c
= (z
- f
* f
) / (s
+ f
);
889 x
= 0.5 * pio2_hi
- (2 * s
* r
- (pio2_lo
- 2 * c
) - (0.5 * pio2_hi
- 2 * f
));
896 /*********************************************************************
897 * MSVCRT_atan (MSVCRT.@)
899 * Copied from musl: src/math/atan.c
901 double CDECL
MSVCRT_atan( double x
)
903 static const double atanhi
[] = {
904 4.63647609000806093515e-01,
905 7.85398163397448278999e-01,
906 9.82793723247329054082e-01,
907 1.57079632679489655800e+00,
909 static const double atanlo
[] = {
910 2.26987774529616870924e-17,
911 3.06161699786838301793e-17,
912 1.39033110312309984516e-17,
913 6.12323399573676603587e-17,
915 static const double aT
[] = {
916 3.33333333333329318027e-01,
917 -1.99999999998764832476e-01,
918 1.42857142725034663711e-01,
919 -1.11111104054623557880e-01,
920 9.09088713343650656196e-02,
921 -7.69187620504482999495e-02,
922 6.66107313738753120669e-02,
923 -5.83357013379057348645e-02,
924 4.97687799461593236017e-02,
925 -3.65315727442169155270e-02,
926 1.62858201153657823623e-02,
930 unsigned int ix
, sign
;
934 if (isnan(x
)) return math_error(_DOMAIN
, "atan", x
, 0, x
);
937 ix
= *(ULONGLONG
*)&x
>> 32;
940 if (ix
>= 0x44100000) { /* if |x| >= 2^66 */
943 z
= atanhi
[3] + 7.5231638452626401e-37;
944 return sign
? -z
: z
;
946 if (ix
< 0x3fdc0000) { /* |x| < 0.4375 */
947 if (ix
< 0x3e400000) { /* |x| < 2^-27 */
949 /* raise underflow for subnormal x */
950 fp_barrierf((float)x
);
956 if (ix
< 0x3ff30000) { /* |x| < 1.1875 */
957 if (ix
< 0x3fe60000) { /* 7/16 <= |x| < 11/16 */
959 x
= (2.0 * x
- 1.0) / (2.0 + x
);
960 } else { /* 11/16 <= |x| < 19/16 */
962 x
= (x
- 1.0) / (x
+ 1.0);
965 if (ix
< 0x40038000) { /* |x| < 2.4375 */
967 x
= (x
- 1.5) / (1.0 + 1.5 * x
);
968 } else { /* 2.4375 <= |x| < 2^66 */
974 /* end of argument reduction */
977 /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
978 s1
= z
* (aT
[0] + w
* (aT
[2] + w
* (aT
[4] + w
* (aT
[6] + w
* (aT
[8] + w
* aT
[10])))));
979 s2
= w
* (aT
[1] + w
* (aT
[3] + w
* (aT
[5] + w
* (aT
[7] + w
* aT
[9]))));
981 return x
- x
* (s1
+ s2
);
982 z
= atanhi
[id
] - (x
* (s1
+ s2
) - atanlo
[id
] - x
);
983 return sign
? -z
: z
;
986 /*********************************************************************
987 * MSVCRT_atan2 (MSVCRT.@)
989 * Copied from musl: src/math/atan2.c
991 double CDECL
MSVCRT_atan2( double y
, double x
)
993 static const double pi
= 3.1415926535897931160E+00,
994 pi_lo
= 1.2246467991473531772E-16;
997 unsigned int m
, lx
, ly
, ix
, iy
;
999 if (isnan(x
) || isnan(y
))
1001 ix
= *(ULONGLONG
*)&x
>> 32;
1002 lx
= *(ULONGLONG
*)&x
;
1003 iy
= *(ULONGLONG
*)&y
>> 32;
1004 ly
= *(ULONGLONG
*)&y
;
1005 if (((ix
- 0x3ff00000) | lx
) == 0) /* x = 1.0 */
1007 m
= ((iy
>> 31) & 1) | ((ix
>> 30) & 2); /* 2*sign(x)+sign(y) */
1008 ix
= ix
& 0x7fffffff;
1009 iy
= iy
& 0x7fffffff;
1012 if ((iy
| ly
) == 0) {
1015 case 1: return y
; /* atan(+-0,+anything)=+-0 */
1016 case 2: return pi
; /* atan(+0,-anything) = pi */
1017 case 3: return -pi
; /* atan(-0,-anything) =-pi */
1022 return m
& 1 ? -pi
/ 2 : pi
/ 2;
1024 if (ix
== 0x7ff00000) {
1025 if (iy
== 0x7ff00000) {
1027 case 0: return pi
/ 4; /* atan(+INF,+INF) */
1028 case 1: return -pi
/ 4; /* atan(-INF,+INF) */
1029 case 2: return 3 * pi
/ 4; /* atan(+INF,-INF) */
1030 case 3: return -3 * pi
/ 4; /* atan(-INF,-INF) */
1034 case 0: return 0.0; /* atan(+...,+INF) */
1035 case 1: return -0.0; /* atan(-...,+INF) */
1036 case 2: return pi
; /* atan(+...,-INF) */
1037 case 3: return -pi
; /* atan(-...,-INF) */
1041 /* |y/x| > 0x1p64 */
1042 if (ix
+ (64 << 20) < iy
|| iy
== 0x7ff00000)
1043 return m
& 1 ? -pi
/ 2 : pi
/ 2;
1045 /* z = atan(|y/x|) without spurious underflow */
1046 if ((m
& 2) && iy
+ (64 << 20) < ix
) /* |y/x| < 0x1p-64, x<0 */
1049 z
= atan(fabs(y
/ x
));
1051 case 0: return z
; /* atan(+,+) */
1052 case 1: return -z
; /* atan(-,+) */
1053 case 2: return pi
- (z
- pi_lo
); /* atan(+,-) */
1054 default: /* case 3 */
1055 return (z
- pi_lo
) - pi
; /* atan(-,-) */
1059 /*********************************************************************
1060 * MSVCRT_cos (MSVCRT.@)
1062 double CDECL
MSVCRT_cos( double x
)
1064 double ret
= cos(x
);
1065 if (!isfinite(x
)) return math_error(_DOMAIN
, "cos", x
, 0, ret
);
1069 /*********************************************************************
1070 * MSVCRT_cosh (MSVCRT.@)
1072 double CDECL
MSVCRT_cosh( double x
)
1074 double ret
= cosh(x
);
1075 if (isnan(x
)) return math_error(_DOMAIN
, "cosh", x
, 0, ret
);
1079 /*********************************************************************
1080 * MSVCRT_exp (MSVCRT.@)
1082 double CDECL
MSVCRT_exp( double x
)
1084 double ret
= exp(x
);
1085 if (isnan(x
)) return math_error(_DOMAIN
, "exp", x
, 0, ret
);
1086 if (isfinite(x
) && !ret
) return math_error(_UNDERFLOW
, "exp", x
, 0, ret
);
1087 if (isfinite(x
) && !isfinite(ret
)) return math_error(_OVERFLOW
, "exp", x
, 0, ret
);
1091 /*********************************************************************
1092 * MSVCRT_fmod (MSVCRT.@)
1094 double CDECL
MSVCRT_fmod( double x
, double y
)
1096 double ret
= fmod(x
, y
);
1097 if (!isfinite(x
) || !isfinite(y
)) return math_error(_DOMAIN
, "fmod", x
, y
, ret
);
1101 /*********************************************************************
1102 * MSVCRT_log (MSVCRT.@)
1104 double CDECL
MSVCRT_log( double x
)
1106 double ret
= log(x
);
1107 if (x
< 0.0) return math_error(_DOMAIN
, "log", x
, 0, ret
);
1108 if (x
== 0.0) return math_error(_SING
, "log", x
, 0, ret
);
1112 /*********************************************************************
1113 * MSVCRT_log10 (MSVCRT.@)
1115 double CDECL
MSVCRT_log10( double x
)
1117 double ret
= log10(x
);
1118 if (x
< 0.0) return math_error(_DOMAIN
, "log10", x
, 0, ret
);
1119 if (x
== 0.0) return math_error(_SING
, "log10", x
, 0, ret
);
1123 /*********************************************************************
1124 * MSVCRT_pow (MSVCRT.@)
1126 double CDECL
MSVCRT_pow( double x
, double y
)
1128 double z
= pow(x
,y
);
1129 if (x
< 0 && y
!= floor(y
))
1130 return math_error(_DOMAIN
, "pow", x
, y
, z
);
1131 if (!x
&& isfinite(y
) && y
< 0)
1132 return math_error(_SING
, "pow", x
, y
, z
);
1133 if (isfinite(x
) && isfinite(y
) && !isfinite(z
))
1134 return math_error(_OVERFLOW
, "pow", x
, y
, z
);
1135 if (x
&& isfinite(x
) && isfinite(y
) && !z
)
1136 return math_error(_UNDERFLOW
, "pow", x
, y
, z
);
1140 /*********************************************************************
1141 * MSVCRT_sin (MSVCRT.@)
1143 double CDECL
MSVCRT_sin( double x
)
1145 double ret
= sin(x
);
1146 if (!isfinite(x
)) return math_error(_DOMAIN
, "sin", x
, 0, ret
);
1150 /*********************************************************************
1151 * MSVCRT_sinh (MSVCRT.@)
1153 double CDECL
MSVCRT_sinh( double x
)
1155 double ret
= sinh(x
);
1156 if (isnan(x
)) return math_error(_DOMAIN
, "sinh", x
, 0, ret
);
1160 /*********************************************************************
1161 * MSVCRT_sqrt (MSVCRT.@)
1163 * Copied from musl: src/math/sqrt.c
1165 double CDECL
MSVCRT_sqrt( double x
)
1167 static const double tiny
= 1.0e-300;
1170 int sign
= 0x80000000;
1172 unsigned int r
,t1
,s1
,ix1
,q1
;
1175 ix
= *(ULONGLONG
*)&x
;
1179 /* take care of Inf and NaN */
1180 if (isnan(x
) || (isinf(x
) && x
> 0))
1183 /* take care of zero */
1185 if (((ix0
& ~sign
) | ix1
) == 0)
1186 return x
; /* sqrt(+-0) = +-0 */
1188 return math_error(_DOMAIN
, "sqrt", x
, 0, (x
- x
) / (x
- x
));
1192 if (m
== 0) { /* subnormal x */
1198 for (i
=0; (ix0
& 0x00100000) == 0; i
++)
1201 ix0
|= ix1
>> (32 - i
);
1204 m
-= 1023; /* unbias exponent */
1205 ix0
= (ix0
& 0x000fffff) | 0x00100000;
1206 if (m
& 1) { /* odd m, double x to make it even */
1207 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1210 m
>>= 1; /* m = [m/2] */
1212 /* generate sqrt(x) bit by bit */
1213 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1215 q
= q1
= s0
= s1
= 0; /* [q,q1] = sqrt(x) */
1216 r
= 0x00200000; /* r = moving bit from right to left */
1225 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1234 if (t
< ix0
|| (t
== ix0
&& t1
<= ix1
)) {
1236 if ((t1
&sign
) == sign
&& (s1
& sign
) == 0)
1244 ix0
+= ix0
+ ((ix1
& sign
) >> 31);
1249 /* use floating add to find out rounding direction */
1250 if ((ix0
| ix1
) != 0) {
1251 z
= 1.0 - tiny
; /* raise inexact flag */
1254 if (q1
== (unsigned int)0xffffffff) {
1257 } else if (z
> 1.0) {
1258 if (q1
== (unsigned int)0xfffffffe)
1265 ix0
= (q
>> 1) + 0x3fe00000;
1269 ix
= ix0
+ ((unsigned int)m
<< 20);
1272 return *(double*)&ix
;
1275 /*********************************************************************
1276 * MSVCRT_tan (MSVCRT.@)
1278 double CDECL
MSVCRT_tan( double x
)
1280 double ret
= tan(x
);
1281 if (!isfinite(x
)) return math_error(_DOMAIN
, "tan", x
, 0, ret
);
1285 /*********************************************************************
1286 * MSVCRT_tanh (MSVCRT.@)
1288 double CDECL
MSVCRT_tanh( double x
)
1290 double ret
= tanh(x
);
1291 if (isnan(x
)) return math_error(_DOMAIN
, "tanh", x
, 0, ret
);
1296 #if defined(__GNUC__) && defined(__i386__)
1298 #define CREATE_FPU_FUNC1(name, call) \
1299 __ASM_GLOBAL_FUNC(name, \
1301 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1302 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
1303 "movl %esp, %ebp\n\t" \
1304 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
1305 "subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
1306 "fstpl (%esp)\n\t" /* store function argument */ \
1308 "movl $1, %ecx\n\t" /* empty FPU stack */ \
1312 "and $0x4500, %ax\n\t" \
1313 "cmp $0x4100, %ax\n\t" \
1315 "fstpl (%esp,%ecx,8)\n\t" \
1320 "movl %ecx, -4(%ebp)\n\t" \
1321 "call " __ASM_NAME( #call ) "\n\t" \
1322 "movl -4(%ebp), %ecx\n\t" \
1323 "fstpl (%esp)\n\t" /* save result */ \
1324 "3:\n\t" /* restore FPU stack */ \
1326 "fldl (%esp,%ecx,8)\n\t" \
1327 "cmpl $0, %ecx\n\t" \
1330 __ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
1331 __ASM_CFI(".cfi_same_value %ebp\n\t") \
1334 #define CREATE_FPU_FUNC2(name, call) \
1335 __ASM_GLOBAL_FUNC(name, \
1337 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1338 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") \
1339 "movl %esp, %ebp\n\t" \
1340 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") \
1341 "subl $68, %esp\n\t" /* sizeof(double)*8 + sizeof(int) */ \
1342 "fstpl 8(%esp)\n\t" /* store function argument */ \
1344 "fstpl (%esp)\n\t" \
1346 "movl $2, %ecx\n\t" /* empty FPU stack */ \
1350 "and $0x4500, %ax\n\t" \
1351 "cmp $0x4100, %ax\n\t" \
1353 "fstpl (%esp,%ecx,8)\n\t" \
1358 "movl %ecx, -4(%ebp)\n\t" \
1359 "call " __ASM_NAME( #call ) "\n\t" \
1360 "movl -4(%ebp), %ecx\n\t" \
1361 "fstpl 8(%esp)\n\t" /* save result */ \
1362 "3:\n\t" /* restore FPU stack */ \
1364 "fldl (%esp,%ecx,8)\n\t" \
1365 "cmpl $1, %ecx\n\t" \
1368 __ASM_CFI(".cfi_def_cfa %esp,4\n\t") \
1369 __ASM_CFI(".cfi_same_value %ebp\n\t") \
1372 CREATE_FPU_FUNC1(_CIacos
, MSVCRT_acos
)
1373 CREATE_FPU_FUNC1(_CIasin
, MSVCRT_asin
)
1374 CREATE_FPU_FUNC1(_CIatan
, MSVCRT_atan
)
1375 CREATE_FPU_FUNC2(_CIatan2
, MSVCRT_atan2
)
1376 CREATE_FPU_FUNC1(_CIcos
, MSVCRT_cos
)
1377 CREATE_FPU_FUNC1(_CIcosh
, MSVCRT_cosh
)
1378 CREATE_FPU_FUNC1(_CIexp
, MSVCRT_exp
)
1379 CREATE_FPU_FUNC2(_CIfmod
, MSVCRT_fmod
)
1380 CREATE_FPU_FUNC1(_CIlog
, MSVCRT_log
)
1381 CREATE_FPU_FUNC1(_CIlog10
, MSVCRT_log10
)
1382 CREATE_FPU_FUNC2(_CIpow
, MSVCRT_pow
)
1383 CREATE_FPU_FUNC1(_CIsin
, MSVCRT_sin
)
1384 CREATE_FPU_FUNC1(_CIsinh
, MSVCRT_sinh
)
1385 CREATE_FPU_FUNC1(_CIsqrt
, MSVCRT_sqrt
)
1386 CREATE_FPU_FUNC1(_CItan
, MSVCRT_tan
)
1387 CREATE_FPU_FUNC1(_CItanh
, MSVCRT_tanh
)
1389 __ASM_GLOBAL_FUNC(MSVCRT__ftol
,
1391 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1392 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1393 "movl %esp, %ebp\n\t"
1394 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1395 "subl $12, %esp\n\t" /* sizeof(LONGLONG) + 2*sizeof(WORD) */
1397 "mov (%esp), %ax\n\t"
1398 "or $0xc00, %ax\n\t"
1399 "mov %ax, 2(%esp)\n\t"
1401 "fistpq 4(%esp)\n\t"
1403 "movl 4(%esp), %eax\n\t"
1404 "movl 8(%esp), %edx\n\t"
1406 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1407 __ASM_CFI(".cfi_same_value %ebp\n\t")
1410 #endif /* defined(__GNUC__) && defined(__i386__) */
1412 /*********************************************************************
1413 * _fpclass (MSVCRT.@)
1415 int CDECL
MSVCRT__fpclass(double num
)
1417 union { double f
; UINT64 i
; } u
= { num
};
1418 int e
= u
.i
>> 52 & 0x7ff;
1424 if (u
.i
<< 1) return s
? MSVCRT__FPCLASS_ND
: MSVCRT__FPCLASS_PD
;
1425 return s
? MSVCRT__FPCLASS_NZ
: MSVCRT__FPCLASS_PZ
;
1427 if (u
.i
<< 12) return ((u
.i
>> 51) & 1) ? MSVCRT__FPCLASS_QNAN
: MSVCRT__FPCLASS_SNAN
;
1428 return s
? MSVCRT__FPCLASS_NINF
: MSVCRT__FPCLASS_PINF
;
1430 return s
? MSVCRT__FPCLASS_NN
: MSVCRT__FPCLASS_PN
;
1434 /*********************************************************************
1437 unsigned int CDECL
_rotl(unsigned int num
, int shift
)
1440 return (num
<< shift
) | (num
>> (32-shift
));
1443 /*********************************************************************
1446 MSVCRT_ulong CDECL
MSVCRT__lrotl(MSVCRT_ulong num
, int shift
)
1449 return (num
<< shift
) | (num
>> (32-shift
));
1452 /*********************************************************************
1455 MSVCRT_ulong CDECL
MSVCRT__lrotr(MSVCRT_ulong num
, int shift
)
1458 return (num
>> shift
) | (num
<< (32-shift
));
1461 /*********************************************************************
1464 unsigned int CDECL
_rotr(unsigned int num
, int shift
)
1467 return (num
>> shift
) | (num
<< (32-shift
));
1470 /*********************************************************************
1471 * _rotl64 (MSVCRT.@)
1473 unsigned __int64 CDECL
_rotl64(unsigned __int64 num
, int shift
)
1476 return (num
<< shift
) | (num
>> (64-shift
));
1479 /*********************************************************************
1480 * _rotr64 (MSVCRT.@)
1482 unsigned __int64 CDECL
_rotr64(unsigned __int64 num
, int shift
)
1485 return (num
>> shift
) | (num
<< (64-shift
));
1488 /*********************************************************************
1491 int CDECL
MSVCRT_abs( int n
)
1493 return n
>= 0 ? n
: -n
;
1496 /*********************************************************************
1499 MSVCRT_long CDECL
MSVCRT_labs( MSVCRT_long n
)
1501 return n
>= 0 ? n
: -n
;
1505 /*********************************************************************
1506 * llabs (MSVCR100.@)
1508 MSVCRT_longlong CDECL
MSVCRT_llabs( MSVCRT_longlong n
)
1510 return n
>= 0 ? n
: -n
;
1515 /*********************************************************************
1516 * imaxabs (MSVCR120.@)
1518 MSVCRT_intmax_t CDECL
MSVCRT_imaxabs( MSVCRT_intmax_t n
)
1520 return n
>= 0 ? n
: -n
;
1524 /*********************************************************************
1527 __int64 CDECL
_abs64( __int64 n
)
1529 return n
>= 0 ? n
: -n
;
1532 /*********************************************************************
1535 double CDECL
MSVCRT__logb(double num
)
1537 double ret
= logb(num
);
1538 if (isnan(num
)) return math_error(_DOMAIN
, "_logb", num
, 0, ret
);
1539 if (!num
) return math_error(_SING
, "_logb", num
, 0, ret
);
1543 /*********************************************************************
1546 double CDECL
_hypot(double x
, double y
)
1548 /* FIXME: errno handling */
1549 return hypot( x
, y
);
1552 /*********************************************************************
1553 * _hypotf (MSVCRT.@)
1555 float CDECL
MSVCRT__hypotf(float x
, float y
)
1557 /* FIXME: errno handling */
1558 return hypotf( x
, y
);
1561 /*********************************************************************
1564 double CDECL
MSVCRT_ceil( double x
)
1569 /*********************************************************************
1572 double CDECL
MSVCRT_floor( double x
)
1577 /*********************************************************************
1580 double CDECL
MSVCRT_fma( double x
, double y
, double z
)
1583 double w
= fma(x
, y
, z
);
1585 double w
= x
* y
+ z
;
1587 if ((isinf(x
) && y
== 0) || (x
== 0 && isinf(y
))) *MSVCRT__errno() = MSVCRT_EDOM
;
1588 else if (isinf(x
) && isinf(z
) && x
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1589 else if (isinf(y
) && isinf(z
) && y
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1593 /*********************************************************************
1596 float CDECL
MSVCRT_fmaf( float x
, float y
, float z
)
1599 float w
= fmaf(x
, y
, z
);
1601 float w
= x
* y
+ z
;
1603 if ((isinf(x
) && y
== 0) || (x
== 0 && isinf(y
))) *MSVCRT__errno() = MSVCRT_EDOM
;
1604 else if (isinf(x
) && isinf(z
) && x
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1605 else if (isinf(y
) && isinf(z
) && y
!= z
) *MSVCRT__errno() = MSVCRT_EDOM
;
1609 /*********************************************************************
1612 double CDECL
MSVCRT_fabs( double x
)
1617 /*********************************************************************
1620 double CDECL
MSVCRT_frexp( double x
, int *exp
)
1622 return frexp( x
, exp
);
1625 /*********************************************************************
1628 double CDECL
MSVCRT_modf( double x
, double *iptr
)
1630 return modf( x
, iptr
);
1633 /**********************************************************************
1634 * _statusfp2 (MSVCRT.@)
1636 * Not exported by native msvcrt, added in msvcr80.
1638 #if defined(__i386__) || defined(__x86_64__)
1639 void CDECL
_statusfp2( unsigned int *x86_sw
, unsigned int *sse2_sw
)
1643 unsigned long fpword
;
1647 __asm__
__volatile__( "fstsw %0" : "=m" (fpword
) );
1649 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1650 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1651 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1652 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1653 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1654 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1658 if (!sse2_sw
) return;
1662 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1664 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1665 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1666 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1667 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1668 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1669 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1674 FIXME( "not implemented\n" );
1679 /**********************************************************************
1680 * _statusfp (MSVCRT.@)
1682 unsigned int CDECL
_statusfp(void)
1684 unsigned int flags
= 0;
1685 #if defined(__i386__) || defined(__x86_64__)
1686 unsigned int x86_sw
, sse2_sw
;
1688 _statusfp2( &x86_sw
, &sse2_sw
);
1689 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
1690 flags
= x86_sw
| sse2_sw
;
1691 #elif defined(__aarch64__)
1694 __asm__
__volatile__( "mrs %0, fpsr" : "=r" (fpsr
) );
1695 if (fpsr
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1696 if (fpsr
& 0x2) flags
|= MSVCRT__SW_ZERODIVIDE
;
1697 if (fpsr
& 0x4) flags
|= MSVCRT__SW_OVERFLOW
;
1698 if (fpsr
& 0x8) flags
|= MSVCRT__SW_UNDERFLOW
;
1699 if (fpsr
& 0x10) flags
|= MSVCRT__SW_INEXACT
;
1700 if (fpsr
& 0x80) flags
|= MSVCRT__SW_DENORMAL
;
1702 FIXME( "not implemented\n" );
1707 /*********************************************************************
1708 * _clearfp (MSVCRT.@)
1710 unsigned int CDECL
_clearfp(void)
1712 unsigned int flags
= 0;
1713 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1714 unsigned long fpword
;
1716 __asm__
__volatile__( "fnstsw %0; fnclex" : "=m" (fpword
) );
1717 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1718 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1719 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1720 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1721 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1722 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1726 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1727 if (fpword
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1728 if (fpword
& 0x2) flags
|= MSVCRT__SW_DENORMAL
;
1729 if (fpword
& 0x4) flags
|= MSVCRT__SW_ZERODIVIDE
;
1730 if (fpword
& 0x8) flags
|= MSVCRT__SW_OVERFLOW
;
1731 if (fpword
& 0x10) flags
|= MSVCRT__SW_UNDERFLOW
;
1732 if (fpword
& 0x20) flags
|= MSVCRT__SW_INEXACT
;
1734 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1736 #elif defined(__aarch64__)
1739 __asm__
__volatile__( "mrs %0, fpsr" : "=r" (fpsr
) );
1740 if (fpsr
& 0x1) flags
|= MSVCRT__SW_INVALID
;
1741 if (fpsr
& 0x2) flags
|= MSVCRT__SW_ZERODIVIDE
;
1742 if (fpsr
& 0x4) flags
|= MSVCRT__SW_OVERFLOW
;
1743 if (fpsr
& 0x8) flags
|= MSVCRT__SW_UNDERFLOW
;
1744 if (fpsr
& 0x10) flags
|= MSVCRT__SW_INEXACT
;
1745 if (fpsr
& 0x80) flags
|= MSVCRT__SW_DENORMAL
;
1747 __asm__
__volatile__( "msr fpsr, %0" :: "r" (fpsr
) );
1749 FIXME( "not implemented\n" );
1754 /*********************************************************************
1755 * __fpecode (MSVCRT.@)
1757 int * CDECL
__fpecode(void)
1759 return &msvcrt_get_thread_data()->fpecode
;
1762 /*********************************************************************
1765 double CDECL
MSVCRT_ldexp(double num
, MSVCRT_long exp
)
1767 double z
= ldexp(num
,exp
);
1769 if (isfinite(num
) && !isfinite(z
))
1770 return math_error(_OVERFLOW
, "ldexp", num
, exp
, z
);
1771 if (num
&& isfinite(num
) && !z
)
1772 return math_error(_UNDERFLOW
, "ldexp", num
, exp
, z
);
1773 if (z
== 0 && signbit(z
))
1774 z
= 0.0; /* Convert -0 -> +0 */
1778 /*********************************************************************
1781 double CDECL
MSVCRT__cabs(struct MSVCRT__complex num
)
1783 return sqrt(num
.x
* num
.x
+ num
.y
* num
.y
);
1786 /*********************************************************************
1787 * _chgsign (MSVCRT.@)
1789 double CDECL
MSVCRT__chgsign(double num
)
1791 /* FIXME: +-infinity,Nan not tested */
1795 /*********************************************************************
1796 * __control87_2 (MSVCR80.@)
1798 * Not exported by native msvcrt, added in msvcr80.
1801 int CDECL
__control87_2( unsigned int newval
, unsigned int mask
,
1802 unsigned int *x86_cw
, unsigned int *sse2_cw
)
1805 unsigned long fpword
;
1807 unsigned int old_flags
;
1811 __asm__
__volatile__( "fstcw %0" : "=m" (fpword
) );
1813 /* Convert into mask constants */
1815 if (fpword
& 0x1) flags
|= MSVCRT__EM_INVALID
;
1816 if (fpword
& 0x2) flags
|= MSVCRT__EM_DENORMAL
;
1817 if (fpword
& 0x4) flags
|= MSVCRT__EM_ZERODIVIDE
;
1818 if (fpword
& 0x8) flags
|= MSVCRT__EM_OVERFLOW
;
1819 if (fpword
& 0x10) flags
|= MSVCRT__EM_UNDERFLOW
;
1820 if (fpword
& 0x20) flags
|= MSVCRT__EM_INEXACT
;
1821 switch (fpword
& 0xc00)
1823 case 0xc00: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1824 case 0x800: flags
|= MSVCRT__RC_UP
; break;
1825 case 0x400: flags
|= MSVCRT__RC_DOWN
; break;
1827 switch (fpword
& 0x300)
1829 case 0x0: flags
|= MSVCRT__PC_24
; break;
1830 case 0x200: flags
|= MSVCRT__PC_53
; break;
1831 case 0x300: flags
|= MSVCRT__PC_64
; break;
1833 if (fpword
& 0x1000) flags
|= MSVCRT__IC_AFFINE
;
1835 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1838 flags
= (flags
& ~mask
) | (newval
& mask
);
1840 /* Convert (masked) value back to fp word */
1842 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x1;
1843 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x2;
1844 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x4;
1845 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x8;
1846 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x10;
1847 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x20;
1848 switch (flags
& MSVCRT__MCW_RC
)
1850 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0xc00; break;
1851 case MSVCRT__RC_UP
: fpword
|= 0x800; break;
1852 case MSVCRT__RC_DOWN
: fpword
|= 0x400; break;
1854 switch (flags
& MSVCRT__MCW_PC
)
1856 case MSVCRT__PC_64
: fpword
|= 0x300; break;
1857 case MSVCRT__PC_53
: fpword
|= 0x200; break;
1858 case MSVCRT__PC_24
: fpword
|= 0x0; break;
1860 if (flags
& MSVCRT__IC_AFFINE
) fpword
|= 0x1000;
1862 __asm__
__volatile__( "fldcw %0" : : "m" (fpword
) );
1867 if (!sse2_cw
) return 1;
1871 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1873 /* Convert into mask constants */
1875 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1876 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1877 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1878 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1879 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1880 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1881 switch (fpword
& 0x6000)
1883 case 0x6000: flags
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
1884 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1885 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1887 switch (fpword
& 0x8040)
1889 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1890 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1891 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1894 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags
, newval
, mask
);
1898 mask
&= MSVCRT__MCW_EM
| MSVCRT__MCW_RC
| MSVCRT__MCW_DN
;
1899 flags
= (flags
& ~mask
) | (newval
& mask
);
1901 if (flags
!= old_flags
)
1903 /* Convert (masked) value back to fp word */
1905 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1906 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1907 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1908 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1909 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1910 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1911 switch (flags
& MSVCRT__MCW_RC
)
1913 case MSVCRT__RC_UP
|MSVCRT__RC_DOWN
: fpword
|= 0x6000; break;
1914 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1915 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1917 switch (flags
& MSVCRT__MCW_DN
)
1919 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1920 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1921 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1923 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
1932 FIXME( "not implemented\n" );
1938 /*********************************************************************
1939 * _control87 (MSVCRT.@)
1941 unsigned int CDECL
_control87(unsigned int newval
, unsigned int mask
)
1943 unsigned int flags
= 0;
1945 unsigned int sse2_cw
;
1947 __control87_2( newval
, mask
, &flags
, &sse2_cw
);
1949 if ((flags
^ sse2_cw
) & (MSVCRT__MCW_EM
| MSVCRT__MCW_RC
)) flags
|= MSVCRT__EM_AMBIGUOUS
;
1951 #elif defined(__x86_64__)
1952 unsigned long fpword
;
1953 unsigned int old_flags
;
1955 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
1956 if (fpword
& 0x80) flags
|= MSVCRT__EM_INVALID
;
1957 if (fpword
& 0x100) flags
|= MSVCRT__EM_DENORMAL
;
1958 if (fpword
& 0x200) flags
|= MSVCRT__EM_ZERODIVIDE
;
1959 if (fpword
& 0x400) flags
|= MSVCRT__EM_OVERFLOW
;
1960 if (fpword
& 0x800) flags
|= MSVCRT__EM_UNDERFLOW
;
1961 if (fpword
& 0x1000) flags
|= MSVCRT__EM_INEXACT
;
1962 switch (fpword
& 0x6000)
1964 case 0x6000: flags
|= MSVCRT__RC_CHOP
; break;
1965 case 0x4000: flags
|= MSVCRT__RC_UP
; break;
1966 case 0x2000: flags
|= MSVCRT__RC_DOWN
; break;
1968 switch (fpword
& 0x8040)
1970 case 0x0040: flags
|= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
; break;
1971 case 0x8000: flags
|= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
; break;
1972 case 0x8040: flags
|= MSVCRT__DN_FLUSH
; break;
1975 mask
&= MSVCRT__MCW_EM
| MSVCRT__MCW_RC
| MSVCRT__MCW_DN
;
1976 flags
= (flags
& ~mask
) | (newval
& mask
);
1977 if (flags
!= old_flags
)
1980 if (flags
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
1981 if (flags
& MSVCRT__EM_DENORMAL
) fpword
|= 0x100;
1982 if (flags
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
1983 if (flags
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
1984 if (flags
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
1985 if (flags
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
1986 switch (flags
& MSVCRT__MCW_RC
)
1988 case MSVCRT__RC_CHOP
: fpword
|= 0x6000; break;
1989 case MSVCRT__RC_UP
: fpword
|= 0x4000; break;
1990 case MSVCRT__RC_DOWN
: fpword
|= 0x2000; break;
1992 switch (flags
& MSVCRT__MCW_DN
)
1994 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS
: fpword
|= 0x0040; break;
1995 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS
: fpword
|= 0x8000; break;
1996 case MSVCRT__DN_FLUSH
: fpword
|= 0x8040; break;
1998 __asm__
__volatile__( "ldmxcsr %0" :: "m" (fpword
) );
2000 #elif defined(__aarch64__)
2003 __asm__
__volatile__( "mrs %0, fpcr" : "=r" (fpcr
) );
2004 if (!(fpcr
& 0x100)) flags
|= MSVCRT__EM_INVALID
;
2005 if (!(fpcr
& 0x200)) flags
|= MSVCRT__EM_ZERODIVIDE
;
2006 if (!(fpcr
& 0x400)) flags
|= MSVCRT__EM_OVERFLOW
;
2007 if (!(fpcr
& 0x800)) flags
|= MSVCRT__EM_UNDERFLOW
;
2008 if (!(fpcr
& 0x1000)) flags
|= MSVCRT__EM_INEXACT
;
2009 if (!(fpcr
& 0x8000)) flags
|= MSVCRT__EM_DENORMAL
;
2010 switch (fpcr
& 0xc00000)
2012 case 0x400000: flags
|= MSVCRT__RC_UP
; break;
2013 case 0x800000: flags
|= MSVCRT__RC_DOWN
; break;
2014 case 0xc00000: flags
|= MSVCRT__RC_CHOP
; break;
2016 flags
= (flags
& ~mask
) | (newval
& mask
);
2017 fpcr
&= ~0xc09f00ul
;
2018 if (!(flags
& MSVCRT__EM_INVALID
)) fpcr
|= 0x100;
2019 if (!(flags
& MSVCRT__EM_ZERODIVIDE
)) fpcr
|= 0x200;
2020 if (!(flags
& MSVCRT__EM_OVERFLOW
)) fpcr
|= 0x400;
2021 if (!(flags
& MSVCRT__EM_UNDERFLOW
)) fpcr
|= 0x800;
2022 if (!(flags
& MSVCRT__EM_INEXACT
)) fpcr
|= 0x1000;
2023 if (!(flags
& MSVCRT__EM_DENORMAL
)) fpcr
|= 0x8000;
2024 switch (flags
& MSVCRT__MCW_RC
)
2026 case MSVCRT__RC_CHOP
: fpcr
|= 0xc00000; break;
2027 case MSVCRT__RC_UP
: fpcr
|= 0x400000; break;
2028 case MSVCRT__RC_DOWN
: fpcr
|= 0x800000; break;
2030 __asm__
__volatile__( "msr fpcr, %0" :: "r" (fpcr
) );
2032 FIXME( "not implemented\n" );
2037 /*********************************************************************
2038 * _controlfp (MSVCRT.@)
2040 unsigned int CDECL
_controlfp(unsigned int newval
, unsigned int mask
)
2042 return _control87( newval
, mask
& ~MSVCRT__EM_DENORMAL
);
2045 /*********************************************************************
2046 * _set_controlfp (MSVCRT.@)
2048 void CDECL
_set_controlfp( unsigned int newval
, unsigned int mask
)
2050 _controlfp( newval
, mask
);
2053 /*********************************************************************
2054 * _controlfp_s (MSVCRT.@)
2056 int CDECL
_controlfp_s(unsigned int *cur
, unsigned int newval
, unsigned int mask
)
2058 static const unsigned int all_flags
= (MSVCRT__MCW_EM
| MSVCRT__MCW_IC
| MSVCRT__MCW_RC
|
2059 MSVCRT__MCW_PC
| MSVCRT__MCW_DN
);
2062 if (!MSVCRT_CHECK_PMT( !(newval
& mask
& ~all_flags
) ))
2064 if (cur
) *cur
= _controlfp( 0, 0 ); /* retrieve it anyway */
2065 return MSVCRT_EINVAL
;
2067 val
= _controlfp( newval
, mask
);
2068 if (cur
) *cur
= val
;
2073 /*********************************************************************
2074 * fegetenv (MSVCR120.@)
2076 int CDECL
MSVCRT_fegetenv(MSVCRT_fenv_t
*env
)
2078 env
->control
= _controlfp(0, 0) & (MSVCRT__EM_INEXACT
| MSVCRT__EM_UNDERFLOW
|
2079 MSVCRT__EM_OVERFLOW
| MSVCRT__EM_ZERODIVIDE
| MSVCRT__EM_INVALID
);
2080 env
->status
= _statusfp();
2086 /*********************************************************************
2087 * __fpe_flt_rounds (UCRTBASE.@)
2089 int CDECL
__fpe_flt_rounds(void)
2091 unsigned int fpc
= _controlfp(0, 0) & MSVCRT__RC_CHOP
;
2096 case MSVCRT__RC_CHOP
: return 0;
2097 case MSVCRT__RC_NEAR
: return 1;
2098 case MSVCRT__RC_UP
: return 2;
2106 /*********************************************************************
2107 * fegetround (MSVCR120.@)
2109 int CDECL
MSVCRT_fegetround(void)
2111 return _controlfp(0, 0) & MSVCRT__RC_CHOP
;
2114 /*********************************************************************
2115 * fesetround (MSVCR120.@)
2117 int CDECL
MSVCRT_fesetround(int round_mode
)
2119 if (round_mode
& (~MSVCRT__RC_CHOP
))
2121 _controlfp(round_mode
, MSVCRT__RC_CHOP
);
2125 #endif /* _MSVCR_VER>=120 */
2127 /*********************************************************************
2128 * _copysign (MSVCRT.@)
2130 double CDECL
MSVCRT__copysign(double num
, double sign
)
2133 return signbit(num
) ? num
: -num
;
2134 return signbit(num
) ? -num
: num
;
2137 /*********************************************************************
2138 * _finite (MSVCRT.@)
2140 int CDECL
MSVCRT__finite(double num
)
2142 union { double f
; UINT64 i
; } u
= { num
};
2143 return (u
.i
& ~0ull >> 1) < 0x7ffull
<< 52;
2146 /*********************************************************************
2147 * _fpreset (MSVCRT.@)
2149 void CDECL
_fpreset(void)
2151 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2152 const unsigned int x86_cw
= 0x27f;
2153 __asm__
__volatile__( "fninit; fldcw %0" : : "m" (x86_cw
) );
2156 const unsigned long sse2_cw
= 0x1f80;
2157 __asm__
__volatile__( "ldmxcsr %0" : : "m" (sse2_cw
) );
2160 FIXME( "not implemented\n" );
2165 /*********************************************************************
2166 * fesetenv (MSVCR120.@)
2168 int CDECL
MSVCRT_fesetenv(const MSVCRT_fenv_t
*env
)
2170 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2178 DWORD instruction_pointer
;
2186 TRACE( "(%p)\n", env
);
2188 if (!env
->control
&& !env
->status
) {
2193 __asm__
__volatile__( "fnstenv %0" : "=m" (fenv
) );
2195 fenv
.control_word
&= ~0x3d;
2196 if (env
->control
& MSVCRT__EM_INVALID
) fenv
.control_word
|= 0x1;
2197 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fenv
.control_word
|= 0x4;
2198 if (env
->control
& MSVCRT__EM_OVERFLOW
) fenv
.control_word
|= 0x8;
2199 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fenv
.control_word
|= 0x10;
2200 if (env
->control
& MSVCRT__EM_INEXACT
) fenv
.control_word
|= 0x20;
2202 fenv
.status_word
&= ~0x3d;
2203 if (env
->status
& MSVCRT__SW_INVALID
) fenv
.status_word
|= 0x1;
2204 if (env
->status
& MSVCRT__SW_ZERODIVIDE
) fenv
.status_word
|= 0x4;
2205 if (env
->status
& MSVCRT__SW_OVERFLOW
) fenv
.status_word
|= 0x8;
2206 if (env
->status
& MSVCRT__SW_UNDERFLOW
) fenv
.status_word
|= 0x10;
2207 if (env
->status
& MSVCRT__SW_INEXACT
) fenv
.status_word
|= 0x20;
2209 __asm__
__volatile__( "fldenv %0" : : "m" (fenv
) : "st", "st(1)",
2210 "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)" );
2216 __asm__
__volatile__( "stmxcsr %0" : "=m" (fpword
) );
2218 if (env
->control
& MSVCRT__EM_INVALID
) fpword
|= 0x80;
2219 if (env
->control
& MSVCRT__EM_ZERODIVIDE
) fpword
|= 0x200;
2220 if (env
->control
& MSVCRT__EM_OVERFLOW
) fpword
|= 0x400;
2221 if (env
->control
& MSVCRT__EM_UNDERFLOW
) fpword
|= 0x800;
2222 if (env
->control
& MSVCRT__EM_INEXACT
) fpword
|= 0x1000;
2223 __asm__
__volatile__( "ldmxcsr %0" : : "m" (fpword
) );
2228 FIXME( "not implemented\n" );
2234 /*********************************************************************
2237 INT CDECL
MSVCRT__isnan(double num
)
2239 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
2240 * Do the same, as the result may be used in calculations
2242 return isnan(num
) != 0;
2245 /*********************************************************************
2248 double CDECL
MSVCRT__j0(double num
)
2250 /* FIXME: errno handling */
2254 FIXME("not implemented\n");
2259 /*********************************************************************
2262 double CDECL
MSVCRT__j1(double num
)
2264 /* FIXME: errno handling */
2268 FIXME("not implemented\n");
2273 /*********************************************************************
2276 double CDECL
MSVCRT__jn(int n
, double num
)
2278 /* FIXME: errno handling */
2282 FIXME("not implemented\n");
2287 /*********************************************************************
2290 double CDECL
MSVCRT__y0(double num
)
2293 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2296 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2298 *MSVCRT__errno() = MSVCRT_EDOM
;
2302 FIXME("not implemented\n");
2308 /*********************************************************************
2311 double CDECL
MSVCRT__y1(double num
)
2314 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2317 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2319 *MSVCRT__errno() = MSVCRT_EDOM
;
2323 FIXME("not implemented\n");
2329 /*********************************************************************
2332 double CDECL
MSVCRT__yn(int order
, double num
)
2335 if (!isfinite(num
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2337 retval
= yn(order
,num
);
2338 if (MSVCRT__fpclass(retval
) == MSVCRT__FPCLASS_NINF
)
2340 *MSVCRT__errno() = MSVCRT_EDOM
;
2344 FIXME("not implemented\n");
2352 /*********************************************************************
2353 * _nearbyint (MSVCR120.@)
2355 double CDECL
MSVCRT_nearbyint(double num
)
2357 #ifdef HAVE_NEARBYINT
2358 return nearbyint(num
);
2360 return num
>= 0 ? floor(num
+ 0.5) : ceil(num
- 0.5);
2364 /*********************************************************************
2365 * _nearbyintf (MSVCR120.@)
2367 float CDECL
MSVCRT_nearbyintf(float num
)
2369 #ifdef HAVE_NEARBYINTF
2370 return nearbyintf(num
);
2372 return MSVCRT_nearbyint(num
);
2376 /*********************************************************************
2377 * nexttoward (MSVCR120.@)
2379 double CDECL
MSVCRT_nexttoward(double num
, double next
)
2381 #ifdef HAVE_NEXTTOWARD
2382 double ret
= nexttoward(num
, next
);
2383 if (!(MSVCRT__fpclass(ret
) & (MSVCRT__FPCLASS_PN
| MSVCRT__FPCLASS_NN
2384 | MSVCRT__FPCLASS_SNAN
| MSVCRT__FPCLASS_QNAN
)) && !isinf(num
))
2386 *MSVCRT__errno() = MSVCRT_ERANGE
;
2390 FIXME("not implemented\n");
2395 /*********************************************************************
2396 * nexttowardf (MSVCR120.@)
2398 float CDECL
MSVCRT_nexttowardf(float num
, double next
)
2400 #ifdef HAVE_NEXTTOWARDF
2401 float ret
= nexttowardf(num
, next
);
2402 if (!(MSVCRT__fpclass(ret
) & (MSVCRT__FPCLASS_PN
| MSVCRT__FPCLASS_NN
2403 | MSVCRT__FPCLASS_SNAN
| MSVCRT__FPCLASS_QNAN
)) && !isinf(num
))
2405 *MSVCRT__errno() = MSVCRT_ERANGE
;
2409 FIXME("not implemented\n");
2414 #endif /* _MSVCR_VER>=120 */
2416 /*********************************************************************
2417 * _nextafter (MSVCRT.@)
2419 double CDECL
MSVCRT__nextafter(double num
, double next
)
2422 if (!isfinite(num
) || !isfinite(next
)) *MSVCRT__errno() = MSVCRT_EDOM
;
2423 retval
= nextafter(num
,next
);
2427 /*********************************************************************
2430 char * CDECL
MSVCRT__ecvt( double number
, int ndigits
, int *decpt
, int *sign
)
2433 thread_data_t
*data
= msvcrt_get_thread_data();
2434 /* FIXME: check better for overflow (native supports over 300 chars) */
2435 ndigits
= min( ndigits
, 80 - 7); /* 7 : space for dec point, 1 for "e",
2436 * 4 for exponent and one for
2437 * terminating '\0' */
2438 if (!data
->efcvt_buffer
)
2439 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
2446 /* handle cases with zero ndigits or less */
2448 if( prec
< 1) prec
= 2;
2449 len
= MSVCRT__snprintf(data
->efcvt_buffer
, 80, "%.*le", prec
- 1, number
);
2450 /* take the decimal "point away */
2452 memmove( data
->efcvt_buffer
+ 1, data
->efcvt_buffer
+ 2, len
- 1 );
2453 /* take the exponential "e" out */
2454 data
->efcvt_buffer
[ prec
] = '\0';
2455 /* read the exponent */
2456 sscanf( data
->efcvt_buffer
+ prec
+ 1, "%d", decpt
);
2458 /* adjust for some border cases */
2459 if( data
->efcvt_buffer
[0] == '0')/* value is zero */
2461 /* handle cases with zero ndigits or less */
2463 if( data
->efcvt_buffer
[ 0] >= '5')
2465 data
->efcvt_buffer
[ 0] = '\0';
2467 TRACE("out=\"%s\"\n",data
->efcvt_buffer
);
2468 return data
->efcvt_buffer
;
2471 /*********************************************************************
2472 * _ecvt_s (MSVCRT.@)
2474 int CDECL
MSVCRT__ecvt_s( char *buffer
, MSVCRT_size_t length
, double number
, int ndigits
, int *decpt
, int *sign
)
2478 const char infret
[] = "1#INF";
2480 if (!MSVCRT_CHECK_PMT(buffer
!= NULL
)) return MSVCRT_EINVAL
;
2481 if (!MSVCRT_CHECK_PMT(decpt
!= NULL
)) return MSVCRT_EINVAL
;
2482 if (!MSVCRT_CHECK_PMT(sign
!= NULL
)) return MSVCRT_EINVAL
;
2483 if (!MSVCRT_CHECK_PMT_ERR( length
> 2, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
2484 if (!MSVCRT_CHECK_PMT_ERR(ndigits
< (int)length
- 1, MSVCRT_ERANGE
)) return MSVCRT_ERANGE
;
2486 /* special case - inf */
2487 if(number
== HUGE_VAL
|| number
== -HUGE_VAL
)
2489 memset(buffer
, '0', ndigits
);
2490 memcpy(buffer
, infret
, min(ndigits
, sizeof(infret
) - 1 ) );
2491 buffer
[ndigits
] = '\0';
2493 if(number
== -HUGE_VAL
)
2499 /* handle cases with zero ndigits or less */
2501 if( prec
< 1) prec
= 2;
2502 result
= MSVCRT_malloc(prec
+ 7);
2509 len
= MSVCRT__snprintf(result
, prec
+ 7, "%.*le", prec
- 1, number
);
2510 /* take the decimal "point away */
2512 memmove( result
+ 1, result
+ 2, len
- 1 );
2513 /* take the exponential "e" out */
2514 result
[ prec
] = '\0';
2515 /* read the exponent */
2516 sscanf( result
+ prec
+ 1, "%d", decpt
);
2518 /* adjust for some border cases */
2519 if( result
[0] == '0')/* value is zero */
2521 /* handle cases with zero ndigits or less */
2523 if( result
[ 0] >= '5')
2527 memcpy( buffer
, result
, max(ndigits
+ 1, 1) );
2528 MSVCRT_free( result
);
2532 /***********************************************************************
2535 char * CDECL
MSVCRT__fcvt( double number
, int ndigits
, int *decpt
, int *sign
)
2537 thread_data_t
*data
= msvcrt_get_thread_data();
2538 int stop
, dec1
, dec2
;
2539 char *ptr1
, *ptr2
, *first
;
2540 char buf
[80]; /* ought to be enough */
2541 char decimal_separator
= get_locinfo()->lconv
->decimal_point
[0];
2543 if (!data
->efcvt_buffer
)
2544 data
->efcvt_buffer
= MSVCRT_malloc( 80 ); /* ought to be enough */
2552 stop
= MSVCRT__snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
2554 ptr2
= data
->efcvt_buffer
;
2559 /* For numbers below the requested resolution, work out where
2560 the decimal point will be rather than finding it in the string */
2561 if (number
< 1.0 && number
> 0.0) {
2562 dec2
= log10(number
+ 1e-10);
2563 if (-dec2
<= ndigits
) dec2
= 0;
2566 /* If requested digits is zero or less, we will need to truncate
2567 * the returned string */
2572 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
2573 while (*ptr1
!= '\0' && *ptr1
!= decimal_separator
) {
2574 if (!first
) first
= ptr2
;
2575 if ((ptr1
- buf
) < stop
) {
2586 while (*ptr1
== '0') { /* Process leading zeroes */
2591 while (*ptr1
!= '\0') {
2592 if (!first
) first
= ptr2
;
2599 /* We never found a non-zero digit, then our number is either
2600 * smaller than the requested precision, or 0.0 */
2605 first
= data
->efcvt_buffer
;
2610 *decpt
= dec2
? dec2
: dec1
;
2614 /***********************************************************************
2615 * _fcvt_s (MSVCRT.@)
2617 int CDECL
MSVCRT__fcvt_s(char* outbuffer
, MSVCRT_size_t size
, double number
, int ndigits
, int *decpt
, int *sign
)
2619 int stop
, dec1
, dec2
;
2620 char *ptr1
, *ptr2
, *first
;
2621 char buf
[80]; /* ought to be enough */
2622 char decimal_separator
= get_locinfo()->lconv
->decimal_point
[0];
2624 if (!outbuffer
|| !decpt
|| !sign
|| size
== 0)
2626 *MSVCRT__errno() = MSVCRT_EINVAL
;
2627 return MSVCRT_EINVAL
;
2636 stop
= MSVCRT__snprintf(buf
, 80, "%.*f", ndigits
< 0 ? 0 : ndigits
, number
);
2643 /* For numbers below the requested resolution, work out where
2644 the decimal point will be rather than finding it in the string */
2645 if (number
< 1.0 && number
> 0.0) {
2646 dec2
= log10(number
+ 1e-10);
2647 if (-dec2
<= ndigits
) dec2
= 0;
2650 /* If requested digits is zero or less, we will need to truncate
2651 * the returned string */
2656 while (*ptr1
== '0') ptr1
++; /* Skip leading zeroes */
2657 while (*ptr1
!= '\0' && *ptr1
!= decimal_separator
) {
2658 if (!first
) first
= ptr2
;
2659 if ((ptr1
- buf
) < stop
) {
2673 while (*ptr1
== '0') { /* Process leading zeroes */
2674 if (number
== 0.0 && size
> 1) {
2682 while (*ptr1
!= '\0') {
2683 if (!first
) first
= ptr2
;
2693 /* We never found a non-zero digit, then our number is either
2694 * smaller than the requested precision, or 0.0 */
2695 if (!first
&& (number
<= 0.0))
2698 *decpt
= dec2
? dec2
: dec1
;
2702 /***********************************************************************
2705 char * CDECL
MSVCRT__gcvt( double number
, int ndigit
, char *buff
)
2708 *MSVCRT__errno() = MSVCRT_EINVAL
;
2713 *MSVCRT__errno() = MSVCRT_ERANGE
;
2717 MSVCRT_sprintf(buff
, "%.*g", ndigit
, number
);
2721 /***********************************************************************
2722 * _gcvt_s (MSVCRT.@)
2724 int CDECL
MSVCRT__gcvt_s(char *buff
, MSVCRT_size_t size
, double number
, int digits
)
2729 *MSVCRT__errno() = MSVCRT_EINVAL
;
2730 return MSVCRT_EINVAL
;
2733 if( digits
<0 || digits
>=size
) {
2737 *MSVCRT__errno() = MSVCRT_ERANGE
;
2738 return MSVCRT_ERANGE
;
2741 len
= MSVCRT__scprintf("%.*g", digits
, number
);
2744 *MSVCRT__errno() = MSVCRT_ERANGE
;
2745 return MSVCRT_ERANGE
;
2748 MSVCRT_sprintf(buff
, "%.*g", digits
, number
);
2752 #include <stdlib.h> /* div_t, ldiv_t */
2754 /*********************************************************************
2757 * [i386] Windows binary compatible - returns the struct in eax/edx.
2760 unsigned __int64 CDECL
MSVCRT_div(int num
, int denom
)
2764 unsigned __int64 uint64
;
2767 ret
.div
.quot
= num
/ denom
;
2768 ret
.div
.rem
= num
% denom
;
2772 /*********************************************************************
2775 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
2777 MSVCRT_div_t CDECL
MSVCRT_div(int num
, int denom
)
2781 ret
.quot
= num
/ denom
;
2782 ret
.rem
= num
% denom
;
2785 #endif /* ifdef __i386__ */
2788 /*********************************************************************
2791 * [i386] Windows binary compatible - returns the struct in eax/edx.
2794 unsigned __int64 CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
2798 unsigned __int64 uint64
;
2801 ret
.ldiv
.quot
= num
/ denom
;
2802 ret
.ldiv
.rem
= num
% denom
;
2806 /*********************************************************************
2809 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
2811 MSVCRT_ldiv_t CDECL
MSVCRT_ldiv(MSVCRT_long num
, MSVCRT_long denom
)
2815 ret
.quot
= num
/ denom
;
2816 ret
.rem
= num
% denom
;
2819 #endif /* ifdef __i386__ */
2822 /*********************************************************************
2823 * lldiv (MSVCR100.@)
2825 MSVCRT_lldiv_t CDECL
MSVCRT_lldiv(MSVCRT_longlong num
, MSVCRT_longlong denom
)
2829 ret
.quot
= num
/ denom
;
2830 ret
.rem
= num
% denom
;
2838 /*********************************************************************
2839 * _adjust_fdiv (MSVCRT.@)
2840 * Used by the MSVC compiler to work around the Pentium FDIV bug.
2842 int MSVCRT__adjust_fdiv
= 0;
2844 /***********************************************************************
2845 * _adj_fdiv_m16i (MSVCRT.@)
2848 * I _think_ this function is intended to work around the Pentium
2851 void __stdcall
_adj_fdiv_m16i( short arg
)
2853 TRACE("(): stub\n");
2856 /***********************************************************************
2857 * _adj_fdiv_m32 (MSVCRT.@)
2860 * I _think_ this function is intended to work around the Pentium
2863 void __stdcall
_adj_fdiv_m32( unsigned int arg
)
2865 TRACE("(): stub\n");
2868 /***********************************************************************
2869 * _adj_fdiv_m32i (MSVCRT.@)
2872 * I _think_ this function is intended to work around the Pentium
2875 void __stdcall
_adj_fdiv_m32i( int arg
)
2877 TRACE("(): stub\n");
2880 /***********************************************************************
2881 * _adj_fdiv_m64 (MSVCRT.@)
2884 * I _think_ this function is intended to work around the Pentium
2887 void __stdcall
_adj_fdiv_m64( unsigned __int64 arg
)
2889 TRACE("(): stub\n");
2892 /***********************************************************************
2893 * _adj_fdiv_r (MSVCRT.@)
2895 * This function is likely to have the wrong number of arguments.
2898 * I _think_ this function is intended to work around the Pentium
2901 void _adj_fdiv_r(void)
2903 TRACE("(): stub\n");
2906 /***********************************************************************
2907 * _adj_fdivr_m16i (MSVCRT.@)
2910 * I _think_ this function is intended to work around the Pentium
2913 void __stdcall
_adj_fdivr_m16i( short arg
)
2915 TRACE("(): stub\n");
2918 /***********************************************************************
2919 * _adj_fdivr_m32 (MSVCRT.@)
2922 * I _think_ this function is intended to work around the Pentium
2925 void __stdcall
_adj_fdivr_m32( unsigned int arg
)
2927 TRACE("(): stub\n");
2930 /***********************************************************************
2931 * _adj_fdivr_m32i (MSVCRT.@)
2934 * I _think_ this function is intended to work around the Pentium
2937 void __stdcall
_adj_fdivr_m32i( int arg
)
2939 TRACE("(): stub\n");
2942 /***********************************************************************
2943 * _adj_fdivr_m64 (MSVCRT.@)
2946 * I _think_ this function is intended to work around the Pentium
2949 void __stdcall
_adj_fdivr_m64( unsigned __int64 arg
)
2951 TRACE("(): stub\n");
2954 /***********************************************************************
2955 * _adj_fpatan (MSVCRT.@)
2957 * This function is likely to have the wrong number of arguments.
2960 * I _think_ this function is intended to work around the Pentium
2963 void _adj_fpatan(void)
2965 TRACE("(): stub\n");
2968 /***********************************************************************
2969 * _adj_fprem (MSVCRT.@)
2971 * This function is likely to have the wrong number of arguments.
2974 * I _think_ this function is intended to work around the Pentium
2977 void _adj_fprem(void)
2979 TRACE("(): stub\n");
2982 /***********************************************************************
2983 * _adj_fprem1 (MSVCRT.@)
2985 * This function is likely to have the wrong number of arguments.
2988 * I _think_ this function is intended to work around the Pentium
2991 void _adj_fprem1(void)
2993 TRACE("(): stub\n");
2996 /***********************************************************************
2997 * _adj_fptan (MSVCRT.@)
2999 * This function is likely to have the wrong number of arguments.
3002 * I _think_ this function is intended to work around the Pentium
3005 void _adj_fptan(void)
3007 TRACE("(): stub\n");
3010 /***********************************************************************
3011 * _safe_fdiv (MSVCRT.@)
3013 * This function is likely to have the wrong number of arguments.
3016 * I _think_ this function is intended to work around the Pentium
3019 void _safe_fdiv(void)
3021 TRACE("(): stub\n");
3024 /***********************************************************************
3025 * _safe_fdivr (MSVCRT.@)
3027 * This function is likely to have the wrong number of arguments.
3030 * I _think_ this function is intended to work around the Pentium
3033 void _safe_fdivr(void)
3035 TRACE("(): stub\n");
3038 /***********************************************************************
3039 * _safe_fprem (MSVCRT.@)
3041 * This function is likely to have the wrong number of arguments.
3044 * I _think_ this function is intended to work around the Pentium
3047 void _safe_fprem(void)
3049 TRACE("(): stub\n");
3052 /***********************************************************************
3053 * _safe_fprem1 (MSVCRT.@)
3056 * This function is likely to have the wrong number of arguments.
3059 * I _think_ this function is intended to work around the Pentium
3062 void _safe_fprem1(void)
3064 TRACE("(): stub\n");
3067 /***********************************************************************
3068 * __libm_sse2_acos (MSVCRT.@)
3070 void __cdecl
MSVCRT___libm_sse2_acos(void)
3073 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3075 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3078 /***********************************************************************
3079 * __libm_sse2_acosf (MSVCRT.@)
3081 void __cdecl
MSVCRT___libm_sse2_acosf(void)
3084 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3086 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3089 /***********************************************************************
3090 * __libm_sse2_asin (MSVCRT.@)
3092 void __cdecl
MSVCRT___libm_sse2_asin(void)
3095 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3097 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3100 /***********************************************************************
3101 * __libm_sse2_asinf (MSVCRT.@)
3103 void __cdecl
MSVCRT___libm_sse2_asinf(void)
3106 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3108 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3111 /***********************************************************************
3112 * __libm_sse2_atan (MSVCRT.@)
3114 void __cdecl
MSVCRT___libm_sse2_atan(void)
3117 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3119 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3122 /***********************************************************************
3123 * __libm_sse2_atan2 (MSVCRT.@)
3125 void __cdecl
MSVCRT___libm_sse2_atan2(void)
3128 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
3129 d1
= atan2( d1
, d2
);
3130 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
3133 /***********************************************************************
3134 * __libm_sse2_atanf (MSVCRT.@)
3136 void __cdecl
MSVCRT___libm_sse2_atanf(void)
3139 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3141 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3144 /***********************************************************************
3145 * __libm_sse2_cos (MSVCRT.@)
3147 void __cdecl
MSVCRT___libm_sse2_cos(void)
3150 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3152 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3155 /***********************************************************************
3156 * __libm_sse2_cosf (MSVCRT.@)
3158 void __cdecl
MSVCRT___libm_sse2_cosf(void)
3161 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3163 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3166 /***********************************************************************
3167 * __libm_sse2_exp (MSVCRT.@)
3169 void __cdecl
MSVCRT___libm_sse2_exp(void)
3172 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3174 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3177 /***********************************************************************
3178 * __libm_sse2_expf (MSVCRT.@)
3180 void __cdecl
MSVCRT___libm_sse2_expf(void)
3183 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3185 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3188 /***********************************************************************
3189 * __libm_sse2_log (MSVCRT.@)
3191 void __cdecl
MSVCRT___libm_sse2_log(void)
3194 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3196 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3199 /***********************************************************************
3200 * __libm_sse2_log10 (MSVCRT.@)
3202 void __cdecl
MSVCRT___libm_sse2_log10(void)
3205 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3207 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3210 /***********************************************************************
3211 * __libm_sse2_log10f (MSVCRT.@)
3213 void __cdecl
MSVCRT___libm_sse2_log10f(void)
3216 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3218 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3221 /***********************************************************************
3222 * __libm_sse2_logf (MSVCRT.@)
3224 void __cdecl
MSVCRT___libm_sse2_logf(void)
3227 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3229 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3232 /***********************************************************************
3233 * __libm_sse2_pow (MSVCRT.@)
3235 void __cdecl
MSVCRT___libm_sse2_pow(void)
3238 __asm__
__volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1
), "=m" (d2
) );
3240 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d1
) );
3243 /***********************************************************************
3244 * __libm_sse2_powf (MSVCRT.@)
3246 void __cdecl
MSVCRT___libm_sse2_powf(void)
3249 __asm__
__volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1
), "=g" (f2
) );
3250 f1
= powf( f1
, f2
);
3251 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f1
) );
3254 /***********************************************************************
3255 * __libm_sse2_sin (MSVCRT.@)
3257 void __cdecl
MSVCRT___libm_sse2_sin(void)
3260 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3262 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3265 /***********************************************************************
3266 * __libm_sse2_sinf (MSVCRT.@)
3268 void __cdecl
MSVCRT___libm_sse2_sinf(void)
3271 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3273 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3276 /***********************************************************************
3277 * __libm_sse2_tan (MSVCRT.@)
3279 void __cdecl
MSVCRT___libm_sse2_tan(void)
3282 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3284 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3287 /***********************************************************************
3288 * __libm_sse2_tanf (MSVCRT.@)
3290 void __cdecl
MSVCRT___libm_sse2_tanf(void)
3293 __asm__
__volatile__( "movd %%xmm0,%0" : "=g" (f
) );
3295 __asm__
__volatile__( "movd %0,%%xmm0" : : "g" (f
) );
3298 /***********************************************************************
3299 * __libm_sse2_sqrt_precise (MSVCR110.@)
3301 void __cdecl
MSVCRT___libm_sse2_sqrt_precise(void)
3304 __asm__
__volatile__( "movq %%xmm0,%0" : "=m" (d
) );
3306 __asm__
__volatile__( "movq %0,%%xmm0" : : "m" (d
) );
3309 #endif /* __i386__ */
3311 /*********************************************************************
3314 double CDECL
MSVCR120_cbrt(double x
)
3319 return x
< 0 ? -pow(-x
, 1.0 / 3.0) : pow(x
, 1.0 / 3.0);
3323 /*********************************************************************
3324 * cbrtf (MSVCR120.@)
3326 float CDECL
MSVCR120_cbrtf(float x
)
3331 return MSVCR120_cbrt(x
);
3335 /*********************************************************************
3336 * cbrtl (MSVCR120.@)
3338 LDOUBLE CDECL
MSVCR120_cbrtl(LDOUBLE x
)
3340 return MSVCR120_cbrt(x
);
3343 /*********************************************************************
3346 double CDECL
MSVCR120_exp2(double x
)
3349 double ret
= exp2(x
);
3351 double ret
= pow(2, x
);
3353 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3357 /*********************************************************************
3358 * exp2f (MSVCR120.@)
3360 float CDECL
MSVCR120_exp2f(float x
)
3363 float ret
= exp2f(x
);
3364 if (finitef(x
) && !finitef(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3367 return MSVCR120_exp2(x
);
3371 /*********************************************************************
3372 * exp2l (MSVCR120.@)
3374 LDOUBLE CDECL
MSVCR120_exp2l(LDOUBLE x
)
3376 return MSVCR120_exp2(x
);
3379 /*********************************************************************
3380 * expm1 (MSVCR120.@)
3382 double CDECL
MSVCR120_expm1(double x
)
3385 double ret
= expm1(x
);
3387 double ret
= exp(x
) - 1;
3389 if (isfinite(x
) && !isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3393 /*********************************************************************
3394 * expm1f (MSVCR120.@)
3396 float CDECL
MSVCR120_expm1f(float x
)
3399 float ret
= expm1f(x
);
3401 float ret
= exp(x
) - 1;
3403 if (finitef(x
) && !finitef(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
3407 /*********************************************************************
3408 * expm1l (MSVCR120.@)
3410 LDOUBLE CDECL
MSVCR120_expm1l(LDOUBLE x
)
3412 return MSVCR120_expm1(x
);
3415 /*********************************************************************
3416 * log1p (MSVCR120.@)
3418 double CDECL
MSVCR120_log1p(double x
)
3420 if (x
< -1) *MSVCRT__errno() = MSVCRT_EDOM
;
3421 else if (x
== -1) *MSVCRT__errno() = MSVCRT_ERANGE
;
3429 /*********************************************************************
3430 * log1pf (MSVCR120.@)
3432 float CDECL
MSVCR120_log1pf(float x
)
3434 if (x
< -1) *MSVCRT__errno() = MSVCRT_EDOM
;
3435 else if (x
== -1) *MSVCRT__errno() = MSVCRT_ERANGE
;
3443 /*********************************************************************
3444 * log1pl (MSVCR120.@)
3446 LDOUBLE CDECL
MSVCR120_log1pl(LDOUBLE x
)
3448 return MSVCR120_log1p(x
);
3451 /*********************************************************************
3454 double CDECL
MSVCR120_log2(double x
)
3456 if (x
< 0) *MSVCRT__errno() = MSVCRT_EDOM
;
3457 else if (x
== 0) *MSVCRT__errno() = MSVCRT_ERANGE
;
3461 return log(x
) / log(2);
3465 /*********************************************************************
3466 * log2f (MSVCR120.@)
3468 float CDECL
MSVCR120_log2f(float x
)
3471 if (x
< 0) *MSVCRT__errno() = MSVCRT_EDOM
;
3472 else if (x
== 0) *MSVCRT__errno() = MSVCRT_ERANGE
;
3475 return MSVCR120_log2(x
);
3479 /*********************************************************************
3480 * log2l (MSVCR120.@)
3482 LDOUBLE CDECL
MSVCR120_log2l(LDOUBLE x
)
3484 return MSVCR120_log2(x
);
3487 /*********************************************************************
3490 double CDECL
MSVCR120_rint(double x
)
3495 /*********************************************************************
3496 * rintf (MSVCR120.@)
3498 float CDECL
MSVCR120_rintf(float x
)
3503 /*********************************************************************
3504 * rintl (MSVCR120.@)
3506 LDOUBLE CDECL
MSVCR120_rintl(LDOUBLE x
)
3508 return MSVCR120_rint(x
);
3511 /*********************************************************************
3512 * lrint (MSVCR120.@)
3514 MSVCRT_long CDECL
MSVCR120_lrint(double x
)
3519 /*********************************************************************
3520 * lrintf (MSVCR120.@)
3522 MSVCRT_long CDECL
MSVCR120_lrintf(float x
)
3527 /*********************************************************************
3528 * lrintl (MSVCR120.@)
3530 MSVCRT_long CDECL
MSVCR120_lrintl(LDOUBLE x
)
3532 return MSVCR120_lrint(x
);
3535 /*********************************************************************
3536 * llrint (MSVCR120.@)
3538 MSVCRT_longlong CDECL
MSVCR120_llrint(double x
)
3543 /*********************************************************************
3544 * llrintf (MSVCR120.@)
3546 MSVCRT_longlong CDECL
MSVCR120_llrintf(float x
)
3551 /*********************************************************************
3552 * rintl (MSVCR120.@)
3554 MSVCRT_longlong CDECL
MSVCR120_llrintl(LDOUBLE x
)
3556 return MSVCR120_llrint(x
);
3561 /*********************************************************************
3562 * round (MSVCR120.@)
3564 double CDECL
MSVCR120_round(double x
)
3569 return MSVCR120_rint(x
);
3573 /*********************************************************************
3574 * roundf (MSVCR120.@)
3576 float CDECL
MSVCR120_roundf(float x
)
3581 return MSVCR120_round(x
);
3585 /*********************************************************************
3586 * roundl (MSVCR120.@)
3588 LDOUBLE CDECL
MSVCR120_roundl(LDOUBLE x
)
3590 return MSVCR120_round(x
);
3593 /*********************************************************************
3594 * lround (MSVCR120.@)
3596 MSVCRT_long CDECL
MSVCR120_lround(double x
)
3601 return MSVCR120_round(x
);
3605 /*********************************************************************
3606 * lroundf (MSVCR120.@)
3608 MSVCRT_long CDECL
MSVCR120_lroundf(float x
)
3613 return MSVCR120_lround(x
);
3617 /*********************************************************************
3618 * lroundl (MSVCR120.@)
3620 MSVCRT_long CDECL
MSVCR120_lroundl(LDOUBLE x
)
3622 return MSVCR120_lround(x
);
3625 /*********************************************************************
3626 * llround (MSVCR120.@)
3628 MSVCRT_longlong CDECL
MSVCR120_llround(double x
)
3633 return MSVCR120_round(x
);
3637 /*********************************************************************
3638 * llroundf (MSVCR120.@)
3640 MSVCRT_longlong CDECL
MSVCR120_llroundf(float x
)
3642 #ifdef HAVE_LLROUNDF
3645 return MSVCR120_llround(x
);
3649 /*********************************************************************
3650 * roundl (MSVCR120.@)
3652 MSVCRT_longlong CDECL
MSVCR120_llroundl(LDOUBLE x
)
3654 return MSVCR120_llround(x
);
3657 /*********************************************************************
3658 * trunc (MSVCR120.@)
3660 double CDECL
MSVCR120_trunc(double x
)
3665 return (x
> 0) ? floor(x
) : ceil(x
);
3669 /*********************************************************************
3670 * truncf (MSVCR120.@)
3672 float CDECL
MSVCR120_truncf(float x
)
3677 return MSVCR120_trunc(x
);
3681 /*********************************************************************
3682 * truncl (MSVCR120.@)
3684 LDOUBLE CDECL
MSVCR120_truncl(LDOUBLE x
)
3686 return MSVCR120_trunc(x
);
3689 /*********************************************************************
3690 * _dclass (MSVCR120.@)
3692 * Copied from musl: src/math/__fpclassify.c
3694 short CDECL
MSVCR120__dclass(double x
)
3696 union { double f
; UINT64 i
; } u
= { x
};
3697 int e
= u
.i
>> 52 & 0x7ff;
3699 if (!e
) return u
.i
<< 1 ? MSVCRT_FP_SUBNORMAL
: MSVCRT_FP_ZERO
;
3700 if (e
== 0x7ff) return (u
.i
<< 12) ? MSVCRT_FP_NAN
: MSVCRT_FP_INFINITE
;
3701 return MSVCRT_FP_NORMAL
;
3704 /*********************************************************************
3705 * _fdclass (MSVCR120.@)
3707 * Copied from musl: src/math/__fpclassifyf.c
3709 short CDECL
MSVCR120__fdclass(float x
)
3711 union { float f
; UINT32 i
; } u
= { x
};
3712 int e
= u
.i
>> 23 & 0xff;
3714 if (!e
) return u
.i
<< 1 ? MSVCRT_FP_SUBNORMAL
: MSVCRT_FP_ZERO
;
3715 if (e
== 0xff) return u
.i
<< 9 ? MSVCRT_FP_NAN
: MSVCRT_FP_INFINITE
;
3716 return MSVCRT_FP_NORMAL
;
3719 /*********************************************************************
3720 * _ldclass (MSVCR120.@)
3722 short CDECL
MSVCR120__ldclass(LDOUBLE x
)
3724 return MSVCR120__dclass(x
);
3727 /*********************************************************************
3728 * _dtest (MSVCR120.@)
3730 short CDECL
MSVCR120__dtest(double *x
)
3732 return MSVCR120__dclass(*x
);
3735 /*********************************************************************
3736 * _fdtest (MSVCR120.@)
3738 short CDECL
MSVCR120__fdtest(float *x
)
3740 return MSVCR120__fdclass(*x
);
3743 /*********************************************************************
3744 * _ldtest (MSVCR120.@)
3746 short CDECL
MSVCR120__ldtest(LDOUBLE
*x
)
3748 return MSVCR120__dclass(*x
);
3751 /*********************************************************************
3754 double CDECL
MSVCR120_erf(double x
)
3759 /* Abramowitz and Stegun approximation, maximum error: 1.5*10^-7 */
3761 int sign
= signbit(x
);
3764 t
= 1 / (1 + 0.3275911 * x
);
3765 y
= ((((1.061405429*t
- 1.453152027)*t
+ 1.421413741)*t
- 0.284496736)*t
+ 0.254829592)*t
;
3766 y
= 1.0 - y
*exp(-x
*x
);
3767 return sign
? -y
: y
;
3771 /*********************************************************************
3774 float CDECL
MSVCR120_erff(float x
)
3779 return MSVCR120_erf(x
);
3783 /*********************************************************************
3786 LDOUBLE CDECL
MSVCR120_erfl(LDOUBLE x
)
3788 return MSVCR120_erf(x
);
3791 /*********************************************************************
3794 double CDECL
MSVCR120_erfc(double x
)
3799 return 1 - MSVCR120_erf(x
);
3803 /*********************************************************************
3804 * erfcf (MSVCR120.@)
3806 float CDECL
MSVCR120_erfcf(float x
)
3811 return MSVCR120_erfc(x
);
3815 /*********************************************************************
3816 * erfcl (MSVCR120.@)
3818 LDOUBLE CDECL
MSVCR120_erfcl(LDOUBLE x
)
3820 return MSVCR120_erfc(x
);
3823 /*********************************************************************
3824 * fmaxf (MSVCR120.@)
3826 float CDECL
MSVCR120_fmaxf(float x
, float y
)
3833 return signbit(x
) ? y
: x
;
3837 /*********************************************************************
3840 double CDECL
MSVCR120_fmax(double x
, double y
)
3847 return signbit(x
) ? y
: x
;
3851 /*********************************************************************
3852 * fdimf (MSVCR120.@)
3854 float CDECL
MSVCR120_fdimf(float x
, float y
)
3860 return x
>y
? x
-y
: 0;
3863 /*********************************************************************
3866 double CDECL
MSVCR120_fdim(double x
, double y
)
3872 return x
>y
? x
-y
: 0;
3875 /*********************************************************************
3876 * _fdsign (MSVCR120.@)
3878 int CDECL
MSVCR120__fdsign(float x
)
3880 return signbit(x
) ? 0x8000 : 0;
3883 /*********************************************************************
3884 * _dsign (MSVCR120.@)
3886 int CDECL
MSVCR120__dsign(double x
)
3888 return signbit(x
) ? 0x8000 : 0;
3892 /*********************************************************************
3893 * _dpcomp (MSVCR120.@)
3895 int CDECL
MSVCR120__dpcomp(double x
, double y
)
3897 if(isnan(x
) || isnan(y
))
3900 if(x
== y
) return 2;
3901 return x
< y
? 1 : 4;
3904 /*********************************************************************
3905 * _fdpcomp (MSVCR120.@)
3907 int CDECL
MSVCR120__fdpcomp(float x
, float y
)
3909 return MSVCR120__dpcomp(x
, y
);
3912 /*********************************************************************
3913 * fminf (MSVCR120.@)
3915 float CDECL
MSVCR120_fminf(float x
, float y
)
3922 return signbit(x
) ? x
: y
;
3926 /*********************************************************************
3929 double CDECL
MSVCR120_fmin(double x
, double y
)
3936 return signbit(x
) ? x
: y
;
3940 /*********************************************************************
3941 * asinh (MSVCR120.@)
3943 double CDECL
MSVCR120_asinh(double x
)
3948 if (!isfinite(x
*x
+1)) {
3949 if (x
> 0) return log(2) + log(x
);
3950 else return -log(2) - log(-x
);
3952 return log(x
+ sqrt(x
*x
+1));
3956 /*********************************************************************
3957 * asinhf (MSVCR120.@)
3959 float CDECL
MSVCR120_asinhf(float x
)
3964 return MSVCR120_asinh(x
);
3968 /*********************************************************************
3969 * asinhl (MSVCR120.@)
3971 LDOUBLE CDECL
MSVCR120_asinhl(LDOUBLE x
)
3973 return MSVCR120_asinh(x
);
3976 /*********************************************************************
3977 * acosh (MSVCR120.@)
3979 double CDECL
MSVCR120_acosh(double x
)
3981 if (x
< 1) *MSVCRT__errno() = MSVCRT_EDOM
;
3989 MSVCRT_fegetenv(&env
);
3990 env
.status
|= MSVCRT__SW_INVALID
;
3991 MSVCRT_fesetenv(&env
);
3994 if (!isfinite(x
*x
)) return log(2) + log(x
);
3995 return log(x
+ sqrt(x
*x
-1));
3999 /*********************************************************************
4000 * acoshf (MSVCR120.@)
4002 float CDECL
MSVCR120_acoshf(float x
)
4005 if (x
< 1) *MSVCRT__errno() = MSVCRT_EDOM
;
4009 return MSVCR120_acosh(x
);
4013 /*********************************************************************
4014 * acoshl (MSVCR120.@)
4016 LDOUBLE CDECL
MSVCR120_acoshl(LDOUBLE x
)
4018 return MSVCR120_acosh(x
);
4021 /*********************************************************************
4022 * atanh (MSVCR120.@)
4024 double CDECL
MSVCR120_atanh(double x
)
4028 if (x
> 1 || x
< -1) {
4031 *MSVCRT__errno() = MSVCRT_EDOM
;
4033 /* on Linux atanh returns -NAN in this case */
4034 MSVCRT_fegetenv(&env
);
4035 env
.status
|= MSVCRT__SW_INVALID
;
4036 MSVCRT_fesetenv(&env
);
4043 if (-1e-6 < x
&& x
< 1e-6) ret
= x
+ x
*x
*x
/3;
4044 else ret
= (log(1+x
) - log(1-x
)) / 2;
4047 if (!isfinite(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
4051 /*********************************************************************
4052 * atanhf (MSVCR120.@)
4054 float CDECL
MSVCR120_atanhf(float x
)
4059 if (x
> 1 || x
< -1) {
4062 *MSVCRT__errno() = MSVCRT_EDOM
;
4064 MSVCRT_fegetenv(&env
);
4065 env
.status
|= MSVCRT__SW_INVALID
;
4066 MSVCRT_fesetenv(&env
);
4072 if (!finitef(ret
)) *MSVCRT__errno() = MSVCRT_ERANGE
;
4075 return MSVCR120_atanh(x
);
4079 /*********************************************************************
4080 * atanhl (MSVCR120.@)
4082 LDOUBLE CDECL
MSVCR120_atanhl(LDOUBLE x
)
4084 return MSVCR120_atanh(x
);
4087 #endif /* _MSVCR_VER>=120 */
4089 /*********************************************************************
4091 * scalbn (MSVCR120.@)
4092 * scalbln (MSVCR120.@)
4094 double CDECL
MSVCRT__scalb(double num
, MSVCRT_long power
)
4096 return MSVCRT_ldexp(num
, power
);
4099 /*********************************************************************
4100 * _scalbf (MSVCRT.@)
4101 * scalbnf (MSVCR120.@)
4102 * scalblnf (MSVCR120.@)
4104 float CDECL
MSVCRT__scalbf(float num
, MSVCRT_long power
)
4106 return MSVCRT_ldexp(num
, power
);
4111 /*********************************************************************
4112 * scalbnl (MSVCR120.@)
4113 * scalblnl (MSVCR120.@)
4115 LDOUBLE CDECL
MSVCR120_scalbnl(LDOUBLE num
, MSVCRT_long power
)
4117 return MSVCRT__scalb(num
, power
);
4120 /*********************************************************************
4121 * remainder (MSVCR120.@)
4123 double CDECL
MSVCR120_remainder(double x
, double y
)
4125 #ifdef HAVE_REMAINDER
4126 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
4127 if(!finite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4128 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
4129 return remainder(x
, y
);
4131 FIXME( "not implemented\n" );
4136 /*********************************************************************
4137 * remainderf (MSVCR120.@)
4139 float CDECL
MSVCR120_remainderf(float x
, float y
)
4141 #ifdef HAVE_REMAINDERF
4142 /* this matches 64-bit Windows. 32-bit Windows is slightly different */
4143 if(!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4144 if(isnan(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
4145 return remainderf(x
, y
);
4147 FIXME( "not implemented\n" );
4152 /*********************************************************************
4153 * remainderl (MSVCR120.@)
4155 LDOUBLE CDECL
MSVCR120_remainderl(LDOUBLE x
, LDOUBLE y
)
4157 return MSVCR120_remainder(x
, y
);
4160 /*********************************************************************
4161 * remquo (MSVCR120.@)
4163 double CDECL
MSVCR120_remquo(double x
, double y
, int *quo
)
4166 if(!finite(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4167 if(isnan(y
) || y
==0.0) *MSVCRT__errno() = MSVCRT_EDOM
;
4168 return remquo(x
, y
, quo
);
4170 FIXME( "not implemented\n" );
4175 /*********************************************************************
4176 * remquof (MSVCR120.@)
4178 float CDECL
MSVCR120_remquof(float x
, float y
, int *quo
)
4181 if(!finitef(x
)) *MSVCRT__errno() = MSVCRT_EDOM
;
4182 if(isnan(y
) || y
==0.0f
) *MSVCRT__errno() = MSVCRT_EDOM
;
4183 return remquof(x
, y
, quo
);
4185 FIXME( "not implemented\n" );
4190 /*********************************************************************
4191 * remquol (MSVCR120.@)
4193 LDOUBLE CDECL
MSVCR120_remquol(LDOUBLE x
, LDOUBLE y
, int *quo
)
4195 return MSVCR120_remquo(x
, y
, quo
);
4198 /*********************************************************************
4199 * lgamma (MSVCR120.@)
4201 double CDECL
MSVCR120_lgamma(double x
)
4206 FIXME( "not implemented\n" );
4211 /*********************************************************************
4212 * lgammaf (MSVCR120.@)
4214 float CDECL
MSVCR120_lgammaf(float x
)
4219 FIXME( "not implemented\n" );
4224 /*********************************************************************
4225 * lgammal (MSVCR120.@)
4227 LDOUBLE CDECL
MSVCR120_lgammal(LDOUBLE x
)
4229 return MSVCR120_lgamma(x
);
4232 /*********************************************************************
4233 * tgamma (MSVCR120.@)
4235 double CDECL
MSVCR120_tgamma(double x
)
4238 if(x
==0.0) *MSVCRT__errno() = MSVCRT_ERANGE
;
4241 if (modf(x
, &integral
) == 0)
4242 *MSVCRT__errno() = MSVCRT_EDOM
;
4246 FIXME( "not implemented\n" );
4251 /*********************************************************************
4252 * tgammaf (MSVCR120.@)
4254 float CDECL
MSVCR120_tgammaf(float x
)
4257 if(x
==0.0f
) *MSVCRT__errno() = MSVCRT_ERANGE
;
4260 if (modff(x
, &integral
) == 0)
4261 *MSVCRT__errno() = MSVCRT_EDOM
;
4265 FIXME( "not implemented\n" );
4270 /*********************************************************************
4273 double CDECL
MSVCR120_nan(const char *tagp
)
4275 /* Windows ignores input (MSDN) */
4279 /*********************************************************************
4282 float CDECL
MSVCR120_nanf(const char *tagp
)
4287 /*********************************************************************
4288 * _except1 (MSVCR120.@)
4290 * - find meaning of ignored cw and operation bits
4293 double CDECL
_except1(DWORD fpe
, _FP_OPERATION_CODE op
, double arg
, double res
, DWORD cw
, void *unk
)
4295 ULONG_PTR exception_arg
;
4296 DWORD exception
= 0;
4301 TRACE("(%x %x %lf %lf %x %p)\n", fpe
, op
, arg
, res
, cw
, unk
);
4304 cw
= ((cw
>> 7) & 0x3f) | ((cw
>> 3) & 0xc00);
4306 operation
= op
<< 5;
4307 exception_arg
= (ULONG_PTR
)&operation
;
4309 MSVCRT_fegetenv(&env
);
4311 if (fpe
& 0x1) { /* overflow */
4312 if ((fpe
== 0x1 && (cw
& 0x8)) || (fpe
==0x11 && (cw
& 0x28))) {
4313 /* 32-bit version also sets SW_INEXACT here */
4314 env
.status
|= MSVCRT__SW_OVERFLOW
;
4315 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4316 res
= signbit(res
) ? -INFINITY
: INFINITY
;
4318 exception
= EXCEPTION_FLT_OVERFLOW
;
4320 } else if (fpe
& 0x2) { /* underflow */
4321 if ((fpe
== 0x2 && (cw
& 0x10)) || (fpe
==0x12 && (cw
& 0x30))) {
4322 env
.status
|= MSVCRT__SW_UNDERFLOW
;
4323 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4324 res
= signbit(res
) ? -0.0 : 0.0;
4326 exception
= EXCEPTION_FLT_UNDERFLOW
;
4328 } else if (fpe
& 0x4) { /* zerodivide */
4329 if ((fpe
== 0x4 && (cw
& 0x4)) || (fpe
==0x14 && (cw
& 0x24))) {
4330 env
.status
|= MSVCRT__SW_ZERODIVIDE
;
4331 if (fpe
& 0x10) env
.status
|= MSVCRT__SW_INEXACT
;
4333 exception
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
4335 } else if (fpe
& 0x8) { /* invalid */
4336 if (fpe
== 0x8 && (cw
& 0x1)) {
4337 env
.status
|= MSVCRT__SW_INVALID
;
4339 exception
= EXCEPTION_FLT_INVALID_OPERATION
;
4341 } else if (fpe
& 0x10) { /* inexact */
4342 if (fpe
== 0x10 && (cw
& 0x20)) {
4343 env
.status
|= MSVCRT__SW_INEXACT
;
4345 exception
= EXCEPTION_FLT_INEXACT_RESULT
;
4351 MSVCRT_fesetenv(&env
);
4353 RaiseException(exception
, 0, 1, &exception_arg
);
4355 if (cw
& 0x1) fpword
|= MSVCRT__EM_INVALID
;
4356 if (cw
& 0x2) fpword
|= MSVCRT__EM_DENORMAL
;
4357 if (cw
& 0x4) fpword
|= MSVCRT__EM_ZERODIVIDE
;
4358 if (cw
& 0x8) fpword
|= MSVCRT__EM_OVERFLOW
;
4359 if (cw
& 0x10) fpword
|= MSVCRT__EM_UNDERFLOW
;
4360 if (cw
& 0x20) fpword
|= MSVCRT__EM_INEXACT
;
4363 case 0xc00: fpword
|= MSVCRT__RC_UP
|MSVCRT__RC_DOWN
; break;
4364 case 0x800: fpword
|= MSVCRT__RC_UP
; break;
4365 case 0x400: fpword
|= MSVCRT__RC_DOWN
; break;
4369 case 0x0: fpword
|= MSVCRT__PC_24
; break;
4370 case 0x200: fpword
|= MSVCRT__PC_53
; break;
4371 case 0x300: fpword
|= MSVCRT__PC_64
; break;
4373 if (cw
& 0x1000) fpword
|= MSVCRT__IC_AFFINE
;
4374 _control87(fpword
, 0xffffffff);
4379 _Dcomplex
* CDECL
MSVCR120__Cbuild(_Dcomplex
*ret
, double r
, double i
)
4386 double CDECL
MSVCR120_creal(_Dcomplex z
)
4391 int CDECL
MSVCR120_ilogb(double x
)
4393 if (!x
) return MSVCRT_FP_ILOGB0
;
4394 if (isnan(x
)) return MSVCRT_FP_ILOGBNAN
;
4395 if (isinf(x
)) return MSVCRT_INT_MAX
;
4404 int CDECL
MSVCR120_ilogbf(float x
)
4406 if (!x
) return MSVCRT_FP_ILOGB0
;
4407 if (isnan(x
)) return MSVCRT_FP_ILOGBNAN
;
4408 if (isinf(x
)) return MSVCRT_INT_MAX
;
4417 int CDECL
MSVCR120_ilogbl(LDOUBLE x
)
4419 return MSVCR120_ilogb(x
);
4422 #endif /* _MSVCR_VER>=120 */