winemac: Prevent maximized windows from entering Cocoa full-screen mode.
[wine/multimedia.git] / dlls / msvcrt / math.c
blobacac35d18b64dee296fc11f3b4debe98e4c2199c
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 #ifndef signbit
50 #define signbit(x) 0
51 #endif
53 typedef int (CDECL *MSVCRT_matherr_func)(struct MSVCRT__exception *);
54 typedef double LDOUBLE; /* long double is just a double */
56 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
58 static BOOL sse2_supported;
59 static BOOL sse2_enabled;
61 void msvcrt_init_math(void)
63 sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
66 /*********************************************************************
67 * _set_SSE2_enable (MSVCRT.@)
69 int CDECL MSVCRT__set_SSE2_enable(int flag)
71 sse2_enabled = flag && sse2_supported;
72 return sse2_enabled;
75 #if defined(__x86_64__) || defined(__arm__)
77 /*********************************************************************
78 * _chgsignf (MSVCRT.@)
80 float CDECL MSVCRT__chgsignf( float num )
82 /* FIXME: +-infinity,Nan not tested */
83 return -num;
86 /*********************************************************************
87 * _copysignf (MSVCRT.@)
89 float CDECL MSVCRT__copysignf( float num, float sign )
91 /* FIXME: Behaviour for Nan/Inf? */
92 if (sign < 0.0)
93 return num < 0.0 ? num : -num;
94 return num < 0.0 ? -num : num;
97 /*********************************************************************
98 * _finitef (MSVCRT.@)
100 int CDECL MSVCRT__finitef( float num )
102 return finitef(num) != 0; /* See comment for _isnan() */
105 /*********************************************************************
106 * _isnanf (MSVCRT.@)
108 INT CDECL MSVCRT__isnanf( float num )
110 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
111 * Do the same, as the result may be used in calculations
113 return isnanf(num) != 0;
116 /*********************************************************************
117 * _logbf (MSVCRT.@)
119 float CDECL MSVCRT__logbf( float num )
121 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
122 return logbf(num);
125 /*********************************************************************
126 * _nextafterf (MSVCRT.@)
128 float CDECL MSVCRT__nextafterf( float num, float next )
130 if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM;
131 return nextafterf( num, next );
134 /*********************************************************************
135 * MSVCRT_acosf (MSVCRT.@)
137 float CDECL MSVCRT_acosf( float x )
139 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
140 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
141 * asin() uses a similar construction. This is bad because as x gets nearer to
142 * 1 the error in the expression "1 - x^2" can get relatively large due to
143 * cancellation. The sqrt() makes things worse. A safer way to calculate
144 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
145 return atan2f(sqrtf((1 - x) * (1 + x)), x);
148 /*********************************************************************
149 * MSVCRT_asinf (MSVCRT.@)
151 float CDECL MSVCRT_asinf( float x )
153 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
154 return atan2f(x, sqrtf((1 - x) * (1 + x)));
157 /*********************************************************************
158 * MSVCRT_atanf (MSVCRT.@)
160 float CDECL MSVCRT_atanf( float x )
162 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
163 return atanf(x);
166 /*********************************************************************
167 * MSVCRT_atan2f (MSVCRT.@)
169 float CDECL MSVCRT_atan2f( float x, float y )
171 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
172 return atan2f(x,y);
175 /*********************************************************************
176 * MSVCRT_cosf (MSVCRT.@)
178 float CDECL MSVCRT_cosf( float x )
180 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
181 return cosf(x);
184 /*********************************************************************
185 * MSVCRT_coshf (MSVCRT.@)
187 float CDECL MSVCRT_coshf( float x )
189 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
190 return coshf(x);
193 /*********************************************************************
194 * MSVCRT_expf (MSVCRT.@)
196 float CDECL MSVCRT_expf( float x )
198 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
199 return expf(x);
202 /*********************************************************************
203 * MSVCRT_fmodf (MSVCRT.@)
205 float CDECL MSVCRT_fmodf( float x, float y )
207 if (!finitef(x) || !finitef(y)) *MSVCRT__errno() = MSVCRT_EDOM;
208 return fmodf(x,y);
211 /*********************************************************************
212 * MSVCRT_logf (MSVCRT.@)
214 float CDECL MSVCRT_logf( float x)
216 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
217 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
218 return logf(x);
221 /*********************************************************************
222 * MSVCRT_log10f (MSVCRT.@)
224 float CDECL MSVCRT_log10f( float x )
226 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
227 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
228 return log10f(x);
231 /*********************************************************************
232 * MSVCRT_powf (MSVCRT.@)
234 float CDECL MSVCRT_powf( float x, float y )
236 /* FIXME: If x < 0 and y is not integral, set EDOM */
237 float z = powf(x,y);
238 if (!finitef(z)) *MSVCRT__errno() = MSVCRT_EDOM;
239 return z;
242 /*********************************************************************
243 * MSVCRT_sinf (MSVCRT.@)
245 float CDECL MSVCRT_sinf( float x )
247 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
248 return sinf(x);
251 /*********************************************************************
252 * MSVCRT_sinhf (MSVCRT.@)
254 float CDECL MSVCRT_sinhf( float x )
256 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
257 return sinhf(x);
260 /*********************************************************************
261 * MSVCRT_sqrtf (MSVCRT.@)
263 float CDECL MSVCRT_sqrtf( float x )
265 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
266 return sqrtf(x);
269 /*********************************************************************
270 * MSVCRT_tanf (MSVCRT.@)
272 float CDECL MSVCRT_tanf( float x )
274 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
275 return tanf(x);
278 /*********************************************************************
279 * MSVCRT_tanhf (MSVCRT.@)
281 float CDECL MSVCRT_tanhf( float x )
283 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
284 return tanhf(x);
287 /*********************************************************************
288 * ceilf (MSVCRT.@)
290 float CDECL MSVCRT_ceilf( float x )
292 return ceilf(x);
295 /*********************************************************************
296 * fabsf (MSVCRT.@)
298 float CDECL MSVCRT_fabsf( float x )
300 return fabsf(x);
303 /*********************************************************************
304 * floorf (MSVCRT.@)
306 float CDECL MSVCRT_floorf( float x )
308 return floorf(x);
311 /*********************************************************************
312 * frexpf (MSVCRT.@)
314 float CDECL MSVCRT_frexpf( float x, int *exp )
316 return frexpf( x, exp );
319 /*********************************************************************
320 * _scalbf (MSVCRT.@)
322 float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
324 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
325 return ldexpf(num, power);
328 /*********************************************************************
329 * modff (MSVCRT.@)
331 double CDECL MSVCRT_modff( float x, float *iptr )
333 return modff( x, iptr );
336 #endif
338 /*********************************************************************
339 * MSVCRT_acos (MSVCRT.@)
341 double CDECL MSVCRT_acos( double x )
343 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
344 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
345 * asin() uses a similar construction. This is bad because as x gets nearer to
346 * 1 the error in the expression "1 - x^2" can get relatively large due to
347 * cancellation. The sqrt() makes things worse. A safer way to calculate
348 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
349 return atan2(sqrt((1 - x) * (1 + x)), x);
352 /*********************************************************************
353 * MSVCRT_asin (MSVCRT.@)
355 double CDECL MSVCRT_asin( double x )
357 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
358 return atan2(x, sqrt((1 - x) * (1 + x)));
361 /*********************************************************************
362 * MSVCRT_atan (MSVCRT.@)
364 double CDECL MSVCRT_atan( double x )
366 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
367 return atan(x);
370 /*********************************************************************
371 * MSVCRT_atan2 (MSVCRT.@)
373 double CDECL MSVCRT_atan2( double x, double y )
375 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
376 return atan2(x,y);
379 /*********************************************************************
380 * MSVCRT_cos (MSVCRT.@)
382 double CDECL MSVCRT_cos( double x )
384 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
385 return cos(x);
388 /*********************************************************************
389 * MSVCRT_cosh (MSVCRT.@)
391 double CDECL MSVCRT_cosh( double x )
393 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
394 return cosh(x);
397 /*********************************************************************
398 * MSVCRT_exp (MSVCRT.@)
400 double CDECL MSVCRT_exp( double x )
402 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
403 return exp(x);
406 /*********************************************************************
407 * MSVCRT_fmod (MSVCRT.@)
409 double CDECL MSVCRT_fmod( double x, double y )
411 if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
412 return fmod(x,y);
415 /*********************************************************************
416 * MSVCRT_log (MSVCRT.@)
418 double CDECL MSVCRT_log( double x)
420 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
421 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
422 return log(x);
425 /*********************************************************************
426 * MSVCRT_log10 (MSVCRT.@)
428 double CDECL MSVCRT_log10( double x )
430 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
431 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
432 return log10(x);
435 /*********************************************************************
436 * MSVCRT_pow (MSVCRT.@)
438 double CDECL MSVCRT_pow( double x, double y )
440 /* FIXME: If x < 0 and y is not integral, set EDOM */
441 double z = pow(x,y);
442 if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
443 return z;
446 /*********************************************************************
447 * MSVCRT_sin (MSVCRT.@)
449 double CDECL MSVCRT_sin( double x )
451 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
452 return sin(x);
455 /*********************************************************************
456 * MSVCRT_sinh (MSVCRT.@)
458 double CDECL MSVCRT_sinh( double x )
460 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
461 return sinh(x);
464 /*********************************************************************
465 * MSVCRT_sqrt (MSVCRT.@)
467 double CDECL MSVCRT_sqrt( double x )
469 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
470 return sqrt(x);
473 /*********************************************************************
474 * MSVCRT_tan (MSVCRT.@)
476 double CDECL MSVCRT_tan( double x )
478 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
479 return tan(x);
482 /*********************************************************************
483 * MSVCRT_tanh (MSVCRT.@)
485 double CDECL MSVCRT_tanh( double x )
487 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
488 return tanh(x);
492 #if defined(__GNUC__) && defined(__i386__)
494 #define FPU_DOUBLE(var) double var; \
495 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
496 #define FPU_DOUBLES(var1,var2) double var1,var2; \
497 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
498 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
500 /*********************************************************************
501 * _CIacos (MSVCRT.@)
503 double CDECL _CIacos(void)
505 FPU_DOUBLE(x);
506 return MSVCRT_acos(x);
509 /*********************************************************************
510 * _CIasin (MSVCRT.@)
512 double CDECL _CIasin(void)
514 FPU_DOUBLE(x);
515 return MSVCRT_asin(x);
518 /*********************************************************************
519 * _CIatan (MSVCRT.@)
521 double CDECL _CIatan(void)
523 FPU_DOUBLE(x);
524 return MSVCRT_atan(x);
527 /*********************************************************************
528 * _CIatan2 (MSVCRT.@)
530 double CDECL _CIatan2(void)
532 FPU_DOUBLES(x,y);
533 return MSVCRT_atan2(x,y);
536 /*********************************************************************
537 * _CIcos (MSVCRT.@)
539 double CDECL _CIcos(void)
541 FPU_DOUBLE(x);
542 return MSVCRT_cos(x);
545 /*********************************************************************
546 * _CIcosh (MSVCRT.@)
548 double CDECL _CIcosh(void)
550 FPU_DOUBLE(x);
551 return MSVCRT_cosh(x);
554 /*********************************************************************
555 * _CIexp (MSVCRT.@)
557 double CDECL _CIexp(void)
559 FPU_DOUBLE(x);
560 return MSVCRT_exp(x);
563 /*********************************************************************
564 * _CIfmod (MSVCRT.@)
566 double CDECL _CIfmod(void)
568 FPU_DOUBLES(x,y);
569 return MSVCRT_fmod(x,y);
572 /*********************************************************************
573 * _CIlog (MSVCRT.@)
575 double CDECL _CIlog(void)
577 FPU_DOUBLE(x);
578 return MSVCRT_log(x);
581 /*********************************************************************
582 * _CIlog10 (MSVCRT.@)
584 double CDECL _CIlog10(void)
586 FPU_DOUBLE(x);
587 return MSVCRT_log10(x);
590 /*********************************************************************
591 * _CIpow (MSVCRT.@)
593 double CDECL _CIpow(void)
595 FPU_DOUBLES(x,y);
596 return MSVCRT_pow(x,y);
599 /*********************************************************************
600 * _CIsin (MSVCRT.@)
602 double CDECL _CIsin(void)
604 FPU_DOUBLE(x);
605 return MSVCRT_sin(x);
608 /*********************************************************************
609 * _CIsinh (MSVCRT.@)
611 double CDECL _CIsinh(void)
613 FPU_DOUBLE(x);
614 return MSVCRT_sinh(x);
617 /*********************************************************************
618 * _CIsqrt (MSVCRT.@)
620 double CDECL _CIsqrt(void)
622 FPU_DOUBLE(x);
623 return MSVCRT_sqrt(x);
626 /*********************************************************************
627 * _CItan (MSVCRT.@)
629 double CDECL _CItan(void)
631 FPU_DOUBLE(x);
632 return MSVCRT_tan(x);
635 /*********************************************************************
636 * _CItanh (MSVCRT.@)
638 double CDECL _CItanh(void)
640 FPU_DOUBLE(x);
641 return MSVCRT_tanh(x);
644 /*********************************************************************
645 * _ftol (MSVCRT.@)
647 LONGLONG CDECL MSVCRT__ftol(void)
649 FPU_DOUBLE(x);
650 return (LONGLONG)x;
653 #endif /* defined(__GNUC__) && defined(__i386__) */
655 /*********************************************************************
656 * _fpclass (MSVCRT.@)
658 int CDECL MSVCRT__fpclass(double num)
660 #if defined(HAVE_FPCLASS) || defined(fpclass)
661 switch (fpclass( num ))
663 #ifdef FP_SNAN
664 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
665 #endif
666 #ifdef FP_QNAN
667 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
668 #endif
669 #ifdef FP_NINF
670 case FP_NINF: return MSVCRT__FPCLASS_NINF;
671 #endif
672 #ifdef FP_PINF
673 case FP_PINF: return MSVCRT__FPCLASS_PINF;
674 #endif
675 #ifdef FP_NDENORM
676 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
677 #endif
678 #ifdef FP_PDENORM
679 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
680 #endif
681 #ifdef FP_NZERO
682 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
683 #endif
684 #ifdef FP_PZERO
685 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
686 #endif
687 #ifdef FP_NNORM
688 case FP_NNORM: return MSVCRT__FPCLASS_NN;
689 #endif
690 #ifdef FP_PNORM
691 case FP_PNORM: return MSVCRT__FPCLASS_PN;
692 #endif
693 default: return MSVCRT__FPCLASS_PN;
695 #elif defined (fpclassify)
696 switch (fpclassify( num ))
698 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
699 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
700 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
701 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
703 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
704 #else
705 if (!isfinite(num))
706 return MSVCRT__FPCLASS_QNAN;
707 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
708 #endif
711 /*********************************************************************
712 * _rotl (MSVCRT.@)
714 unsigned int CDECL _rotl(unsigned int num, int shift)
716 shift &= 31;
717 return (num << shift) | (num >> (32-shift));
720 /*********************************************************************
721 * _lrotl (MSVCRT.@)
723 MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
725 shift &= 0x1f;
726 return (num << shift) | (num >> (32-shift));
729 /*********************************************************************
730 * _lrotr (MSVCRT.@)
732 MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
734 shift &= 0x1f;
735 return (num >> shift) | (num << (32-shift));
738 /*********************************************************************
739 * _rotr (MSVCRT.@)
741 unsigned int CDECL _rotr(unsigned int num, int shift)
743 shift &= 0x1f;
744 return (num >> shift) | (num << (32-shift));
747 /*********************************************************************
748 * _rotl64 (MSVCRT.@)
750 unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
752 shift &= 63;
753 return (num << shift) | (num >> (64-shift));
756 /*********************************************************************
757 * _rotr64 (MSVCRT.@)
759 unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
761 shift &= 63;
762 return (num >> shift) | (num << (64-shift));
765 /*********************************************************************
766 * abs (MSVCRT.@)
768 int CDECL MSVCRT_abs( int n )
770 return n >= 0 ? n : -n;
773 /*********************************************************************
774 * labs (MSVCRT.@)
776 MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
778 return n >= 0 ? n : -n;
781 /*********************************************************************
782 * llabs (MSVCRT.@)
784 MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
786 return n >= 0 ? n : -n;
789 /*********************************************************************
790 * _abs64 (MSVCRT.@)
792 __int64 CDECL _abs64( __int64 n )
794 return n >= 0 ? n : -n;
797 /*********************************************************************
798 * _logb (MSVCRT.@)
800 double CDECL MSVCRT__logb(double num)
802 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
803 return logb(num);
806 /*********************************************************************
807 * _scalb (MSVCRT.@)
809 double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
811 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
812 return ldexp(num, power);
815 /*********************************************************************
816 * _hypot (MSVCRT.@)
818 double CDECL _hypot(double x, double y)
820 /* FIXME: errno handling */
821 return hypot( x, y );
824 /*********************************************************************
825 * _hypotf (MSVCRT.@)
827 float CDECL MSVCRT__hypotf(float x, float y)
829 /* FIXME: errno handling */
830 return hypotf( x, y );
833 /*********************************************************************
834 * ceil (MSVCRT.@)
836 double CDECL MSVCRT_ceil( double x )
838 return ceil(x);
841 /*********************************************************************
842 * floor (MSVCRT.@)
844 double CDECL MSVCRT_floor( double x )
846 return floor(x);
849 /*********************************************************************
850 * fabs (MSVCRT.@)
852 double CDECL MSVCRT_fabs( double x )
854 return fabs(x);
857 /*********************************************************************
858 * frexp (MSVCRT.@)
860 double CDECL MSVCRT_frexp( double x, int *exp )
862 return frexp( x, exp );
865 /*********************************************************************
866 * modf (MSVCRT.@)
868 double CDECL MSVCRT_modf( double x, double *iptr )
870 return modf( x, iptr );
873 /*********************************************************************
874 * _matherr (MSVCRT.@)
876 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
878 if (e)
879 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
880 e->retval);
881 else
882 TRACE("(null)\n");
883 if (MSVCRT_default_matherr_func)
884 return MSVCRT_default_matherr_func(e);
885 ERR(":Unhandled math error!\n");
886 return 0;
889 /*********************************************************************
890 * __setusermatherr (MSVCRT.@)
892 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
894 MSVCRT_default_matherr_func = func;
895 TRACE(":new matherr handler %p\n", func);
898 /**********************************************************************
899 * _statusfp2 (MSVCRT.@)
901 * Not exported by native msvcrt, added in msvcr80.
903 #if defined(__i386__) || defined(__x86_64__)
904 void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
906 #ifdef __GNUC__
907 unsigned int flags;
908 unsigned long fpword;
910 if (x86_sw)
912 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
913 flags = 0;
914 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
915 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
916 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
917 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
918 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
919 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
920 *x86_sw = flags;
923 if (!sse2_sw) return;
925 if (sse2_supported)
927 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
928 flags = 0;
929 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
930 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
931 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
932 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
933 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
934 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
935 *sse2_sw = flags;
937 else *sse2_sw = 0;
938 #else
939 FIXME( "not implemented\n" );
940 #endif
942 #endif
944 /**********************************************************************
945 * _statusfp (MSVCRT.@)
947 unsigned int CDECL _statusfp(void)
949 #if defined(__i386__) || defined(__x86_64__)
950 unsigned int x86_sw, sse2_sw;
952 _statusfp2( &x86_sw, &sse2_sw );
953 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
954 return x86_sw | sse2_sw;
955 #else
956 FIXME( "not implemented\n" );
957 return 0;
958 #endif
961 /*********************************************************************
962 * _clearfp (MSVCRT.@)
964 unsigned int CDECL _clearfp(void)
966 unsigned int flags = 0;
967 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
968 unsigned long fpword;
970 __asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
971 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
972 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
973 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
974 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
975 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
976 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
978 if (sse2_supported)
980 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
981 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
982 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
983 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
984 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
985 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
986 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
987 fpword &= ~0x3f;
988 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
990 #else
991 FIXME( "not implemented\n" );
992 #endif
993 return flags;
996 /*********************************************************************
997 * __fpecode (MSVCRT.@)
999 int * CDECL __fpecode(void)
1001 return &msvcrt_get_thread_data()->fpecode;
1004 /*********************************************************************
1005 * ldexp (MSVCRT.@)
1007 double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
1009 double z = ldexp(num,exp);
1011 if (!isfinite(z))
1012 *MSVCRT__errno() = MSVCRT_ERANGE;
1013 else if (z == 0 && signbit(z))
1014 z = 0.0; /* Convert -0 -> +0 */
1015 return z;
1018 /*********************************************************************
1019 * _cabs (MSVCRT.@)
1021 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
1023 return sqrt(num.x * num.x + num.y * num.y);
1026 /*********************************************************************
1027 * _chgsign (MSVCRT.@)
1029 double CDECL MSVCRT__chgsign(double num)
1031 /* FIXME: +-infinity,Nan not tested */
1032 return -num;
1035 /*********************************************************************
1036 * __control87_2 (MSVCRT.@)
1038 * Not exported by native msvcrt, added in msvcr80.
1040 #if defined(__i386__) || defined(__x86_64__)
1041 int CDECL __control87_2( unsigned int newval, unsigned int mask,
1042 unsigned int *x86_cw, unsigned int *sse2_cw )
1044 #ifdef __GNUC__
1045 unsigned long fpword;
1046 unsigned int flags;
1048 if (x86_cw)
1050 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
1052 /* Convert into mask constants */
1053 flags = 0;
1054 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
1055 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
1056 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
1057 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
1058 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
1059 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
1060 switch (fpword & 0xc00)
1062 case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1063 case 0x800: flags |= MSVCRT__RC_UP; break;
1064 case 0x400: flags |= MSVCRT__RC_DOWN; break;
1066 switch (fpword & 0x300)
1068 case 0x0: flags |= MSVCRT__PC_24; break;
1069 case 0x200: flags |= MSVCRT__PC_53; break;
1070 case 0x300: flags |= MSVCRT__PC_64; break;
1072 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
1074 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1075 if (mask)
1077 flags = (flags & ~mask) | (newval & mask);
1079 /* Convert (masked) value back to fp word */
1080 fpword = 0;
1081 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
1082 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
1083 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
1084 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
1085 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
1086 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
1087 switch (flags & MSVCRT__MCW_RC)
1089 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
1090 case MSVCRT__RC_UP: fpword |= 0x800; break;
1091 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
1093 switch (flags & MSVCRT__MCW_PC)
1095 case MSVCRT__PC_64: fpword |= 0x300; break;
1096 case MSVCRT__PC_53: fpword |= 0x200; break;
1097 case MSVCRT__PC_24: fpword |= 0x0; break;
1099 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
1101 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
1103 *x86_cw = flags;
1106 if (!sse2_cw) return 1;
1108 if (sse2_supported)
1110 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
1112 /* Convert into mask constants */
1113 flags = 0;
1114 if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
1115 if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
1116 if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
1117 if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
1118 if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
1119 if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
1120 switch (fpword & 0x6000)
1122 case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1123 case 0x4000: flags |= MSVCRT__RC_UP; break;
1124 case 0x2000: flags |= MSVCRT__RC_DOWN; break;
1126 switch (fpword & 0x8040)
1128 case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
1129 case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
1130 case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
1133 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1134 if (mask)
1136 flags = (flags & ~mask) | (newval & mask);
1138 /* Convert (masked) value back to fp word */
1139 fpword = 0;
1140 if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
1141 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
1142 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
1143 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
1144 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
1145 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
1146 switch (flags & MSVCRT__MCW_RC)
1148 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
1149 case MSVCRT__RC_UP: fpword |= 0x4000; break;
1150 case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
1152 switch (flags & MSVCRT__MCW_DN)
1154 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
1155 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
1156 case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
1158 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1160 *sse2_cw = flags;
1162 else *sse2_cw = 0;
1164 return 1;
1165 #else
1166 FIXME( "not implemented\n" );
1167 return 0;
1168 #endif
1170 #endif
1172 /*********************************************************************
1173 * _control87 (MSVCRT.@)
1175 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
1177 #if defined(__i386__) || defined(__x86_64__)
1178 unsigned int x86_cw, sse2_cw;
1180 __control87_2( newval, mask, &x86_cw, &sse2_cw );
1182 if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS;
1183 return x86_cw;
1184 #else
1185 FIXME( "not implemented\n" );
1186 return 0;
1187 #endif
1190 /*********************************************************************
1191 * _controlfp (MSVCRT.@)
1193 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
1195 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
1198 /*********************************************************************
1199 * _set_controlfp (MSVCRT.@)
1201 void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
1203 _controlfp( newval, mask );
1206 /*********************************************************************
1207 * _controlfp_s (MSVCRT.@)
1209 int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
1211 static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
1212 MSVCRT__MCW_PC | MSVCRT__MCW_DN);
1213 unsigned int val;
1215 if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
1217 if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
1218 return MSVCRT_EINVAL;
1220 val = _controlfp( newval, mask );
1221 if (cur) *cur = val;
1222 return 0;
1225 /*********************************************************************
1226 * _copysign (MSVCRT.@)
1228 double CDECL MSVCRT__copysign(double num, double sign)
1230 /* FIXME: Behaviour for Nan/Inf? */
1231 if (sign < 0.0)
1232 return num < 0.0 ? num : -num;
1233 return num < 0.0 ? -num : num;
1236 /*********************************************************************
1237 * _finite (MSVCRT.@)
1239 int CDECL MSVCRT__finite(double num)
1241 return isfinite(num) != 0; /* See comment for _isnan() */
1244 /*********************************************************************
1245 * _fpreset (MSVCRT.@)
1247 void CDECL _fpreset(void)
1249 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1250 const unsigned int x86_cw = 0x27f;
1251 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1252 if (sse2_supported)
1254 const unsigned long sse2_cw = 0x1f80;
1255 __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
1257 #else
1258 FIXME( "not implemented\n" );
1259 #endif
1262 /*********************************************************************
1263 * _isnan (MSVCRT.@)
1265 INT CDECL MSVCRT__isnan(double num)
1267 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1268 * Do the same, as the result may be used in calculations
1270 return isnan(num) != 0;
1273 /*********************************************************************
1274 * _j0 (MSVCRT.@)
1276 double CDECL MSVCRT__j0(double num)
1278 /* FIXME: errno handling */
1279 return j0(num);
1282 /*********************************************************************
1283 * _j1 (MSVCRT.@)
1285 double CDECL MSVCRT__j1(double num)
1287 /* FIXME: errno handling */
1288 return j1(num);
1291 /*********************************************************************
1292 * _jn (MSVCRT.@)
1294 double CDECL MSVCRT__jn(int n, double num)
1296 /* FIXME: errno handling */
1297 return jn(n, num);
1300 /*********************************************************************
1301 * _y0 (MSVCRT.@)
1303 double CDECL MSVCRT__y0(double num)
1305 double retval;
1306 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1307 retval = y0(num);
1308 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1310 *MSVCRT__errno() = MSVCRT_EDOM;
1311 retval = sqrt(-1);
1313 return retval;
1316 /*********************************************************************
1317 * _y1 (MSVCRT.@)
1319 double CDECL MSVCRT__y1(double num)
1321 double retval;
1322 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1323 retval = y1(num);
1324 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1326 *MSVCRT__errno() = MSVCRT_EDOM;
1327 retval = sqrt(-1);
1329 return retval;
1332 /*********************************************************************
1333 * _yn (MSVCRT.@)
1335 double CDECL MSVCRT__yn(int order, double num)
1337 double retval;
1338 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1339 retval = yn(order,num);
1340 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1342 *MSVCRT__errno() = MSVCRT_EDOM;
1343 retval = sqrt(-1);
1345 return retval;
1348 /*********************************************************************
1349 * _nextafter (MSVCRT.@)
1351 double CDECL MSVCRT__nextafter(double num, double next)
1353 double retval;
1354 if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
1355 retval = nextafter(num,next);
1356 return retval;
1359 /*********************************************************************
1360 * _ecvt (MSVCRT.@)
1362 char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
1364 int prec, len;
1365 thread_data_t *data = msvcrt_get_thread_data();
1366 /* FIXME: check better for overflow (native supports over 300 chars) */
1367 ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
1368 * 4 for exponent and one for
1369 * terminating '\0' */
1370 if (!data->efcvt_buffer)
1371 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1373 if( number < 0) {
1374 *sign = TRUE;
1375 number = -number;
1376 } else
1377 *sign = FALSE;
1378 /* handle cases with zero ndigits or less */
1379 prec = ndigits;
1380 if( prec < 1) prec = 2;
1381 len = snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
1382 /* take the decimal "point away */
1383 if( prec != 1)
1384 memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
1385 /* take the exponential "e" out */
1386 data->efcvt_buffer[ prec] = '\0';
1387 /* read the exponent */
1388 sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
1389 (*decpt)++;
1390 /* adjust for some border cases */
1391 if( data->efcvt_buffer[0] == '0')/* value is zero */
1392 *decpt = 0;
1393 /* handle cases with zero ndigits or less */
1394 if( ndigits < 1){
1395 if( data->efcvt_buffer[ 0] >= '5')
1396 (*decpt)++;
1397 data->efcvt_buffer[ 0] = '\0';
1399 TRACE("out=\"%s\"\n",data->efcvt_buffer);
1400 return data->efcvt_buffer;
1403 /*********************************************************************
1404 * _ecvt_s (MSVCRT.@)
1406 int CDECL MSVCRT__ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
1408 int prec, len;
1409 char *result;
1410 const char infret[] = "1#INF";
1412 if (!MSVCRT_CHECK_PMT(buffer != NULL)) return MSVCRT_EINVAL;
1413 if (!MSVCRT_CHECK_PMT(decpt != NULL)) return MSVCRT_EINVAL;
1414 if (!MSVCRT_CHECK_PMT(sign != NULL)) return MSVCRT_EINVAL;
1415 if (!MSVCRT_CHECK_PMT_ERR( length > 2, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1416 if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1418 /* special case - inf */
1419 if(number == HUGE_VAL || number == -HUGE_VAL)
1421 memset(buffer, '0', ndigits);
1422 memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
1423 buffer[ndigits] = '\0';
1424 (*decpt) = 1;
1425 if(number == -HUGE_VAL)
1426 (*sign) = 1;
1427 else
1428 (*sign) = 0;
1429 return 0;
1431 /* handle cases with zero ndigits or less */
1432 prec = ndigits;
1433 if( prec < 1) prec = 2;
1434 result = MSVCRT_malloc(prec + 7);
1436 if( number < 0) {
1437 *sign = TRUE;
1438 number = -number;
1439 } else
1440 *sign = FALSE;
1441 len = snprintf(result, prec + 7, "%.*le", prec - 1, number);
1442 /* take the decimal "point away */
1443 if( prec != 1)
1444 memmove( result + 1, result + 2, len - 1 );
1445 /* take the exponential "e" out */
1446 result[ prec] = '\0';
1447 /* read the exponent */
1448 sscanf( result + prec + 1, "%d", decpt);
1449 (*decpt)++;
1450 /* adjust for some border cases */
1451 if( result[0] == '0')/* value is zero */
1452 *decpt = 0;
1453 /* handle cases with zero ndigits or less */
1454 if( ndigits < 1){
1455 if( result[ 0] >= '5')
1456 (*decpt)++;
1457 result[ 0] = '\0';
1459 memcpy( buffer, result, max(ndigits + 1, 1) );
1460 MSVCRT_free( result );
1461 return 0;
1464 /***********************************************************************
1465 * _fcvt (MSVCRT.@)
1467 char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
1469 thread_data_t *data = msvcrt_get_thread_data();
1470 int stop, dec1, dec2;
1471 char *ptr1, *ptr2, *first;
1472 char buf[80]; /* ought to be enough */
1474 if (!data->efcvt_buffer)
1475 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1477 if (number < 0)
1479 *sign = 1;
1480 number = -number;
1481 } else *sign = 0;
1483 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1484 ptr1 = buf;
1485 ptr2 = data->efcvt_buffer;
1486 first = NULL;
1487 dec1 = 0;
1488 dec2 = 0;
1490 /* For numbers below the requested resolution, work out where
1491 the decimal point will be rather than finding it in the string */
1492 if (number < 1.0 && number > 0.0) {
1493 dec2 = log10(number + 1e-10);
1494 if (-dec2 <= ndigits) dec2 = 0;
1497 /* If requested digits is zero or less, we will need to truncate
1498 * the returned string */
1499 if (ndigits < 1) {
1500 stop = strlen(buf) + ndigits;
1501 } else {
1502 stop = strlen(buf);
1505 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1506 while (*ptr1 != '\0' && *ptr1 != '.') {
1507 if (!first) first = ptr2;
1508 if ((ptr1 - buf) < stop) {
1509 *ptr2++ = *ptr1++;
1510 } else {
1511 ptr1++;
1513 dec1++;
1516 if (ndigits > 0) {
1517 ptr1++;
1518 if (!first) {
1519 while (*ptr1 == '0') { /* Process leading zeroes */
1520 *ptr2++ = *ptr1++;
1521 dec1--;
1524 while (*ptr1 != '\0') {
1525 if (!first) first = ptr2;
1526 *ptr2++ = *ptr1++;
1530 *ptr2 = '\0';
1532 /* We never found a non-zero digit, then our number is either
1533 * smaller than the requested precision, or 0.0 */
1534 if (!first) {
1535 if (number > 0.0) {
1536 first = ptr2;
1537 } else {
1538 first = data->efcvt_buffer;
1539 dec1 = 0;
1543 *decpt = dec2 ? dec2 : dec1;
1544 return first;
1547 /***********************************************************************
1548 * _fcvt_s (MSVCRT.@)
1550 int CDECL MSVCRT__fcvt_s(char* outbuffer, MSVCRT_size_t size, double number, int ndigits, int *decpt, int *sign)
1552 int stop, dec1, dec2;
1553 char *ptr1, *ptr2, *first;
1554 char buf[80]; /* ought to be enough */
1556 if (!outbuffer || !decpt || !sign || size == 0)
1558 *MSVCRT__errno() = MSVCRT_EINVAL;
1559 return MSVCRT_EINVAL;
1562 if (number < 0)
1564 *sign = 1;
1565 number = -number;
1566 } else *sign = 0;
1568 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1569 ptr1 = buf;
1570 ptr2 = outbuffer;
1571 first = NULL;
1572 dec1 = 0;
1573 dec2 = 0;
1575 /* For numbers below the requested resolution, work out where
1576 the decimal point will be rather than finding it in the string */
1577 if (number < 1.0 && number > 0.0) {
1578 dec2 = log10(number + 1e-10);
1579 if (-dec2 <= ndigits) dec2 = 0;
1582 /* If requested digits is zero or less, we will need to truncate
1583 * the returned string */
1584 if (ndigits < 1) {
1585 stop = strlen(buf) + ndigits;
1586 } else {
1587 stop = strlen(buf);
1590 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1591 while (*ptr1 != '\0' && *ptr1 != '.') {
1592 if (!first) first = ptr2;
1593 if ((ptr1 - buf) < stop) {
1594 if (size > 1) {
1595 *ptr2++ = *ptr1++;
1596 size--;
1598 } else {
1599 ptr1++;
1601 dec1++;
1604 if (ndigits > 0) {
1605 ptr1++;
1606 if (!first) {
1607 while (*ptr1 == '0') { /* Process leading zeroes */
1608 if (number == 0.0 && size > 1) {
1609 *ptr2++ = '0';
1610 size--;
1612 ptr1++;
1613 dec1--;
1616 while (*ptr1 != '\0') {
1617 if (!first) first = ptr2;
1618 if (size > 1) {
1619 *ptr2++ = *ptr1++;
1620 size--;
1625 *ptr2 = '\0';
1627 /* We never found a non-zero digit, then our number is either
1628 * smaller than the requested precision, or 0.0 */
1629 if (!first && (number <= 0.0))
1630 dec1 = 0;
1632 *decpt = dec2 ? dec2 : dec1;
1633 return 0;
1636 /***********************************************************************
1637 * _gcvt (MSVCRT.@)
1639 char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
1641 if(!buff) {
1642 *MSVCRT__errno() = MSVCRT_EINVAL;
1643 return NULL;
1646 if(ndigit < 0) {
1647 *MSVCRT__errno() = MSVCRT_ERANGE;
1648 return NULL;
1651 MSVCRT_sprintf(buff, "%.*g", ndigit, number);
1652 return buff;
1655 /***********************************************************************
1656 * _gcvt_s (MSVCRT.@)
1658 int CDECL MSVCRT__gcvt_s(char *buff, MSVCRT_size_t size, double number, int digits)
1660 int len;
1662 if(!buff) {
1663 *MSVCRT__errno() = MSVCRT_EINVAL;
1664 return MSVCRT_EINVAL;
1667 if( digits<0 || digits>=size) {
1668 if(size)
1669 buff[0] = '\0';
1671 *MSVCRT__errno() = MSVCRT_ERANGE;
1672 return MSVCRT_ERANGE;
1675 len = MSVCRT__scprintf("%.*g", digits, number);
1676 if(len > size) {
1677 buff[0] = '\0';
1678 *MSVCRT__errno() = MSVCRT_ERANGE;
1679 return MSVCRT_ERANGE;
1682 MSVCRT_sprintf(buff, "%.*g", digits, number);
1683 return 0;
1686 #include <stdlib.h> /* div_t, ldiv_t */
1688 /*********************************************************************
1689 * div (MSVCRT.@)
1690 * VERSION
1691 * [i386] Windows binary compatible - returns the struct in eax/edx.
1693 #ifdef __i386__
1694 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
1696 div_t dt = div(num,denom);
1697 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
1699 #else
1700 /*********************************************************************
1701 * div (MSVCRT.@)
1702 * VERSION
1703 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1705 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
1707 div_t dt = div(num,denom);
1708 MSVCRT_div_t ret;
1709 ret.quot = dt.quot;
1710 ret.rem = dt.rem;
1712 return ret;
1715 #endif /* ifdef __i386__ */
1718 /*********************************************************************
1719 * ldiv (MSVCRT.@)
1720 * VERSION
1721 * [i386] Windows binary compatible - returns the struct in eax/edx.
1723 #ifdef __i386__
1724 unsigned __int64 CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1726 ldiv_t ldt = ldiv(num,denom);
1727 return ((unsigned __int64)ldt.rem << 32) | (MSVCRT_ulong)ldt.quot;
1729 #else
1730 /*********************************************************************
1731 * ldiv (MSVCRT.@)
1732 * VERSION
1733 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1735 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1737 ldiv_t result = ldiv(num,denom);
1739 MSVCRT_ldiv_t ret;
1740 ret.quot = result.quot;
1741 ret.rem = result.rem;
1743 return ret;
1745 #endif /* ifdef __i386__ */
1747 #ifdef __i386__
1749 /*********************************************************************
1750 * _adjust_fdiv (MSVCRT.@)
1751 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1753 int MSVCRT__adjust_fdiv = 0;
1755 /***********************************************************************
1756 * _adj_fdiv_m16i (MSVCRT.@)
1758 * NOTE
1759 * I _think_ this function is intended to work around the Pentium
1760 * fdiv bug.
1762 void __stdcall _adj_fdiv_m16i( short arg )
1764 TRACE("(): stub\n");
1767 /***********************************************************************
1768 * _adj_fdiv_m32 (MSVCRT.@)
1770 * NOTE
1771 * I _think_ this function is intended to work around the Pentium
1772 * fdiv bug.
1774 void __stdcall _adj_fdiv_m32( unsigned int arg )
1776 TRACE("(): stub\n");
1779 /***********************************************************************
1780 * _adj_fdiv_m32i (MSVCRT.@)
1782 * NOTE
1783 * I _think_ this function is intended to work around the Pentium
1784 * fdiv bug.
1786 void __stdcall _adj_fdiv_m32i( int arg )
1788 TRACE("(): stub\n");
1791 /***********************************************************************
1792 * _adj_fdiv_m64 (MSVCRT.@)
1794 * NOTE
1795 * I _think_ this function is intended to work around the Pentium
1796 * fdiv bug.
1798 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1800 TRACE("(): stub\n");
1803 /***********************************************************************
1804 * _adj_fdiv_r (MSVCRT.@)
1805 * FIXME
1806 * This function is likely to have the wrong number of arguments.
1808 * NOTE
1809 * I _think_ this function is intended to work around the Pentium
1810 * fdiv bug.
1812 void _adj_fdiv_r(void)
1814 TRACE("(): stub\n");
1817 /***********************************************************************
1818 * _adj_fdivr_m16i (MSVCRT.@)
1820 * NOTE
1821 * I _think_ this function is intended to work around the Pentium
1822 * fdiv bug.
1824 void __stdcall _adj_fdivr_m16i( short arg )
1826 TRACE("(): stub\n");
1829 /***********************************************************************
1830 * _adj_fdivr_m32 (MSVCRT.@)
1832 * NOTE
1833 * I _think_ this function is intended to work around the Pentium
1834 * fdiv bug.
1836 void __stdcall _adj_fdivr_m32( unsigned int arg )
1838 TRACE("(): stub\n");
1841 /***********************************************************************
1842 * _adj_fdivr_m32i (MSVCRT.@)
1844 * NOTE
1845 * I _think_ this function is intended to work around the Pentium
1846 * fdiv bug.
1848 void __stdcall _adj_fdivr_m32i( int arg )
1850 TRACE("(): stub\n");
1853 /***********************************************************************
1854 * _adj_fdivr_m64 (MSVCRT.@)
1856 * NOTE
1857 * I _think_ this function is intended to work around the Pentium
1858 * fdiv bug.
1860 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1862 TRACE("(): stub\n");
1865 /***********************************************************************
1866 * _adj_fpatan (MSVCRT.@)
1867 * FIXME
1868 * This function is likely to have the wrong number of arguments.
1870 * NOTE
1871 * I _think_ this function is intended to work around the Pentium
1872 * fdiv bug.
1874 void _adj_fpatan(void)
1876 TRACE("(): stub\n");
1879 /***********************************************************************
1880 * _adj_fprem (MSVCRT.@)
1881 * FIXME
1882 * This function is likely to have the wrong number of arguments.
1884 * NOTE
1885 * I _think_ this function is intended to work around the Pentium
1886 * fdiv bug.
1888 void _adj_fprem(void)
1890 TRACE("(): stub\n");
1893 /***********************************************************************
1894 * _adj_fprem1 (MSVCRT.@)
1895 * FIXME
1896 * This function is likely to have the wrong number of arguments.
1898 * NOTE
1899 * I _think_ this function is intended to work around the Pentium
1900 * fdiv bug.
1902 void _adj_fprem1(void)
1904 TRACE("(): stub\n");
1907 /***********************************************************************
1908 * _adj_fptan (MSVCRT.@)
1909 * FIXME
1910 * This function is likely to have the wrong number of arguments.
1912 * NOTE
1913 * I _think_ this function is intended to work around the Pentium
1914 * fdiv bug.
1916 void _adj_fptan(void)
1918 TRACE("(): stub\n");
1921 /***********************************************************************
1922 * _safe_fdiv (MSVCRT.@)
1923 * FIXME
1924 * This function is likely to have the wrong number of arguments.
1926 * NOTE
1927 * I _think_ this function is intended to work around the Pentium
1928 * fdiv bug.
1930 void _safe_fdiv(void)
1932 TRACE("(): stub\n");
1935 /***********************************************************************
1936 * _safe_fdivr (MSVCRT.@)
1937 * FIXME
1938 * This function is likely to have the wrong number of arguments.
1940 * NOTE
1941 * I _think_ this function is intended to work around the Pentium
1942 * fdiv bug.
1944 void _safe_fdivr(void)
1946 TRACE("(): stub\n");
1949 /***********************************************************************
1950 * _safe_fprem (MSVCRT.@)
1951 * FIXME
1952 * This function is likely to have the wrong number of arguments.
1954 * NOTE
1955 * I _think_ this function is intended to work around the Pentium
1956 * fdiv bug.
1958 void _safe_fprem(void)
1960 TRACE("(): stub\n");
1963 /***********************************************************************
1964 * _safe_fprem1 (MSVCRT.@)
1966 * FIXME
1967 * This function is likely to have the wrong number of arguments.
1969 * NOTE
1970 * I _think_ this function is intended to work around the Pentium
1971 * fdiv bug.
1973 void _safe_fprem1(void)
1975 TRACE("(): stub\n");
1978 /***********************************************************************
1979 * __libm_sse2_acos (MSVCRT.@)
1981 void __cdecl __libm_sse2_acos(void)
1983 double d;
1984 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1985 d = acos( d );
1986 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
1989 /***********************************************************************
1990 * __libm_sse2_acosf (MSVCRT.@)
1992 void __cdecl __libm_sse2_acosf(void)
1994 float f;
1995 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
1996 f = acosf( f );
1997 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2000 /***********************************************************************
2001 * __libm_sse2_asin (MSVCRT.@)
2003 void __cdecl __libm_sse2_asin(void)
2005 double d;
2006 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2007 d = asin( d );
2008 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2011 /***********************************************************************
2012 * __libm_sse2_asinf (MSVCRT.@)
2014 void __cdecl __libm_sse2_asinf(void)
2016 float f;
2017 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2018 f = asinf( f );
2019 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2022 /***********************************************************************
2023 * __libm_sse2_atan (MSVCRT.@)
2025 void __cdecl __libm_sse2_atan(void)
2027 double d;
2028 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2029 d = atan( d );
2030 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2033 /***********************************************************************
2034 * __libm_sse2_atan2 (MSVCRT.@)
2036 void __cdecl __libm_sse2_atan2(void)
2038 double d1, d2;
2039 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2040 d1 = atan2( d1, d2 );
2041 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2044 /***********************************************************************
2045 * __libm_sse2_atanf (MSVCRT.@)
2047 void __cdecl __libm_sse2_atanf(void)
2049 float f;
2050 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2051 f = atanf( f );
2052 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2055 /***********************************************************************
2056 * __libm_sse2_cos (MSVCRT.@)
2058 void __cdecl __libm_sse2_cos(void)
2060 double d;
2061 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2062 d = cos( d );
2063 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2066 /***********************************************************************
2067 * __libm_sse2_cosf (MSVCRT.@)
2069 void __cdecl __libm_sse2_cosf(void)
2071 float f;
2072 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2073 f = cosf( f );
2074 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2077 /***********************************************************************
2078 * __libm_sse2_exp (MSVCRT.@)
2080 void __cdecl __libm_sse2_exp(void)
2082 double d;
2083 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2084 d = exp( d );
2085 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2088 /***********************************************************************
2089 * __libm_sse2_expf (MSVCRT.@)
2091 void __cdecl __libm_sse2_expf(void)
2093 float f;
2094 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2095 f = expf( f );
2096 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2099 /***********************************************************************
2100 * __libm_sse2_log (MSVCRT.@)
2102 void __cdecl __libm_sse2_log(void)
2104 double d;
2105 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2106 d = log( d );
2107 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2110 /***********************************************************************
2111 * __libm_sse2_log10 (MSVCRT.@)
2113 void __cdecl __libm_sse2_log10(void)
2115 double d;
2116 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2117 d = log10( d );
2118 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2121 /***********************************************************************
2122 * __libm_sse2_log10f (MSVCRT.@)
2124 void __cdecl __libm_sse2_log10f(void)
2126 float f;
2127 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2128 f = log10f( f );
2129 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2132 /***********************************************************************
2133 * __libm_sse2_logf (MSVCRT.@)
2135 void __cdecl __libm_sse2_logf(void)
2137 float f;
2138 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2139 f = logf( f );
2140 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2143 /***********************************************************************
2144 * __libm_sse2_pow (MSVCRT.@)
2146 void __cdecl __libm_sse2_pow(void)
2148 double d1, d2;
2149 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2150 d1 = pow( d1, d2 );
2151 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2154 /***********************************************************************
2155 * __libm_sse2_powf (MSVCRT.@)
2157 void __cdecl __libm_sse2_powf(void)
2159 float f1, f2;
2160 __asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
2161 f1 = powf( f1, f2 );
2162 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
2165 /***********************************************************************
2166 * __libm_sse2_sin (MSVCRT.@)
2168 void __cdecl __libm_sse2_sin(void)
2170 double d;
2171 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2172 d = sin( d );
2173 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2176 /***********************************************************************
2177 * __libm_sse2_sinf (MSVCRT.@)
2179 void __cdecl __libm_sse2_sinf(void)
2181 float f;
2182 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2183 f = sinf( f );
2184 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2187 /***********************************************************************
2188 * __libm_sse2_tan (MSVCRT.@)
2190 void __cdecl __libm_sse2_tan(void)
2192 double d;
2193 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2194 d = tan( d );
2195 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2198 /***********************************************************************
2199 * __libm_sse2_tanf (MSVCRT.@)
2201 void __cdecl __libm_sse2_tanf(void)
2203 float f;
2204 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2205 f = tanf( f );
2206 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2209 /***********************************************************************
2210 * __libm_sse2_sqrt_precise (MSVCR110.@)
2212 void __cdecl __libm_sse2_sqrt_precise(void)
2214 double d;
2215 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2216 d = sqrt( d );
2217 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2220 #endif /* __i386__ */
2222 /*********************************************************************
2223 * cbrt (MSVCR120.@)
2225 double CDECL MSVCR120_cbrt(double x)
2227 #ifdef HAVE_CBRT
2228 return cbrt(x);
2229 #else
2230 return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
2231 #endif
2234 /*********************************************************************
2235 * cbrtf (MSVCR120.@)
2237 float CDECL MSVCR120_cbrtf(float x)
2239 #ifdef HAVE_CBRTF
2240 return cbrtf(x);
2241 #else
2242 return MSVCR120_cbrt(x);
2243 #endif
2246 /*********************************************************************
2247 * cbrtl (MSVCR120.@)
2249 LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
2251 return MSVCR120_cbrt(x);
2254 /*********************************************************************
2255 * exp2 (MSVCR120.@)
2257 double CDECL MSVCR120_exp2(double x)
2259 #ifdef HAVE_EXP2
2260 return exp2(x);
2261 #else
2262 return pow(2, x);
2263 #endif
2266 /*********************************************************************
2267 * exp2f (MSVCR120.@)
2269 float CDECL MSVCR120_exp2f(float x)
2271 #ifdef HAVE_EXP2F
2272 return exp2f(x);
2273 #else
2274 return MSVCR120_exp2(x);
2275 #endif
2278 /*********************************************************************
2279 * exp2l (MSVCR120.@)
2281 LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
2283 return MSVCR120_exp2(x);
2286 /*********************************************************************
2287 * log2 (MSVCR120.@)
2289 double CDECL MSVCR120_log2(double x)
2291 #ifdef HAVE_LOG2
2292 return log2(x);
2293 #else
2294 return log(x) / log(2);
2295 #endif
2298 /*********************************************************************
2299 * log2f (MSVCR120.@)
2301 float CDECL MSVCR120_log2f(float x)
2303 #ifdef HAVE_LOG2F
2304 return log2f(x);
2305 #else
2306 return MSVCR120_log2(x);
2307 #endif
2310 /*********************************************************************
2311 * log2l (MSVCR120.@)
2313 LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
2315 return MSVCR120_log2(x);
2318 /*********************************************************************
2319 * rint (MSVCR120.@)
2321 double CDECL MSVCR120_rint(double x)
2323 #ifdef HAVE_RINT
2324 return rint(x);
2325 #else
2326 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
2327 #endif
2330 /*********************************************************************
2331 * rintf (MSVCR120.@)
2333 float CDECL MSVCR120_rintf(float x)
2335 #ifdef HAVE_RINTF
2336 return rintf(x);
2337 #else
2338 return MSVCR120_rint(x);
2339 #endif
2342 /*********************************************************************
2343 * rintl (MSVCR120.@)
2345 LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
2347 return MSVCR120_rint(x);
2350 /*********************************************************************
2351 * lrint (MSVCR120.@)
2353 MSVCRT_long CDECL MSVCR120_lrint(double x)
2355 #ifdef HAVE_LRINT
2356 return lrint(x);
2357 #else
2358 return MSVCR120_rint(x);
2359 #endif
2362 /*********************************************************************
2363 * lrintf (MSVCR120.@)
2365 MSVCRT_long CDECL MSVCR120_lrintf(float x)
2367 #ifdef HAVE_LRINTF
2368 return lrintf(x);
2369 #else
2370 return MSVCR120_lrint(x);
2371 #endif
2374 /*********************************************************************
2375 * lrintl (MSVCR120.@)
2377 MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
2379 return MSVCR120_lrint(x);
2382 /*********************************************************************
2383 * llrint (MSVCR120.@)
2385 MSVCRT_longlong CDECL MSVCR120_llrint(double x)
2387 #ifdef HAVE_LLRINT
2388 return llrint(x);
2389 #else
2390 return MSVCR120_rint(x);
2391 #endif
2394 /*********************************************************************
2395 * llrintf (MSVCR120.@)
2397 MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
2399 #ifdef HAVE_LLRINTF
2400 return llrintf(x);
2401 #else
2402 return MSVCR120_llrint(x);
2403 #endif
2406 /*********************************************************************
2407 * rintl (MSVCR120.@)
2409 MSVCRT_longlong CDECL MSVCR120_llrintl(LDOUBLE x)
2411 return MSVCR120_llrint(x);
2414 /*********************************************************************
2415 * round (MSVCR120.@)
2417 double CDECL MSVCR120_round(double x)
2419 #ifdef HAVE_ROUND
2420 return round(x);
2421 #else
2422 return MSVCR120_rint(x);
2423 #endif
2426 /*********************************************************************
2427 * roundf (MSVCR120.@)
2429 float CDECL MSVCR120_roundf(float x)
2431 #ifdef HAVE_ROUNDF
2432 return roundf(x);
2433 #else
2434 return MSVCR120_round(x);
2435 #endif
2438 /*********************************************************************
2439 * roundl (MSVCR120.@)
2441 LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
2443 return MSVCR120_round(x);
2446 /*********************************************************************
2447 * lround (MSVCR120.@)
2449 MSVCRT_long CDECL MSVCR120_lround(double x)
2451 #ifdef HAVE_LROUND
2452 return lround(x);
2453 #else
2454 return MSVCR120_round(x);
2455 #endif
2458 /*********************************************************************
2459 * lroundf (MSVCR120.@)
2461 MSVCRT_long CDECL MSVCR120_lroundf(float x)
2463 #ifdef HAVE_LROUNDF
2464 return lroundf(x);
2465 #else
2466 return MSVCR120_lround(x);
2467 #endif
2470 /*********************************************************************
2471 * lroundl (MSVCR120.@)
2473 MSVCRT_long CDECL MSVCR120_lroundl(LDOUBLE x)
2475 return MSVCR120_lround(x);
2478 /*********************************************************************
2479 * llround (MSVCR120.@)
2481 MSVCRT_longlong CDECL MSVCR120_llround(double x)
2483 #ifdef HAVE_LLROUND
2484 return llround(x);
2485 #else
2486 return MSVCR120_round(x);
2487 #endif
2490 /*********************************************************************
2491 * llroundf (MSVCR120.@)
2493 MSVCRT_longlong CDECL MSVCR120_llroundf(float x)
2495 #ifdef HAVE_LLROUNDF
2496 return llroundf(x);
2497 #else
2498 return MSVCR120_llround(x);
2499 #endif
2502 /*********************************************************************
2503 * roundl (MSVCR120.@)
2505 MSVCRT_longlong CDECL MSVCR120_llroundl(LDOUBLE x)
2507 return MSVCR120_llround(x);
2510 /*********************************************************************
2511 * trunc (MSVCR120.@)
2513 double CDECL MSVCR120_trunc(double x)
2515 #ifdef HAVE_TRUNC
2516 return trunc(x);
2517 #else
2518 return (x > 0) ? floor(x) : ceil(x);
2519 #endif
2522 /*********************************************************************
2523 * truncf (MSVCR120.@)
2525 float CDECL MSVCR120_truncf(float x)
2527 #ifdef HAVE_TRUNCF
2528 return truncf(x);
2529 #else
2530 return MSVCR120_trunc(x);
2531 #endif
2534 /*********************************************************************
2535 * truncl (MSVCR120.@)
2537 LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
2539 return MSVCR120_trunc(x);
2542 /*********************************************************************
2543 * _dclass (MSVCR120.@)
2545 short CDECL MSVCR120__dclass(double x)
2547 switch (MSVCRT__fpclass(x)) {
2548 case MSVCRT__FPCLASS_QNAN:
2549 case MSVCRT__FPCLASS_SNAN:
2550 return MSVCRT_FP_NAN;
2551 case MSVCRT__FPCLASS_NINF:
2552 case MSVCRT__FPCLASS_PINF:
2553 return MSVCRT_FP_INFINITE;
2554 case MSVCRT__FPCLASS_ND:
2555 case MSVCRT__FPCLASS_PD:
2556 return MSVCRT_FP_SUBNORMAL;
2557 case MSVCRT__FPCLASS_NN:
2558 case MSVCRT__FPCLASS_PN:
2559 default:
2560 return MSVCRT_FP_NORMAL;
2561 case MSVCRT__FPCLASS_NZ:
2562 case MSVCRT__FPCLASS_PZ:
2563 return MSVCRT_FP_ZERO;
2567 /*********************************************************************
2568 * _fdclass (MSVCR120.@)
2570 short CDECL MSVCR120__fdclass(float x)
2572 return MSVCR120__dclass(x);
2575 /*********************************************************************
2576 * _ldclass (MSVCR120.@)
2578 short CDECL MSVCR120__ldclass(LDOUBLE x)
2580 return MSVCR120__dclass(x);
2583 /*********************************************************************
2584 * _dtest (MSVCR120.@)
2586 short CDECL MSVCR120__dtest(double *x)
2588 return MSVCR120__dclass(*x);
2591 /*********************************************************************
2592 * _fdtest (MSVCR120.@)
2594 short CDECL MSVCR120__fdtest(float *x)
2596 return MSVCR120__dclass(*x);
2599 /*********************************************************************
2600 * _ldtest (MSVCR120.@)
2602 short CDECL MSVCR120__ldtest(LDOUBLE *x)
2604 return MSVCR120__dclass(*x);