xaudio2: Implement IXAudio2SourceVoice::Discontinuity.
[wine/multimedia.git] / dlls / msvcrt / math.c
blob2459bf57fcebcd2a14a42639d4f6945ac4fcdf62
1 /*
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdio.h>
24 #define __USE_ISOC9X 1
25 #define __USE_ISOC99 1
26 #include <math.h>
27 #ifdef HAVE_IEEEFP_H
28 #include <ieeefp.h>
29 #endif
31 #include "msvcrt.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
37 #ifndef HAVE_FINITEF
38 #define finitef(x) isfinite(x)
39 #endif
41 #ifndef HAVE_ISNANF
42 #ifdef HAVE_ISNAN
43 #define isnanf(x) isnan(x)
44 #else
45 #define isnanf(x) 0
46 #endif
47 #endif
49 /* FIXME: Does not work with -NAN and -0. */
50 #ifndef signbit
51 #define signbit(x) ((x) < 0)
52 #endif
54 typedef int (CDECL *MSVCRT_matherr_func)(struct MSVCRT__exception *);
55 typedef double LDOUBLE; /* long double is just a double */
57 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
59 static BOOL sse2_supported;
60 static BOOL sse2_enabled;
62 void msvcrt_init_math(void)
64 sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
67 /*********************************************************************
68 * _set_SSE2_enable (MSVCRT.@)
70 int CDECL MSVCRT__set_SSE2_enable(int flag)
72 sse2_enabled = flag && sse2_supported;
73 return sse2_enabled;
76 #if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
78 /*********************************************************************
79 * _chgsignf (MSVCRT.@)
81 float CDECL MSVCRT__chgsignf( float num )
83 /* FIXME: +-infinity,Nan not tested */
84 return -num;
87 /*********************************************************************
88 * _copysignf (MSVCRT.@)
90 float CDECL MSVCRT__copysignf( float num, float sign )
92 if (signbit(sign))
93 return signbit(num) ? num : -num;
94 return signbit(num) ? -num : num;
97 #endif
98 #if defined(__x86_64__) || defined(__arm__)
100 /*********************************************************************
101 * _finitef (MSVCRT.@)
103 int CDECL MSVCRT__finitef( float num )
105 return finitef(num) != 0; /* See comment for _isnan() */
108 /*********************************************************************
109 * _isnanf (MSVCRT.@)
111 INT CDECL MSVCRT__isnanf( float num )
113 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
114 * Do the same, as the result may be used in calculations
116 return isnanf(num) != 0;
119 /*********************************************************************
120 * _logbf (MSVCRT.@)
122 float CDECL MSVCRT__logbf( float num )
124 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
125 return logbf(num);
128 /*********************************************************************
129 * _nextafterf (MSVCRT.@)
131 float CDECL MSVCRT__nextafterf( float num, float next )
133 if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM;
134 return nextafterf( num, next );
137 /*********************************************************************
138 * MSVCRT_acosf (MSVCRT.@)
140 float CDECL MSVCRT_acosf( float x )
142 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
143 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
144 * asin() uses a similar construction. This is bad because as x gets nearer to
145 * 1 the error in the expression "1 - x^2" can get relatively large due to
146 * cancellation. The sqrt() makes things worse. A safer way to calculate
147 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
148 return atan2f(sqrtf((1 - x) * (1 + x)), x);
151 /*********************************************************************
152 * MSVCRT_asinf (MSVCRT.@)
154 float CDECL MSVCRT_asinf( float x )
156 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
157 return atan2f(x, sqrtf((1 - x) * (1 + x)));
160 /*********************************************************************
161 * MSVCRT_atanf (MSVCRT.@)
163 float CDECL MSVCRT_atanf( float x )
165 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
166 return atanf(x);
169 /*********************************************************************
170 * MSVCRT_atan2f (MSVCRT.@)
172 float CDECL MSVCRT_atan2f( float x, float y )
174 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
175 return atan2f(x,y);
178 /*********************************************************************
179 * MSVCRT_cosf (MSVCRT.@)
181 float CDECL MSVCRT_cosf( float x )
183 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
184 return cosf(x);
187 /*********************************************************************
188 * MSVCRT_coshf (MSVCRT.@)
190 float CDECL MSVCRT_coshf( float x )
192 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
193 return coshf(x);
196 /*********************************************************************
197 * MSVCRT_expf (MSVCRT.@)
199 float CDECL MSVCRT_expf( float x )
201 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
202 return expf(x);
205 /*********************************************************************
206 * MSVCRT_fmodf (MSVCRT.@)
208 float CDECL MSVCRT_fmodf( float x, float y )
210 if (!finitef(x) || !finitef(y)) *MSVCRT__errno() = MSVCRT_EDOM;
211 return fmodf(x,y);
214 /*********************************************************************
215 * MSVCRT_logf (MSVCRT.@)
217 float CDECL MSVCRT_logf( float x)
219 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
220 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
221 return logf(x);
224 /*********************************************************************
225 * MSVCRT_log10f (MSVCRT.@)
227 float CDECL MSVCRT_log10f( float x )
229 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
230 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
231 return log10f(x);
234 /*********************************************************************
235 * MSVCRT_powf (MSVCRT.@)
237 float CDECL MSVCRT_powf( float x, float y )
239 /* FIXME: If x < 0 and y is not integral, set EDOM */
240 float z = powf(x,y);
241 if (!finitef(z)) *MSVCRT__errno() = MSVCRT_EDOM;
242 return z;
245 /*********************************************************************
246 * MSVCRT_sinf (MSVCRT.@)
248 float CDECL MSVCRT_sinf( float x )
250 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
251 return sinf(x);
254 /*********************************************************************
255 * MSVCRT_sinhf (MSVCRT.@)
257 float CDECL MSVCRT_sinhf( float x )
259 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
260 return sinhf(x);
263 /*********************************************************************
264 * MSVCRT_sqrtf (MSVCRT.@)
266 float CDECL MSVCRT_sqrtf( float x )
268 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
269 return sqrtf(x);
272 /*********************************************************************
273 * MSVCRT_tanf (MSVCRT.@)
275 float CDECL MSVCRT_tanf( float x )
277 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
278 return tanf(x);
281 /*********************************************************************
282 * MSVCRT_tanhf (MSVCRT.@)
284 float CDECL MSVCRT_tanhf( float x )
286 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
287 return tanhf(x);
290 /*********************************************************************
291 * ceilf (MSVCRT.@)
293 float CDECL MSVCRT_ceilf( float x )
295 return ceilf(x);
298 /*********************************************************************
299 * fabsf (MSVCRT.@)
301 float CDECL MSVCRT_fabsf( float x )
303 return fabsf(x);
306 /*********************************************************************
307 * floorf (MSVCRT.@)
309 float CDECL MSVCRT_floorf( float x )
311 return floorf(x);
314 /*********************************************************************
315 * frexpf (MSVCRT.@)
317 float CDECL MSVCRT_frexpf( float x, int *exp )
319 return frexpf( x, exp );
322 /*********************************************************************
323 * _scalbf (MSVCRT.@)
325 float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
327 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
328 return ldexpf(num, power);
331 /*********************************************************************
332 * modff (MSVCRT.@)
334 double CDECL MSVCRT_modff( float x, float *iptr )
336 return modff( x, iptr );
339 #endif
341 /*********************************************************************
342 * MSVCRT_acos (MSVCRT.@)
344 double CDECL MSVCRT_acos( double x )
346 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
347 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
348 * asin() uses a similar construction. This is bad because as x gets nearer to
349 * 1 the error in the expression "1 - x^2" can get relatively large due to
350 * cancellation. The sqrt() makes things worse. A safer way to calculate
351 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
352 return atan2(sqrt((1 - x) * (1 + x)), x);
355 /*********************************************************************
356 * MSVCRT_asin (MSVCRT.@)
358 double CDECL MSVCRT_asin( double x )
360 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
361 return atan2(x, sqrt((1 - x) * (1 + x)));
364 /*********************************************************************
365 * MSVCRT_atan (MSVCRT.@)
367 double CDECL MSVCRT_atan( double x )
369 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
370 return atan(x);
373 /*********************************************************************
374 * MSVCRT_atan2 (MSVCRT.@)
376 double CDECL MSVCRT_atan2( double x, double y )
378 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
379 return atan2(x,y);
382 /*********************************************************************
383 * MSVCRT_cos (MSVCRT.@)
385 double CDECL MSVCRT_cos( double x )
387 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
388 return cos(x);
391 /*********************************************************************
392 * MSVCRT_cosh (MSVCRT.@)
394 double CDECL MSVCRT_cosh( double x )
396 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
397 return cosh(x);
400 /*********************************************************************
401 * MSVCRT_exp (MSVCRT.@)
403 double CDECL MSVCRT_exp( double x )
405 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
406 return exp(x);
409 /*********************************************************************
410 * MSVCRT_fmod (MSVCRT.@)
412 double CDECL MSVCRT_fmod( double x, double y )
414 if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
415 return fmod(x,y);
418 /*********************************************************************
419 * MSVCRT_log (MSVCRT.@)
421 double CDECL MSVCRT_log( double x)
423 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
424 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
425 return log(x);
428 /*********************************************************************
429 * MSVCRT_log10 (MSVCRT.@)
431 double CDECL MSVCRT_log10( double x )
433 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
434 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
435 return log10(x);
438 /*********************************************************************
439 * MSVCRT_pow (MSVCRT.@)
441 double CDECL MSVCRT_pow( double x, double y )
443 /* FIXME: If x < 0 and y is not integral, set EDOM */
444 double z = pow(x,y);
445 if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
446 return z;
449 /*********************************************************************
450 * MSVCRT_sin (MSVCRT.@)
452 double CDECL MSVCRT_sin( double x )
454 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
455 return sin(x);
458 /*********************************************************************
459 * MSVCRT_sinh (MSVCRT.@)
461 double CDECL MSVCRT_sinh( double x )
463 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
464 return sinh(x);
467 /*********************************************************************
468 * MSVCRT_sqrt (MSVCRT.@)
470 double CDECL MSVCRT_sqrt( double x )
472 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
473 return sqrt(x);
476 /*********************************************************************
477 * MSVCRT_tan (MSVCRT.@)
479 double CDECL MSVCRT_tan( double x )
481 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
482 return tan(x);
485 /*********************************************************************
486 * MSVCRT_tanh (MSVCRT.@)
488 double CDECL MSVCRT_tanh( double x )
490 if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
491 return tanh(x);
495 #if defined(__GNUC__) && defined(__i386__)
497 #define FPU_DOUBLE(var) double var; \
498 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
499 #define FPU_DOUBLES(var1,var2) double var1,var2; \
500 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
501 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
503 /*********************************************************************
504 * _CIacos (MSVCRT.@)
506 double CDECL _CIacos(void)
508 FPU_DOUBLE(x);
509 return MSVCRT_acos(x);
512 /*********************************************************************
513 * _CIasin (MSVCRT.@)
515 double CDECL _CIasin(void)
517 FPU_DOUBLE(x);
518 return MSVCRT_asin(x);
521 /*********************************************************************
522 * _CIatan (MSVCRT.@)
524 double CDECL _CIatan(void)
526 FPU_DOUBLE(x);
527 return MSVCRT_atan(x);
530 /*********************************************************************
531 * _CIatan2 (MSVCRT.@)
533 double CDECL _CIatan2(void)
535 FPU_DOUBLES(x,y);
536 return MSVCRT_atan2(x,y);
539 /*********************************************************************
540 * _CIcos (MSVCRT.@)
542 double CDECL _CIcos(void)
544 FPU_DOUBLE(x);
545 return MSVCRT_cos(x);
548 /*********************************************************************
549 * _CIcosh (MSVCRT.@)
551 double CDECL _CIcosh(void)
553 FPU_DOUBLE(x);
554 return MSVCRT_cosh(x);
557 /*********************************************************************
558 * _CIexp (MSVCRT.@)
560 double CDECL _CIexp(void)
562 FPU_DOUBLE(x);
563 return MSVCRT_exp(x);
566 /*********************************************************************
567 * _CIfmod (MSVCRT.@)
569 double CDECL _CIfmod(void)
571 FPU_DOUBLES(x,y);
572 return MSVCRT_fmod(x,y);
575 /*********************************************************************
576 * _CIlog (MSVCRT.@)
578 double CDECL _CIlog(void)
580 FPU_DOUBLE(x);
581 return MSVCRT_log(x);
584 /*********************************************************************
585 * _CIlog10 (MSVCRT.@)
587 double CDECL _CIlog10(void)
589 FPU_DOUBLE(x);
590 return MSVCRT_log10(x);
593 /*********************************************************************
594 * _CIpow (MSVCRT.@)
596 double CDECL _CIpow(void)
598 FPU_DOUBLES(x,y);
599 return MSVCRT_pow(x,y);
602 /*********************************************************************
603 * _CIsin (MSVCRT.@)
605 double CDECL _CIsin(void)
607 FPU_DOUBLE(x);
608 return MSVCRT_sin(x);
611 /*********************************************************************
612 * _CIsinh (MSVCRT.@)
614 double CDECL _CIsinh(void)
616 FPU_DOUBLE(x);
617 return MSVCRT_sinh(x);
620 /*********************************************************************
621 * _CIsqrt (MSVCRT.@)
623 double CDECL _CIsqrt(void)
625 FPU_DOUBLE(x);
626 return MSVCRT_sqrt(x);
629 /*********************************************************************
630 * _CItan (MSVCRT.@)
632 double CDECL _CItan(void)
634 FPU_DOUBLE(x);
635 return MSVCRT_tan(x);
638 /*********************************************************************
639 * _CItanh (MSVCRT.@)
641 double CDECL _CItanh(void)
643 FPU_DOUBLE(x);
644 return MSVCRT_tanh(x);
647 /*********************************************************************
648 * _ftol (MSVCRT.@)
650 LONGLONG CDECL MSVCRT__ftol(void)
652 FPU_DOUBLE(x);
653 return (LONGLONG)x;
656 #endif /* defined(__GNUC__) && defined(__i386__) */
658 /*********************************************************************
659 * _fpclass (MSVCRT.@)
661 int CDECL MSVCRT__fpclass(double num)
663 #if defined(HAVE_FPCLASS) || defined(fpclass)
664 switch (fpclass( num ))
666 #ifdef FP_SNAN
667 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
668 #endif
669 #ifdef FP_QNAN
670 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
671 #endif
672 #ifdef FP_NINF
673 case FP_NINF: return MSVCRT__FPCLASS_NINF;
674 #endif
675 #ifdef FP_PINF
676 case FP_PINF: return MSVCRT__FPCLASS_PINF;
677 #endif
678 #ifdef FP_NDENORM
679 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
680 #endif
681 #ifdef FP_PDENORM
682 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
683 #endif
684 #ifdef FP_NZERO
685 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
686 #endif
687 #ifdef FP_PZERO
688 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
689 #endif
690 #ifdef FP_NNORM
691 case FP_NNORM: return MSVCRT__FPCLASS_NN;
692 #endif
693 #ifdef FP_PNORM
694 case FP_PNORM: return MSVCRT__FPCLASS_PN;
695 #endif
696 default: return MSVCRT__FPCLASS_PN;
698 #elif defined (fpclassify)
699 switch (fpclassify( num ))
701 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
702 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
703 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
704 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
706 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
707 #else
708 if (!isfinite(num))
709 return MSVCRT__FPCLASS_QNAN;
710 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
711 #endif
714 /*********************************************************************
715 * _rotl (MSVCRT.@)
717 unsigned int CDECL _rotl(unsigned int num, int shift)
719 shift &= 31;
720 return (num << shift) | (num >> (32-shift));
723 /*********************************************************************
724 * _lrotl (MSVCRT.@)
726 MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
728 shift &= 0x1f;
729 return (num << shift) | (num >> (32-shift));
732 /*********************************************************************
733 * _lrotr (MSVCRT.@)
735 MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
737 shift &= 0x1f;
738 return (num >> shift) | (num << (32-shift));
741 /*********************************************************************
742 * _rotr (MSVCRT.@)
744 unsigned int CDECL _rotr(unsigned int num, int shift)
746 shift &= 0x1f;
747 return (num >> shift) | (num << (32-shift));
750 /*********************************************************************
751 * _rotl64 (MSVCRT.@)
753 unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
755 shift &= 63;
756 return (num << shift) | (num >> (64-shift));
759 /*********************************************************************
760 * _rotr64 (MSVCRT.@)
762 unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
764 shift &= 63;
765 return (num >> shift) | (num << (64-shift));
768 /*********************************************************************
769 * abs (MSVCRT.@)
771 int CDECL MSVCRT_abs( int n )
773 return n >= 0 ? n : -n;
776 /*********************************************************************
777 * labs (MSVCRT.@)
779 MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
781 return n >= 0 ? n : -n;
784 /*********************************************************************
785 * llabs (MSVCRT.@)
787 MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
789 return n >= 0 ? n : -n;
792 /*********************************************************************
793 * _abs64 (MSVCRT.@)
795 __int64 CDECL _abs64( __int64 n )
797 return n >= 0 ? n : -n;
800 /*********************************************************************
801 * _logb (MSVCRT.@)
803 double CDECL MSVCRT__logb(double num)
805 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
806 return logb(num);
809 /*********************************************************************
810 * _scalb (MSVCRT.@)
812 double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
814 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
815 return ldexp(num, power);
818 /*********************************************************************
819 * _hypot (MSVCRT.@)
821 double CDECL _hypot(double x, double y)
823 /* FIXME: errno handling */
824 return hypot( x, y );
827 /*********************************************************************
828 * _hypotf (MSVCRT.@)
830 float CDECL MSVCRT__hypotf(float x, float y)
832 /* FIXME: errno handling */
833 return hypotf( x, y );
836 /*********************************************************************
837 * ceil (MSVCRT.@)
839 double CDECL MSVCRT_ceil( double x )
841 return ceil(x);
844 /*********************************************************************
845 * floor (MSVCRT.@)
847 double CDECL MSVCRT_floor( double x )
849 return floor(x);
852 /*********************************************************************
853 * fabs (MSVCRT.@)
855 double CDECL MSVCRT_fabs( double x )
857 return fabs(x);
860 /*********************************************************************
861 * frexp (MSVCRT.@)
863 double CDECL MSVCRT_frexp( double x, int *exp )
865 return frexp( x, exp );
868 /*********************************************************************
869 * modf (MSVCRT.@)
871 double CDECL MSVCRT_modf( double x, double *iptr )
873 return modf( x, iptr );
876 /*********************************************************************
877 * _matherr (MSVCRT.@)
879 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
881 if (e)
882 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
883 e->retval);
884 else
885 TRACE("(null)\n");
886 if (MSVCRT_default_matherr_func)
887 return MSVCRT_default_matherr_func(e);
888 ERR(":Unhandled math error!\n");
889 return 0;
892 /*********************************************************************
893 * __setusermatherr (MSVCRT.@)
895 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
897 MSVCRT_default_matherr_func = func;
898 TRACE(":new matherr handler %p\n", func);
901 /**********************************************************************
902 * _statusfp2 (MSVCRT.@)
904 * Not exported by native msvcrt, added in msvcr80.
906 #if defined(__i386__) || defined(__x86_64__)
907 void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
909 #ifdef __GNUC__
910 unsigned int flags;
911 unsigned long fpword;
913 if (x86_sw)
915 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
916 flags = 0;
917 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
918 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
919 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
920 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
921 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
922 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
923 *x86_sw = flags;
926 if (!sse2_sw) return;
928 if (sse2_supported)
930 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
931 flags = 0;
932 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
933 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
934 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
935 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
936 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
937 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
938 *sse2_sw = flags;
940 else *sse2_sw = 0;
941 #else
942 FIXME( "not implemented\n" );
943 #endif
945 #endif
947 /**********************************************************************
948 * _statusfp (MSVCRT.@)
950 unsigned int CDECL _statusfp(void)
952 #if defined(__i386__) || defined(__x86_64__)
953 unsigned int x86_sw, sse2_sw;
955 _statusfp2( &x86_sw, &sse2_sw );
956 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
957 return x86_sw | sse2_sw;
958 #else
959 FIXME( "not implemented\n" );
960 return 0;
961 #endif
964 /*********************************************************************
965 * _clearfp (MSVCRT.@)
967 unsigned int CDECL _clearfp(void)
969 unsigned int flags = 0;
970 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
971 unsigned long fpword;
973 __asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
974 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
975 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
976 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
977 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
978 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
979 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
981 if (sse2_supported)
983 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
984 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
985 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
986 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
987 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
988 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
989 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
990 fpword &= ~0x3f;
991 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
993 #else
994 FIXME( "not implemented\n" );
995 #endif
996 return flags;
999 /*********************************************************************
1000 * __fpecode (MSVCRT.@)
1002 int * CDECL __fpecode(void)
1004 return &msvcrt_get_thread_data()->fpecode;
1007 /*********************************************************************
1008 * ldexp (MSVCRT.@)
1010 double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
1012 double z = ldexp(num,exp);
1014 if (!isfinite(z))
1015 *MSVCRT__errno() = MSVCRT_ERANGE;
1016 else if (z == 0 && signbit(z))
1017 z = 0.0; /* Convert -0 -> +0 */
1018 return z;
1021 /*********************************************************************
1022 * _cabs (MSVCRT.@)
1024 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
1026 return sqrt(num.x * num.x + num.y * num.y);
1029 /*********************************************************************
1030 * _chgsign (MSVCRT.@)
1032 double CDECL MSVCRT__chgsign(double num)
1034 /* FIXME: +-infinity,Nan not tested */
1035 return -num;
1038 /*********************************************************************
1039 * __control87_2 (MSVCRT.@)
1041 * Not exported by native msvcrt, added in msvcr80.
1043 #if defined(__i386__) || defined(__x86_64__)
1044 int CDECL __control87_2( unsigned int newval, unsigned int mask,
1045 unsigned int *x86_cw, unsigned int *sse2_cw )
1047 #ifdef __GNUC__
1048 unsigned long fpword;
1049 unsigned int flags;
1051 if (x86_cw)
1053 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
1055 /* Convert into mask constants */
1056 flags = 0;
1057 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
1058 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
1059 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
1060 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
1061 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
1062 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
1063 switch (fpword & 0xc00)
1065 case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1066 case 0x800: flags |= MSVCRT__RC_UP; break;
1067 case 0x400: flags |= MSVCRT__RC_DOWN; break;
1069 switch (fpword & 0x300)
1071 case 0x0: flags |= MSVCRT__PC_24; break;
1072 case 0x200: flags |= MSVCRT__PC_53; break;
1073 case 0x300: flags |= MSVCRT__PC_64; break;
1075 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
1077 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1078 if (mask)
1080 flags = (flags & ~mask) | (newval & mask);
1082 /* Convert (masked) value back to fp word */
1083 fpword = 0;
1084 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
1085 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
1086 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
1087 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
1088 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
1089 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
1090 switch (flags & MSVCRT__MCW_RC)
1092 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
1093 case MSVCRT__RC_UP: fpword |= 0x800; break;
1094 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
1096 switch (flags & MSVCRT__MCW_PC)
1098 case MSVCRT__PC_64: fpword |= 0x300; break;
1099 case MSVCRT__PC_53: fpword |= 0x200; break;
1100 case MSVCRT__PC_24: fpword |= 0x0; break;
1102 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
1104 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
1106 *x86_cw = flags;
1109 if (!sse2_cw) return 1;
1111 if (sse2_supported)
1113 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
1115 /* Convert into mask constants */
1116 flags = 0;
1117 if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
1118 if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
1119 if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
1120 if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
1121 if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
1122 if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
1123 switch (fpword & 0x6000)
1125 case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1126 case 0x4000: flags |= MSVCRT__RC_UP; break;
1127 case 0x2000: flags |= MSVCRT__RC_DOWN; break;
1129 switch (fpword & 0x8040)
1131 case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
1132 case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
1133 case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
1136 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1137 if (mask)
1139 flags = (flags & ~mask) | (newval & mask);
1141 /* Convert (masked) value back to fp word */
1142 fpword = 0;
1143 if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
1144 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
1145 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
1146 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
1147 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
1148 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
1149 switch (flags & MSVCRT__MCW_RC)
1151 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
1152 case MSVCRT__RC_UP: fpword |= 0x4000; break;
1153 case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
1155 switch (flags & MSVCRT__MCW_DN)
1157 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
1158 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
1159 case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
1161 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1163 *sse2_cw = flags;
1165 else *sse2_cw = 0;
1167 return 1;
1168 #else
1169 FIXME( "not implemented\n" );
1170 return 0;
1171 #endif
1173 #endif
1175 /*********************************************************************
1176 * _control87 (MSVCRT.@)
1178 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
1180 #if defined(__i386__) || defined(__x86_64__)
1181 unsigned int x86_cw, sse2_cw;
1183 __control87_2( newval, mask, &x86_cw, &sse2_cw );
1185 if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS;
1186 return x86_cw;
1187 #else
1188 FIXME( "not implemented\n" );
1189 return 0;
1190 #endif
1193 /*********************************************************************
1194 * _controlfp (MSVCRT.@)
1196 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
1198 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
1201 /*********************************************************************
1202 * _set_controlfp (MSVCRT.@)
1204 void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
1206 _controlfp( newval, mask );
1209 /*********************************************************************
1210 * _controlfp_s (MSVCRT.@)
1212 int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
1214 static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
1215 MSVCRT__MCW_PC | MSVCRT__MCW_DN);
1216 unsigned int val;
1218 if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
1220 if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
1221 return MSVCRT_EINVAL;
1223 val = _controlfp( newval, mask );
1224 if (cur) *cur = val;
1225 return 0;
1228 /*********************************************************************
1229 * _copysign (MSVCRT.@)
1231 double CDECL MSVCRT__copysign(double num, double sign)
1233 if (signbit(sign))
1234 return signbit(num) ? num : -num;
1235 return signbit(num) ? -num : num;
1238 /*********************************************************************
1239 * _finite (MSVCRT.@)
1241 int CDECL MSVCRT__finite(double num)
1243 return isfinite(num) != 0; /* See comment for _isnan() */
1246 /*********************************************************************
1247 * _fpreset (MSVCRT.@)
1249 void CDECL _fpreset(void)
1251 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1252 const unsigned int x86_cw = 0x27f;
1253 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1254 if (sse2_supported)
1256 const unsigned long sse2_cw = 0x1f80;
1257 __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
1259 #else
1260 FIXME( "not implemented\n" );
1261 #endif
1264 /*********************************************************************
1265 * _isnan (MSVCRT.@)
1267 INT CDECL MSVCRT__isnan(double num)
1269 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1270 * Do the same, as the result may be used in calculations
1272 return isnan(num) != 0;
1275 /*********************************************************************
1276 * _j0 (MSVCRT.@)
1278 double CDECL MSVCRT__j0(double num)
1280 /* FIXME: errno handling */
1281 return j0(num);
1284 /*********************************************************************
1285 * _j1 (MSVCRT.@)
1287 double CDECL MSVCRT__j1(double num)
1289 /* FIXME: errno handling */
1290 return j1(num);
1293 /*********************************************************************
1294 * _jn (MSVCRT.@)
1296 double CDECL MSVCRT__jn(int n, double num)
1298 /* FIXME: errno handling */
1299 return jn(n, num);
1302 /*********************************************************************
1303 * _y0 (MSVCRT.@)
1305 double CDECL MSVCRT__y0(double num)
1307 double retval;
1308 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1309 retval = y0(num);
1310 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1312 *MSVCRT__errno() = MSVCRT_EDOM;
1313 retval = sqrt(-1);
1315 return retval;
1318 /*********************************************************************
1319 * _y1 (MSVCRT.@)
1321 double CDECL MSVCRT__y1(double num)
1323 double retval;
1324 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1325 retval = y1(num);
1326 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1328 *MSVCRT__errno() = MSVCRT_EDOM;
1329 retval = sqrt(-1);
1331 return retval;
1334 /*********************************************************************
1335 * _yn (MSVCRT.@)
1337 double CDECL MSVCRT__yn(int order, double num)
1339 double retval;
1340 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1341 retval = yn(order,num);
1342 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1344 *MSVCRT__errno() = MSVCRT_EDOM;
1345 retval = sqrt(-1);
1347 return retval;
1350 /*********************************************************************
1351 * _nextafter (MSVCRT.@)
1353 double CDECL MSVCRT__nextafter(double num, double next)
1355 double retval;
1356 if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
1357 retval = nextafter(num,next);
1358 return retval;
1361 /*********************************************************************
1362 * _ecvt (MSVCRT.@)
1364 char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
1366 int prec, len;
1367 thread_data_t *data = msvcrt_get_thread_data();
1368 /* FIXME: check better for overflow (native supports over 300 chars) */
1369 ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
1370 * 4 for exponent and one for
1371 * terminating '\0' */
1372 if (!data->efcvt_buffer)
1373 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1375 if( number < 0) {
1376 *sign = TRUE;
1377 number = -number;
1378 } else
1379 *sign = FALSE;
1380 /* handle cases with zero ndigits or less */
1381 prec = ndigits;
1382 if( prec < 1) prec = 2;
1383 len = snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
1384 /* take the decimal "point away */
1385 if( prec != 1)
1386 memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
1387 /* take the exponential "e" out */
1388 data->efcvt_buffer[ prec] = '\0';
1389 /* read the exponent */
1390 sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
1391 (*decpt)++;
1392 /* adjust for some border cases */
1393 if( data->efcvt_buffer[0] == '0')/* value is zero */
1394 *decpt = 0;
1395 /* handle cases with zero ndigits or less */
1396 if( ndigits < 1){
1397 if( data->efcvt_buffer[ 0] >= '5')
1398 (*decpt)++;
1399 data->efcvt_buffer[ 0] = '\0';
1401 TRACE("out=\"%s\"\n",data->efcvt_buffer);
1402 return data->efcvt_buffer;
1405 /*********************************************************************
1406 * _ecvt_s (MSVCRT.@)
1408 int CDECL MSVCRT__ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
1410 int prec, len;
1411 char *result;
1412 const char infret[] = "1#INF";
1414 if (!MSVCRT_CHECK_PMT(buffer != NULL)) return MSVCRT_EINVAL;
1415 if (!MSVCRT_CHECK_PMT(decpt != NULL)) return MSVCRT_EINVAL;
1416 if (!MSVCRT_CHECK_PMT(sign != NULL)) return MSVCRT_EINVAL;
1417 if (!MSVCRT_CHECK_PMT_ERR( length > 2, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1418 if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1420 /* special case - inf */
1421 if(number == HUGE_VAL || number == -HUGE_VAL)
1423 memset(buffer, '0', ndigits);
1424 memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
1425 buffer[ndigits] = '\0';
1426 (*decpt) = 1;
1427 if(number == -HUGE_VAL)
1428 (*sign) = 1;
1429 else
1430 (*sign) = 0;
1431 return 0;
1433 /* handle cases with zero ndigits or less */
1434 prec = ndigits;
1435 if( prec < 1) prec = 2;
1436 result = MSVCRT_malloc(prec + 7);
1438 if( number < 0) {
1439 *sign = TRUE;
1440 number = -number;
1441 } else
1442 *sign = FALSE;
1443 len = snprintf(result, prec + 7, "%.*le", prec - 1, number);
1444 /* take the decimal "point away */
1445 if( prec != 1)
1446 memmove( result + 1, result + 2, len - 1 );
1447 /* take the exponential "e" out */
1448 result[ prec] = '\0';
1449 /* read the exponent */
1450 sscanf( result + prec + 1, "%d", decpt);
1451 (*decpt)++;
1452 /* adjust for some border cases */
1453 if( result[0] == '0')/* value is zero */
1454 *decpt = 0;
1455 /* handle cases with zero ndigits or less */
1456 if( ndigits < 1){
1457 if( result[ 0] >= '5')
1458 (*decpt)++;
1459 result[ 0] = '\0';
1461 memcpy( buffer, result, max(ndigits + 1, 1) );
1462 MSVCRT_free( result );
1463 return 0;
1466 /***********************************************************************
1467 * _fcvt (MSVCRT.@)
1469 char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
1471 thread_data_t *data = msvcrt_get_thread_data();
1472 int stop, dec1, dec2;
1473 char *ptr1, *ptr2, *first;
1474 char buf[80]; /* ought to be enough */
1476 if (!data->efcvt_buffer)
1477 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1479 if (number < 0)
1481 *sign = 1;
1482 number = -number;
1483 } else *sign = 0;
1485 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1486 ptr1 = buf;
1487 ptr2 = data->efcvt_buffer;
1488 first = NULL;
1489 dec1 = 0;
1490 dec2 = 0;
1492 /* For numbers below the requested resolution, work out where
1493 the decimal point will be rather than finding it in the string */
1494 if (number < 1.0 && number > 0.0) {
1495 dec2 = log10(number + 1e-10);
1496 if (-dec2 <= ndigits) dec2 = 0;
1499 /* If requested digits is zero or less, we will need to truncate
1500 * the returned string */
1501 if (ndigits < 1) {
1502 stop = strlen(buf) + ndigits;
1503 } else {
1504 stop = strlen(buf);
1507 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1508 while (*ptr1 != '\0' && *ptr1 != '.') {
1509 if (!first) first = ptr2;
1510 if ((ptr1 - buf) < stop) {
1511 *ptr2++ = *ptr1++;
1512 } else {
1513 ptr1++;
1515 dec1++;
1518 if (ndigits > 0) {
1519 ptr1++;
1520 if (!first) {
1521 while (*ptr1 == '0') { /* Process leading zeroes */
1522 *ptr2++ = *ptr1++;
1523 dec1--;
1526 while (*ptr1 != '\0') {
1527 if (!first) first = ptr2;
1528 *ptr2++ = *ptr1++;
1532 *ptr2 = '\0';
1534 /* We never found a non-zero digit, then our number is either
1535 * smaller than the requested precision, or 0.0 */
1536 if (!first) {
1537 if (number > 0.0) {
1538 first = ptr2;
1539 } else {
1540 first = data->efcvt_buffer;
1541 dec1 = 0;
1545 *decpt = dec2 ? dec2 : dec1;
1546 return first;
1549 /***********************************************************************
1550 * _fcvt_s (MSVCRT.@)
1552 int CDECL MSVCRT__fcvt_s(char* outbuffer, MSVCRT_size_t size, double number, int ndigits, int *decpt, int *sign)
1554 int stop, dec1, dec2;
1555 char *ptr1, *ptr2, *first;
1556 char buf[80]; /* ought to be enough */
1558 if (!outbuffer || !decpt || !sign || size == 0)
1560 *MSVCRT__errno() = MSVCRT_EINVAL;
1561 return MSVCRT_EINVAL;
1564 if (number < 0)
1566 *sign = 1;
1567 number = -number;
1568 } else *sign = 0;
1570 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1571 ptr1 = buf;
1572 ptr2 = outbuffer;
1573 first = NULL;
1574 dec1 = 0;
1575 dec2 = 0;
1577 /* For numbers below the requested resolution, work out where
1578 the decimal point will be rather than finding it in the string */
1579 if (number < 1.0 && number > 0.0) {
1580 dec2 = log10(number + 1e-10);
1581 if (-dec2 <= ndigits) dec2 = 0;
1584 /* If requested digits is zero or less, we will need to truncate
1585 * the returned string */
1586 if (ndigits < 1) {
1587 stop = strlen(buf) + ndigits;
1588 } else {
1589 stop = strlen(buf);
1592 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1593 while (*ptr1 != '\0' && *ptr1 != '.') {
1594 if (!first) first = ptr2;
1595 if ((ptr1 - buf) < stop) {
1596 if (size > 1) {
1597 *ptr2++ = *ptr1++;
1598 size--;
1600 } else {
1601 ptr1++;
1603 dec1++;
1606 if (ndigits > 0) {
1607 ptr1++;
1608 if (!first) {
1609 while (*ptr1 == '0') { /* Process leading zeroes */
1610 if (number == 0.0 && size > 1) {
1611 *ptr2++ = '0';
1612 size--;
1614 ptr1++;
1615 dec1--;
1618 while (*ptr1 != '\0') {
1619 if (!first) first = ptr2;
1620 if (size > 1) {
1621 *ptr2++ = *ptr1++;
1622 size--;
1627 *ptr2 = '\0';
1629 /* We never found a non-zero digit, then our number is either
1630 * smaller than the requested precision, or 0.0 */
1631 if (!first && (number <= 0.0))
1632 dec1 = 0;
1634 *decpt = dec2 ? dec2 : dec1;
1635 return 0;
1638 /***********************************************************************
1639 * _gcvt (MSVCRT.@)
1641 char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
1643 if(!buff) {
1644 *MSVCRT__errno() = MSVCRT_EINVAL;
1645 return NULL;
1648 if(ndigit < 0) {
1649 *MSVCRT__errno() = MSVCRT_ERANGE;
1650 return NULL;
1653 MSVCRT_sprintf(buff, "%.*g", ndigit, number);
1654 return buff;
1657 /***********************************************************************
1658 * _gcvt_s (MSVCRT.@)
1660 int CDECL MSVCRT__gcvt_s(char *buff, MSVCRT_size_t size, double number, int digits)
1662 int len;
1664 if(!buff) {
1665 *MSVCRT__errno() = MSVCRT_EINVAL;
1666 return MSVCRT_EINVAL;
1669 if( digits<0 || digits>=size) {
1670 if(size)
1671 buff[0] = '\0';
1673 *MSVCRT__errno() = MSVCRT_ERANGE;
1674 return MSVCRT_ERANGE;
1677 len = MSVCRT__scprintf("%.*g", digits, number);
1678 if(len > size) {
1679 buff[0] = '\0';
1680 *MSVCRT__errno() = MSVCRT_ERANGE;
1681 return MSVCRT_ERANGE;
1684 MSVCRT_sprintf(buff, "%.*g", digits, number);
1685 return 0;
1688 #include <stdlib.h> /* div_t, ldiv_t */
1690 /*********************************************************************
1691 * div (MSVCRT.@)
1692 * VERSION
1693 * [i386] Windows binary compatible - returns the struct in eax/edx.
1695 #ifdef __i386__
1696 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
1698 div_t dt = div(num,denom);
1699 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
1701 #else
1702 /*********************************************************************
1703 * div (MSVCRT.@)
1704 * VERSION
1705 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1707 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
1709 div_t dt = div(num,denom);
1710 MSVCRT_div_t ret;
1711 ret.quot = dt.quot;
1712 ret.rem = dt.rem;
1714 return ret;
1717 #endif /* ifdef __i386__ */
1720 /*********************************************************************
1721 * ldiv (MSVCRT.@)
1722 * VERSION
1723 * [i386] Windows binary compatible - returns the struct in eax/edx.
1725 #ifdef __i386__
1726 unsigned __int64 CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1728 ldiv_t ldt = ldiv(num,denom);
1729 return ((unsigned __int64)ldt.rem << 32) | (MSVCRT_ulong)ldt.quot;
1731 #else
1732 /*********************************************************************
1733 * ldiv (MSVCRT.@)
1734 * VERSION
1735 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1737 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1739 ldiv_t result = ldiv(num,denom);
1741 MSVCRT_ldiv_t ret;
1742 ret.quot = result.quot;
1743 ret.rem = result.rem;
1745 return ret;
1747 #endif /* ifdef __i386__ */
1749 #ifdef __i386__
1751 /*********************************************************************
1752 * _adjust_fdiv (MSVCRT.@)
1753 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1755 int MSVCRT__adjust_fdiv = 0;
1757 /***********************************************************************
1758 * _adj_fdiv_m16i (MSVCRT.@)
1760 * NOTE
1761 * I _think_ this function is intended to work around the Pentium
1762 * fdiv bug.
1764 void __stdcall _adj_fdiv_m16i( short arg )
1766 TRACE("(): stub\n");
1769 /***********************************************************************
1770 * _adj_fdiv_m32 (MSVCRT.@)
1772 * NOTE
1773 * I _think_ this function is intended to work around the Pentium
1774 * fdiv bug.
1776 void __stdcall _adj_fdiv_m32( unsigned int arg )
1778 TRACE("(): stub\n");
1781 /***********************************************************************
1782 * _adj_fdiv_m32i (MSVCRT.@)
1784 * NOTE
1785 * I _think_ this function is intended to work around the Pentium
1786 * fdiv bug.
1788 void __stdcall _adj_fdiv_m32i( int arg )
1790 TRACE("(): stub\n");
1793 /***********************************************************************
1794 * _adj_fdiv_m64 (MSVCRT.@)
1796 * NOTE
1797 * I _think_ this function is intended to work around the Pentium
1798 * fdiv bug.
1800 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1802 TRACE("(): stub\n");
1805 /***********************************************************************
1806 * _adj_fdiv_r (MSVCRT.@)
1807 * FIXME
1808 * This function is likely to have the wrong number of arguments.
1810 * NOTE
1811 * I _think_ this function is intended to work around the Pentium
1812 * fdiv bug.
1814 void _adj_fdiv_r(void)
1816 TRACE("(): stub\n");
1819 /***********************************************************************
1820 * _adj_fdivr_m16i (MSVCRT.@)
1822 * NOTE
1823 * I _think_ this function is intended to work around the Pentium
1824 * fdiv bug.
1826 void __stdcall _adj_fdivr_m16i( short arg )
1828 TRACE("(): stub\n");
1831 /***********************************************************************
1832 * _adj_fdivr_m32 (MSVCRT.@)
1834 * NOTE
1835 * I _think_ this function is intended to work around the Pentium
1836 * fdiv bug.
1838 void __stdcall _adj_fdivr_m32( unsigned int arg )
1840 TRACE("(): stub\n");
1843 /***********************************************************************
1844 * _adj_fdivr_m32i (MSVCRT.@)
1846 * NOTE
1847 * I _think_ this function is intended to work around the Pentium
1848 * fdiv bug.
1850 void __stdcall _adj_fdivr_m32i( int arg )
1852 TRACE("(): stub\n");
1855 /***********************************************************************
1856 * _adj_fdivr_m64 (MSVCRT.@)
1858 * NOTE
1859 * I _think_ this function is intended to work around the Pentium
1860 * fdiv bug.
1862 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1864 TRACE("(): stub\n");
1867 /***********************************************************************
1868 * _adj_fpatan (MSVCRT.@)
1869 * FIXME
1870 * This function is likely to have the wrong number of arguments.
1872 * NOTE
1873 * I _think_ this function is intended to work around the Pentium
1874 * fdiv bug.
1876 void _adj_fpatan(void)
1878 TRACE("(): stub\n");
1881 /***********************************************************************
1882 * _adj_fprem (MSVCRT.@)
1883 * FIXME
1884 * This function is likely to have the wrong number of arguments.
1886 * NOTE
1887 * I _think_ this function is intended to work around the Pentium
1888 * fdiv bug.
1890 void _adj_fprem(void)
1892 TRACE("(): stub\n");
1895 /***********************************************************************
1896 * _adj_fprem1 (MSVCRT.@)
1897 * FIXME
1898 * This function is likely to have the wrong number of arguments.
1900 * NOTE
1901 * I _think_ this function is intended to work around the Pentium
1902 * fdiv bug.
1904 void _adj_fprem1(void)
1906 TRACE("(): stub\n");
1909 /***********************************************************************
1910 * _adj_fptan (MSVCRT.@)
1911 * FIXME
1912 * This function is likely to have the wrong number of arguments.
1914 * NOTE
1915 * I _think_ this function is intended to work around the Pentium
1916 * fdiv bug.
1918 void _adj_fptan(void)
1920 TRACE("(): stub\n");
1923 /***********************************************************************
1924 * _safe_fdiv (MSVCRT.@)
1925 * FIXME
1926 * This function is likely to have the wrong number of arguments.
1928 * NOTE
1929 * I _think_ this function is intended to work around the Pentium
1930 * fdiv bug.
1932 void _safe_fdiv(void)
1934 TRACE("(): stub\n");
1937 /***********************************************************************
1938 * _safe_fdivr (MSVCRT.@)
1939 * FIXME
1940 * This function is likely to have the wrong number of arguments.
1942 * NOTE
1943 * I _think_ this function is intended to work around the Pentium
1944 * fdiv bug.
1946 void _safe_fdivr(void)
1948 TRACE("(): stub\n");
1951 /***********************************************************************
1952 * _safe_fprem (MSVCRT.@)
1953 * FIXME
1954 * This function is likely to have the wrong number of arguments.
1956 * NOTE
1957 * I _think_ this function is intended to work around the Pentium
1958 * fdiv bug.
1960 void _safe_fprem(void)
1962 TRACE("(): stub\n");
1965 /***********************************************************************
1966 * _safe_fprem1 (MSVCRT.@)
1968 * FIXME
1969 * This function is likely to have the wrong number of arguments.
1971 * NOTE
1972 * I _think_ this function is intended to work around the Pentium
1973 * fdiv bug.
1975 void _safe_fprem1(void)
1977 TRACE("(): stub\n");
1980 /***********************************************************************
1981 * __libm_sse2_acos (MSVCRT.@)
1983 void __cdecl __libm_sse2_acos(void)
1985 double d;
1986 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1987 d = acos( d );
1988 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
1991 /***********************************************************************
1992 * __libm_sse2_acosf (MSVCRT.@)
1994 void __cdecl __libm_sse2_acosf(void)
1996 float f;
1997 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
1998 f = acosf( f );
1999 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2002 /***********************************************************************
2003 * __libm_sse2_asin (MSVCRT.@)
2005 void __cdecl __libm_sse2_asin(void)
2007 double d;
2008 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2009 d = asin( d );
2010 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2013 /***********************************************************************
2014 * __libm_sse2_asinf (MSVCRT.@)
2016 void __cdecl __libm_sse2_asinf(void)
2018 float f;
2019 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2020 f = asinf( f );
2021 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2024 /***********************************************************************
2025 * __libm_sse2_atan (MSVCRT.@)
2027 void __cdecl __libm_sse2_atan(void)
2029 double d;
2030 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2031 d = atan( d );
2032 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2035 /***********************************************************************
2036 * __libm_sse2_atan2 (MSVCRT.@)
2038 void __cdecl __libm_sse2_atan2(void)
2040 double d1, d2;
2041 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2042 d1 = atan2( d1, d2 );
2043 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2046 /***********************************************************************
2047 * __libm_sse2_atanf (MSVCRT.@)
2049 void __cdecl __libm_sse2_atanf(void)
2051 float f;
2052 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2053 f = atanf( f );
2054 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2057 /***********************************************************************
2058 * __libm_sse2_cos (MSVCRT.@)
2060 void __cdecl __libm_sse2_cos(void)
2062 double d;
2063 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2064 d = cos( d );
2065 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2068 /***********************************************************************
2069 * __libm_sse2_cosf (MSVCRT.@)
2071 void __cdecl __libm_sse2_cosf(void)
2073 float f;
2074 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2075 f = cosf( f );
2076 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2079 /***********************************************************************
2080 * __libm_sse2_exp (MSVCRT.@)
2082 void __cdecl __libm_sse2_exp(void)
2084 double d;
2085 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2086 d = exp( d );
2087 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2090 /***********************************************************************
2091 * __libm_sse2_expf (MSVCRT.@)
2093 void __cdecl __libm_sse2_expf(void)
2095 float f;
2096 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2097 f = expf( f );
2098 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2101 /***********************************************************************
2102 * __libm_sse2_log (MSVCRT.@)
2104 void __cdecl __libm_sse2_log(void)
2106 double d;
2107 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2108 d = log( d );
2109 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2112 /***********************************************************************
2113 * __libm_sse2_log10 (MSVCRT.@)
2115 void __cdecl __libm_sse2_log10(void)
2117 double d;
2118 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2119 d = log10( d );
2120 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2123 /***********************************************************************
2124 * __libm_sse2_log10f (MSVCRT.@)
2126 void __cdecl __libm_sse2_log10f(void)
2128 float f;
2129 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2130 f = log10f( f );
2131 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2134 /***********************************************************************
2135 * __libm_sse2_logf (MSVCRT.@)
2137 void __cdecl __libm_sse2_logf(void)
2139 float f;
2140 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2141 f = logf( f );
2142 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2145 /***********************************************************************
2146 * __libm_sse2_pow (MSVCRT.@)
2148 void __cdecl __libm_sse2_pow(void)
2150 double d1, d2;
2151 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2152 d1 = pow( d1, d2 );
2153 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2156 /***********************************************************************
2157 * __libm_sse2_powf (MSVCRT.@)
2159 void __cdecl __libm_sse2_powf(void)
2161 float f1, f2;
2162 __asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
2163 f1 = powf( f1, f2 );
2164 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
2167 /***********************************************************************
2168 * __libm_sse2_sin (MSVCRT.@)
2170 void __cdecl __libm_sse2_sin(void)
2172 double d;
2173 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2174 d = sin( d );
2175 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2178 /***********************************************************************
2179 * __libm_sse2_sinf (MSVCRT.@)
2181 void __cdecl __libm_sse2_sinf(void)
2183 float f;
2184 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2185 f = sinf( f );
2186 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2189 /***********************************************************************
2190 * __libm_sse2_tan (MSVCRT.@)
2192 void __cdecl __libm_sse2_tan(void)
2194 double d;
2195 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2196 d = tan( d );
2197 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2200 /***********************************************************************
2201 * __libm_sse2_tanf (MSVCRT.@)
2203 void __cdecl __libm_sse2_tanf(void)
2205 float f;
2206 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2207 f = tanf( f );
2208 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2211 /***********************************************************************
2212 * __libm_sse2_sqrt_precise (MSVCR110.@)
2214 void __cdecl __libm_sse2_sqrt_precise(void)
2216 double d;
2217 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2218 d = sqrt( d );
2219 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2222 #endif /* __i386__ */
2224 /*********************************************************************
2225 * cbrt (MSVCR120.@)
2227 double CDECL MSVCR120_cbrt(double x)
2229 #ifdef HAVE_CBRT
2230 return cbrt(x);
2231 #else
2232 return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
2233 #endif
2236 /*********************************************************************
2237 * cbrtf (MSVCR120.@)
2239 float CDECL MSVCR120_cbrtf(float x)
2241 #ifdef HAVE_CBRTF
2242 return cbrtf(x);
2243 #else
2244 return MSVCR120_cbrt(x);
2245 #endif
2248 /*********************************************************************
2249 * cbrtl (MSVCR120.@)
2251 LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
2253 return MSVCR120_cbrt(x);
2256 /*********************************************************************
2257 * exp2 (MSVCR120.@)
2259 double CDECL MSVCR120_exp2(double x)
2261 #ifdef HAVE_EXP2
2262 return exp2(x);
2263 #else
2264 return pow(2, x);
2265 #endif
2268 /*********************************************************************
2269 * exp2f (MSVCR120.@)
2271 float CDECL MSVCR120_exp2f(float x)
2273 #ifdef HAVE_EXP2F
2274 return exp2f(x);
2275 #else
2276 return MSVCR120_exp2(x);
2277 #endif
2280 /*********************************************************************
2281 * exp2l (MSVCR120.@)
2283 LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
2285 return MSVCR120_exp2(x);
2288 /*********************************************************************
2289 * log2 (MSVCR120.@)
2291 double CDECL MSVCR120_log2(double x)
2293 #ifdef HAVE_LOG2
2294 return log2(x);
2295 #else
2296 return log(x) / log(2);
2297 #endif
2300 /*********************************************************************
2301 * log2f (MSVCR120.@)
2303 float CDECL MSVCR120_log2f(float x)
2305 #ifdef HAVE_LOG2F
2306 return log2f(x);
2307 #else
2308 return MSVCR120_log2(x);
2309 #endif
2312 /*********************************************************************
2313 * log2l (MSVCR120.@)
2315 LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
2317 return MSVCR120_log2(x);
2320 /*********************************************************************
2321 * rint (MSVCR120.@)
2323 double CDECL MSVCR120_rint(double x)
2325 #ifdef HAVE_RINT
2326 return rint(x);
2327 #else
2328 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
2329 #endif
2332 /*********************************************************************
2333 * rintf (MSVCR120.@)
2335 float CDECL MSVCR120_rintf(float x)
2337 #ifdef HAVE_RINTF
2338 return rintf(x);
2339 #else
2340 return MSVCR120_rint(x);
2341 #endif
2344 /*********************************************************************
2345 * rintl (MSVCR120.@)
2347 LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
2349 return MSVCR120_rint(x);
2352 /*********************************************************************
2353 * lrint (MSVCR120.@)
2355 MSVCRT_long CDECL MSVCR120_lrint(double x)
2357 #ifdef HAVE_LRINT
2358 return lrint(x);
2359 #else
2360 return MSVCR120_rint(x);
2361 #endif
2364 /*********************************************************************
2365 * lrintf (MSVCR120.@)
2367 MSVCRT_long CDECL MSVCR120_lrintf(float x)
2369 #ifdef HAVE_LRINTF
2370 return lrintf(x);
2371 #else
2372 return MSVCR120_lrint(x);
2373 #endif
2376 /*********************************************************************
2377 * lrintl (MSVCR120.@)
2379 MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
2381 return MSVCR120_lrint(x);
2384 /*********************************************************************
2385 * llrint (MSVCR120.@)
2387 MSVCRT_longlong CDECL MSVCR120_llrint(double x)
2389 #ifdef HAVE_LLRINT
2390 return llrint(x);
2391 #else
2392 return MSVCR120_rint(x);
2393 #endif
2396 /*********************************************************************
2397 * llrintf (MSVCR120.@)
2399 MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
2401 #ifdef HAVE_LLRINTF
2402 return llrintf(x);
2403 #else
2404 return MSVCR120_llrint(x);
2405 #endif
2408 /*********************************************************************
2409 * rintl (MSVCR120.@)
2411 MSVCRT_longlong CDECL MSVCR120_llrintl(LDOUBLE x)
2413 return MSVCR120_llrint(x);
2416 /*********************************************************************
2417 * round (MSVCR120.@)
2419 double CDECL MSVCR120_round(double x)
2421 #ifdef HAVE_ROUND
2422 return round(x);
2423 #else
2424 return MSVCR120_rint(x);
2425 #endif
2428 /*********************************************************************
2429 * roundf (MSVCR120.@)
2431 float CDECL MSVCR120_roundf(float x)
2433 #ifdef HAVE_ROUNDF
2434 return roundf(x);
2435 #else
2436 return MSVCR120_round(x);
2437 #endif
2440 /*********************************************************************
2441 * roundl (MSVCR120.@)
2443 LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
2445 return MSVCR120_round(x);
2448 /*********************************************************************
2449 * lround (MSVCR120.@)
2451 MSVCRT_long CDECL MSVCR120_lround(double x)
2453 #ifdef HAVE_LROUND
2454 return lround(x);
2455 #else
2456 return MSVCR120_round(x);
2457 #endif
2460 /*********************************************************************
2461 * lroundf (MSVCR120.@)
2463 MSVCRT_long CDECL MSVCR120_lroundf(float x)
2465 #ifdef HAVE_LROUNDF
2466 return lroundf(x);
2467 #else
2468 return MSVCR120_lround(x);
2469 #endif
2472 /*********************************************************************
2473 * lroundl (MSVCR120.@)
2475 MSVCRT_long CDECL MSVCR120_lroundl(LDOUBLE x)
2477 return MSVCR120_lround(x);
2480 /*********************************************************************
2481 * llround (MSVCR120.@)
2483 MSVCRT_longlong CDECL MSVCR120_llround(double x)
2485 #ifdef HAVE_LLROUND
2486 return llround(x);
2487 #else
2488 return MSVCR120_round(x);
2489 #endif
2492 /*********************************************************************
2493 * llroundf (MSVCR120.@)
2495 MSVCRT_longlong CDECL MSVCR120_llroundf(float x)
2497 #ifdef HAVE_LLROUNDF
2498 return llroundf(x);
2499 #else
2500 return MSVCR120_llround(x);
2501 #endif
2504 /*********************************************************************
2505 * roundl (MSVCR120.@)
2507 MSVCRT_longlong CDECL MSVCR120_llroundl(LDOUBLE x)
2509 return MSVCR120_llround(x);
2512 /*********************************************************************
2513 * trunc (MSVCR120.@)
2515 double CDECL MSVCR120_trunc(double x)
2517 #ifdef HAVE_TRUNC
2518 return trunc(x);
2519 #else
2520 return (x > 0) ? floor(x) : ceil(x);
2521 #endif
2524 /*********************************************************************
2525 * truncf (MSVCR120.@)
2527 float CDECL MSVCR120_truncf(float x)
2529 #ifdef HAVE_TRUNCF
2530 return truncf(x);
2531 #else
2532 return MSVCR120_trunc(x);
2533 #endif
2536 /*********************************************************************
2537 * truncl (MSVCR120.@)
2539 LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
2541 return MSVCR120_trunc(x);
2544 /*********************************************************************
2545 * _dclass (MSVCR120.@)
2547 short CDECL MSVCR120__dclass(double x)
2549 switch (MSVCRT__fpclass(x)) {
2550 case MSVCRT__FPCLASS_QNAN:
2551 case MSVCRT__FPCLASS_SNAN:
2552 return MSVCRT_FP_NAN;
2553 case MSVCRT__FPCLASS_NINF:
2554 case MSVCRT__FPCLASS_PINF:
2555 return MSVCRT_FP_INFINITE;
2556 case MSVCRT__FPCLASS_ND:
2557 case MSVCRT__FPCLASS_PD:
2558 return MSVCRT_FP_SUBNORMAL;
2559 case MSVCRT__FPCLASS_NN:
2560 case MSVCRT__FPCLASS_PN:
2561 default:
2562 return MSVCRT_FP_NORMAL;
2563 case MSVCRT__FPCLASS_NZ:
2564 case MSVCRT__FPCLASS_PZ:
2565 return MSVCRT_FP_ZERO;
2569 /*********************************************************************
2570 * _fdclass (MSVCR120.@)
2572 short CDECL MSVCR120__fdclass(float x)
2574 return MSVCR120__dclass(x);
2577 /*********************************************************************
2578 * _ldclass (MSVCR120.@)
2580 short CDECL MSVCR120__ldclass(LDOUBLE x)
2582 return MSVCR120__dclass(x);
2585 /*********************************************************************
2586 * _dtest (MSVCR120.@)
2588 short CDECL MSVCR120__dtest(double *x)
2590 return MSVCR120__dclass(*x);
2593 /*********************************************************************
2594 * _fdtest (MSVCR120.@)
2596 short CDECL MSVCR120__fdtest(float *x)
2598 return MSVCR120__dclass(*x);
2601 /*********************************************************************
2602 * _ldtest (MSVCR120.@)
2604 short CDECL MSVCR120__ldtest(LDOUBLE *x)
2606 return MSVCR120__dclass(*x);
2609 /*********************************************************************
2610 * erff (MSVCR120.@)
2612 float CDECL MSVCR120_erff(float x)
2614 #ifdef HAVE_ERFF
2615 return erff(x);
2616 #else
2617 FIXME( "not implemented\n" );
2618 return 0.0f;
2619 #endif
2622 /*********************************************************************
2623 * erf (MSVCR120.@)
2625 double CDECL MSVCR120_erf(double x)
2627 #ifdef HAVE_ERF
2628 return erf(x);
2629 #else
2630 FIXME( "not implemented\n" );
2631 return 0.0;
2632 #endif
2635 /*********************************************************************
2636 * erfl (MSVCR120.@)
2638 LDOUBLE CDECL MSVCR120_erfl(LDOUBLE x)
2640 return MSVCR120_erf(x);
2643 /*********************************************************************
2644 * fmaxf (MSVCR120.@)
2646 float CDECL MSVCR120_fmaxf(float x, float y)
2648 if(isnanf(x))
2649 return y;
2650 if(isnanf(y))
2651 return x;
2652 if(x==0 && y==0)
2653 return signbit(x) ? y : x;
2654 return x<y ? y : x;
2657 /*********************************************************************
2658 * fmax (MSVCR120.@)
2660 double CDECL MSVCR120_fmax(double x, double y)
2662 if(isnan(x))
2663 return y;
2664 if(isnan(y))
2665 return x;
2666 if(x==0 && y==0)
2667 return signbit(x) ? y : x;
2668 return x<y ? y : x;
2671 /*********************************************************************
2672 * _fdsign (MSVCR120.@)
2674 int CDECL MSVCR120__fdsign(float x)
2676 return signbit(x) ? 0x8000 : 0;
2679 /*********************************************************************
2680 * _dsign (MSVCR120.@)
2682 int CDECL MSVCR120__dsign(double x)
2684 return signbit(x) ? 0x8000 : 0;
2687 /*********************************************************************
2688 * fminf (MSVCR120.@)
2690 float CDECL MSVCR120_fminf(float x, float y)
2692 if(isnanf(x))
2693 return y;
2694 if(isnanf(y))
2695 return x;
2696 if(x==0 && y==0)
2697 return signbit(x) ? x : y;
2698 return x<y ? x : y;
2701 /*********************************************************************
2702 * fmin (MSVCR120.@)
2704 double CDECL MSVCR120_fmin(double x, double y)
2706 if(isnan(x))
2707 return y;
2708 if(isnan(y))
2709 return x;
2710 if(x==0 && y==0)
2711 return signbit(x) ? x : y;
2712 return x<y ? x : y;