kernel32/tests: Add tabular UTF-7 encoding tests.
[wine.git] / dlls / msvcrt / math.c
blob9b75d361f47394d96faffb7b8f9c2ea637203f18
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 signbit
38 #define signbit(x) 0
39 #endif
41 typedef int (CDECL *MSVCRT_matherr_func)(struct MSVCRT__exception *);
42 typedef double LDOUBLE; /* long double is just a double */
44 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
46 static BOOL sse2_supported;
47 static BOOL sse2_enabled;
49 void msvcrt_init_math(void)
51 sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
54 /*********************************************************************
55 * _set_SSE2_enable (MSVCRT.@)
57 int CDECL MSVCRT__set_SSE2_enable(int flag)
59 sse2_enabled = flag && sse2_supported;
60 return sse2_enabled;
63 #if defined(__x86_64__) || defined(__arm__)
65 /*********************************************************************
66 * _chgsignf (MSVCRT.@)
68 float CDECL MSVCRT__chgsignf( float num )
70 /* FIXME: +-infinity,Nan not tested */
71 return -num;
74 /*********************************************************************
75 * _copysignf (MSVCRT.@)
77 float CDECL MSVCRT__copysignf( float num, float sign )
79 /* FIXME: Behaviour for Nan/Inf? */
80 if (sign < 0.0)
81 return num < 0.0 ? num : -num;
82 return num < 0.0 ? -num : num;
85 /*********************************************************************
86 * _finitef (MSVCRT.@)
88 int CDECL MSVCRT__finitef( float num )
90 return finitef(num) != 0; /* See comment for _isnan() */
93 /*********************************************************************
94 * _isnanf (MSVCRT.@)
96 INT CDECL MSVCRT__isnanf( float num )
98 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
99 * Do the same, as the result may be used in calculations
101 return isnanf(num) != 0;
104 /*********************************************************************
105 * _logbf (MSVCRT.@)
107 float CDECL MSVCRT__logbf( float num )
109 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
110 return logbf(num);
113 /*********************************************************************
114 * _nextafterf (MSVCRT.@)
116 float CDECL MSVCRT__nextafterf( float num, float next )
118 if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM;
119 return nextafterf( num, next );
122 /*********************************************************************
123 * MSVCRT_acosf (MSVCRT.@)
125 float CDECL MSVCRT_acosf( float x )
127 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
128 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
129 * asin() uses a similar construction. This is bad because as x gets nearer to
130 * 1 the error in the expression "1 - x^2" can get relatively large due to
131 * cancellation. The sqrt() makes things worse. A safer way to calculate
132 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
133 return atan2f(sqrtf((1 - x) * (1 + x)), x);
136 /*********************************************************************
137 * MSVCRT_asinf (MSVCRT.@)
139 float CDECL MSVCRT_asinf( float x )
141 if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
142 return atan2f(x, sqrtf((1 - x) * (1 + x)));
145 /*********************************************************************
146 * MSVCRT_atanf (MSVCRT.@)
148 float CDECL MSVCRT_atanf( float x )
150 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
151 return atanf(x);
154 /*********************************************************************
155 * MSVCRT_atan2f (MSVCRT.@)
157 float CDECL MSVCRT_atan2f( float x, float y )
159 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
160 return atan2f(x,y);
163 /*********************************************************************
164 * MSVCRT_cosf (MSVCRT.@)
166 float CDECL MSVCRT_cosf( float x )
168 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
169 return cosf(x);
172 /*********************************************************************
173 * MSVCRT_coshf (MSVCRT.@)
175 float CDECL MSVCRT_coshf( float x )
177 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
178 return coshf(x);
181 /*********************************************************************
182 * MSVCRT_expf (MSVCRT.@)
184 float CDECL MSVCRT_expf( float x )
186 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
187 return expf(x);
190 /*********************************************************************
191 * MSVCRT_fmodf (MSVCRT.@)
193 float CDECL MSVCRT_fmodf( float x, float y )
195 if (!finitef(x) || !finitef(y)) *MSVCRT__errno() = MSVCRT_EDOM;
196 return fmodf(x,y);
199 /*********************************************************************
200 * MSVCRT_logf (MSVCRT.@)
202 float CDECL MSVCRT_logf( float x)
204 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
205 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
206 return logf(x);
209 /*********************************************************************
210 * MSVCRT_log10f (MSVCRT.@)
212 float CDECL MSVCRT_log10f( float x )
214 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
215 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
216 return log10f(x);
219 /*********************************************************************
220 * MSVCRT_powf (MSVCRT.@)
222 float CDECL MSVCRT_powf( float x, float y )
224 /* FIXME: If x < 0 and y is not integral, set EDOM */
225 float z = powf(x,y);
226 if (!finitef(z)) *MSVCRT__errno() = MSVCRT_EDOM;
227 return z;
230 /*********************************************************************
231 * MSVCRT_sinf (MSVCRT.@)
233 float CDECL MSVCRT_sinf( float x )
235 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
236 return sinf(x);
239 /*********************************************************************
240 * MSVCRT_sinhf (MSVCRT.@)
242 float CDECL MSVCRT_sinhf( float x )
244 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
245 return sinhf(x);
248 /*********************************************************************
249 * MSVCRT_sqrtf (MSVCRT.@)
251 float CDECL MSVCRT_sqrtf( float x )
253 if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
254 return sqrtf(x);
257 /*********************************************************************
258 * MSVCRT_tanf (MSVCRT.@)
260 float CDECL MSVCRT_tanf( float x )
262 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
263 return tanf(x);
266 /*********************************************************************
267 * MSVCRT_tanhf (MSVCRT.@)
269 float CDECL MSVCRT_tanhf( float x )
271 if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
272 return tanhf(x);
275 /*********************************************************************
276 * ceilf (MSVCRT.@)
278 float CDECL MSVCRT_ceilf( float x )
280 return ceilf(x);
283 /*********************************************************************
284 * fabsf (MSVCRT.@)
286 float CDECL MSVCRT_fabsf( float x )
288 return fabsf(x);
291 /*********************************************************************
292 * floorf (MSVCRT.@)
294 float CDECL MSVCRT_floorf( float x )
296 return floorf(x);
299 /*********************************************************************
300 * frexpf (MSVCRT.@)
302 float CDECL MSVCRT_frexpf( float x, int *exp )
304 return frexpf( x, exp );
307 /*********************************************************************
308 * _scalbf (MSVCRT.@)
310 float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
312 if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
313 return ldexpf(num, power);
316 /*********************************************************************
317 * modff (MSVCRT.@)
319 double CDECL MSVCRT_modff( float x, float *iptr )
321 return modff( x, iptr );
324 #endif
326 /*********************************************************************
327 * MSVCRT_acos (MSVCRT.@)
329 double CDECL MSVCRT_acos( double x )
331 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
332 /* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
333 * asin() uses a similar construction. This is bad because as x gets nearer to
334 * 1 the error in the expression "1 - x^2" can get relatively large due to
335 * cancellation. The sqrt() makes things worse. A safer way to calculate
336 * acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
337 return atan2(sqrt((1 - x) * (1 + x)), x);
340 /*********************************************************************
341 * MSVCRT_asin (MSVCRT.@)
343 double CDECL MSVCRT_asin( double x )
345 if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
346 return atan2(x, sqrt((1 - x) * (1 + x)));
349 /*********************************************************************
350 * MSVCRT_atan (MSVCRT.@)
352 double CDECL MSVCRT_atan( double x )
354 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
355 return atan(x);
358 /*********************************************************************
359 * MSVCRT_atan2 (MSVCRT.@)
361 double CDECL MSVCRT_atan2( double x, double y )
363 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
364 return atan2(x,y);
367 /*********************************************************************
368 * MSVCRT_cos (MSVCRT.@)
370 double CDECL MSVCRT_cos( double x )
372 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
373 return cos(x);
376 /*********************************************************************
377 * MSVCRT_cosh (MSVCRT.@)
379 double CDECL MSVCRT_cosh( double x )
381 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
382 return cosh(x);
385 /*********************************************************************
386 * MSVCRT_exp (MSVCRT.@)
388 double CDECL MSVCRT_exp( double x )
390 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
391 return exp(x);
394 /*********************************************************************
395 * MSVCRT_fmod (MSVCRT.@)
397 double CDECL MSVCRT_fmod( double x, double y )
399 if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
400 return fmod(x,y);
403 /*********************************************************************
404 * MSVCRT_log (MSVCRT.@)
406 double CDECL MSVCRT_log( double x)
408 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
409 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
410 return log(x);
413 /*********************************************************************
414 * MSVCRT_log10 (MSVCRT.@)
416 double CDECL MSVCRT_log10( double x )
418 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
419 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
420 return log10(x);
423 /*********************************************************************
424 * MSVCRT_pow (MSVCRT.@)
426 double CDECL MSVCRT_pow( double x, double y )
428 /* FIXME: If x < 0 and y is not integral, set EDOM */
429 double z = pow(x,y);
430 if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
431 return z;
434 /*********************************************************************
435 * MSVCRT_sin (MSVCRT.@)
437 double CDECL MSVCRT_sin( double x )
439 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
440 return sin(x);
443 /*********************************************************************
444 * MSVCRT_sinh (MSVCRT.@)
446 double CDECL MSVCRT_sinh( double x )
448 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
449 return sinh(x);
452 /*********************************************************************
453 * MSVCRT_sqrt (MSVCRT.@)
455 double CDECL MSVCRT_sqrt( double x )
457 if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
458 return sqrt(x);
461 /*********************************************************************
462 * MSVCRT_tan (MSVCRT.@)
464 double CDECL MSVCRT_tan( double x )
466 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
467 return tan(x);
470 /*********************************************************************
471 * MSVCRT_tanh (MSVCRT.@)
473 double CDECL MSVCRT_tanh( double x )
475 if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
476 return tanh(x);
480 #if defined(__GNUC__) && defined(__i386__)
482 #define FPU_DOUBLE(var) double var; \
483 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
484 #define FPU_DOUBLES(var1,var2) double var1,var2; \
485 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
486 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
488 /*********************************************************************
489 * _CIacos (MSVCRT.@)
491 double CDECL _CIacos(void)
493 FPU_DOUBLE(x);
494 return MSVCRT_acos(x);
497 /*********************************************************************
498 * _CIasin (MSVCRT.@)
500 double CDECL _CIasin(void)
502 FPU_DOUBLE(x);
503 return MSVCRT_asin(x);
506 /*********************************************************************
507 * _CIatan (MSVCRT.@)
509 double CDECL _CIatan(void)
511 FPU_DOUBLE(x);
512 return MSVCRT_atan(x);
515 /*********************************************************************
516 * _CIatan2 (MSVCRT.@)
518 double CDECL _CIatan2(void)
520 FPU_DOUBLES(x,y);
521 return MSVCRT_atan2(x,y);
524 /*********************************************************************
525 * _CIcos (MSVCRT.@)
527 double CDECL _CIcos(void)
529 FPU_DOUBLE(x);
530 return MSVCRT_cos(x);
533 /*********************************************************************
534 * _CIcosh (MSVCRT.@)
536 double CDECL _CIcosh(void)
538 FPU_DOUBLE(x);
539 return MSVCRT_cosh(x);
542 /*********************************************************************
543 * _CIexp (MSVCRT.@)
545 double CDECL _CIexp(void)
547 FPU_DOUBLE(x);
548 return MSVCRT_exp(x);
551 /*********************************************************************
552 * _CIfmod (MSVCRT.@)
554 double CDECL _CIfmod(void)
556 FPU_DOUBLES(x,y);
557 return MSVCRT_fmod(x,y);
560 /*********************************************************************
561 * _CIlog (MSVCRT.@)
563 double CDECL _CIlog(void)
565 FPU_DOUBLE(x);
566 return MSVCRT_log(x);
569 /*********************************************************************
570 * _CIlog10 (MSVCRT.@)
572 double CDECL _CIlog10(void)
574 FPU_DOUBLE(x);
575 return MSVCRT_log10(x);
578 /*********************************************************************
579 * _CIpow (MSVCRT.@)
581 double CDECL _CIpow(void)
583 FPU_DOUBLES(x,y);
584 return MSVCRT_pow(x,y);
587 /*********************************************************************
588 * _CIsin (MSVCRT.@)
590 double CDECL _CIsin(void)
592 FPU_DOUBLE(x);
593 return MSVCRT_sin(x);
596 /*********************************************************************
597 * _CIsinh (MSVCRT.@)
599 double CDECL _CIsinh(void)
601 FPU_DOUBLE(x);
602 return MSVCRT_sinh(x);
605 /*********************************************************************
606 * _CIsqrt (MSVCRT.@)
608 double CDECL _CIsqrt(void)
610 FPU_DOUBLE(x);
611 return MSVCRT_sqrt(x);
614 /*********************************************************************
615 * _CItan (MSVCRT.@)
617 double CDECL _CItan(void)
619 FPU_DOUBLE(x);
620 return MSVCRT_tan(x);
623 /*********************************************************************
624 * _CItanh (MSVCRT.@)
626 double CDECL _CItanh(void)
628 FPU_DOUBLE(x);
629 return MSVCRT_tanh(x);
632 /*********************************************************************
633 * _ftol (MSVCRT.@)
635 LONGLONG CDECL MSVCRT__ftol(void)
637 FPU_DOUBLE(x);
638 return (LONGLONG)x;
641 #endif /* defined(__GNUC__) && defined(__i386__) */
643 /*********************************************************************
644 * _fpclass (MSVCRT.@)
646 int CDECL MSVCRT__fpclass(double num)
648 #if defined(HAVE_FPCLASS) || defined(fpclass)
649 switch (fpclass( num ))
651 #ifdef FP_SNAN
652 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
653 #endif
654 #ifdef FP_QNAN
655 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
656 #endif
657 #ifdef FP_NINF
658 case FP_NINF: return MSVCRT__FPCLASS_NINF;
659 #endif
660 #ifdef FP_PINF
661 case FP_PINF: return MSVCRT__FPCLASS_PINF;
662 #endif
663 #ifdef FP_NDENORM
664 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
665 #endif
666 #ifdef FP_PDENORM
667 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
668 #endif
669 #ifdef FP_NZERO
670 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
671 #endif
672 #ifdef FP_PZERO
673 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
674 #endif
675 #ifdef FP_NNORM
676 case FP_NNORM: return MSVCRT__FPCLASS_NN;
677 #endif
678 #ifdef FP_PNORM
679 case FP_PNORM: return MSVCRT__FPCLASS_PN;
680 #endif
681 default: return MSVCRT__FPCLASS_PN;
683 #elif defined (fpclassify)
684 switch (fpclassify( num ))
686 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
687 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
688 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
689 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
691 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
692 #else
693 if (!isfinite(num))
694 return MSVCRT__FPCLASS_QNAN;
695 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
696 #endif
699 /*********************************************************************
700 * _rotl (MSVCRT.@)
702 unsigned int CDECL _rotl(unsigned int num, int shift)
704 shift &= 31;
705 return (num << shift) | (num >> (32-shift));
708 /*********************************************************************
709 * _lrotl (MSVCRT.@)
711 MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
713 shift &= 0x1f;
714 return (num << shift) | (num >> (32-shift));
717 /*********************************************************************
718 * _lrotr (MSVCRT.@)
720 MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
722 shift &= 0x1f;
723 return (num >> shift) | (num << (32-shift));
726 /*********************************************************************
727 * _rotr (MSVCRT.@)
729 unsigned int CDECL _rotr(unsigned int num, int shift)
731 shift &= 0x1f;
732 return (num >> shift) | (num << (32-shift));
735 /*********************************************************************
736 * _rotl64 (MSVCRT.@)
738 unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
740 shift &= 63;
741 return (num << shift) | (num >> (64-shift));
744 /*********************************************************************
745 * _rotr64 (MSVCRT.@)
747 unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
749 shift &= 63;
750 return (num >> shift) | (num << (64-shift));
753 /*********************************************************************
754 * abs (MSVCRT.@)
756 int CDECL MSVCRT_abs( int n )
758 return n >= 0 ? n : -n;
761 /*********************************************************************
762 * labs (MSVCRT.@)
764 MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
766 return n >= 0 ? n : -n;
769 /*********************************************************************
770 * llabs (MSVCRT.@)
772 MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
774 return n >= 0 ? n : -n;
777 /*********************************************************************
778 * _abs64 (MSVCRT.@)
780 __int64 CDECL _abs64( __int64 n )
782 return n >= 0 ? n : -n;
785 /*********************************************************************
786 * _logb (MSVCRT.@)
788 double CDECL MSVCRT__logb(double num)
790 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
791 return logb(num);
794 /*********************************************************************
795 * _scalb (MSVCRT.@)
797 double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
799 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
800 return ldexp(num, power);
803 /*********************************************************************
804 * _hypot (MSVCRT.@)
806 double CDECL _hypot(double x, double y)
808 /* FIXME: errno handling */
809 return hypot( x, y );
812 /*********************************************************************
813 * _hypotf (MSVCRT.@)
815 float CDECL MSVCRT__hypotf(float x, float y)
817 /* FIXME: errno handling */
818 return hypotf( x, y );
821 /*********************************************************************
822 * ceil (MSVCRT.@)
824 double CDECL MSVCRT_ceil( double x )
826 return ceil(x);
829 /*********************************************************************
830 * floor (MSVCRT.@)
832 double CDECL MSVCRT_floor( double x )
834 return floor(x);
837 /*********************************************************************
838 * fabs (MSVCRT.@)
840 double CDECL MSVCRT_fabs( double x )
842 return fabs(x);
845 /*********************************************************************
846 * frexp (MSVCRT.@)
848 double CDECL MSVCRT_frexp( double x, int *exp )
850 return frexp( x, exp );
853 /*********************************************************************
854 * modf (MSVCRT.@)
856 double CDECL MSVCRT_modf( double x, double *iptr )
858 return modf( x, iptr );
861 /*********************************************************************
862 * _matherr (MSVCRT.@)
864 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
866 if (e)
867 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
868 e->retval);
869 else
870 TRACE("(null)\n");
871 if (MSVCRT_default_matherr_func)
872 return MSVCRT_default_matherr_func(e);
873 ERR(":Unhandled math error!\n");
874 return 0;
877 /*********************************************************************
878 * __setusermatherr (MSVCRT.@)
880 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
882 MSVCRT_default_matherr_func = func;
883 TRACE(":new matherr handler %p\n", func);
886 /**********************************************************************
887 * _statusfp2 (MSVCRT.@)
889 * Not exported by native msvcrt, added in msvcr80.
891 #if defined(__i386__) || defined(__x86_64__)
892 void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
894 #ifdef __GNUC__
895 unsigned int flags;
896 unsigned long fpword;
898 if (x86_sw)
900 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
901 flags = 0;
902 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
903 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
904 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
905 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
906 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
907 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
908 *x86_sw = flags;
911 if (!sse2_sw) return;
913 if (sse2_supported)
915 __asm__ __volatile__( "stmxcsr %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 *sse2_sw = flags;
925 else *sse2_sw = 0;
926 #else
927 FIXME( "not implemented\n" );
928 #endif
930 #endif
932 /**********************************************************************
933 * _statusfp (MSVCRT.@)
935 unsigned int CDECL _statusfp(void)
937 #if defined(__i386__) || defined(__x86_64__)
938 unsigned int x86_sw, sse2_sw;
940 _statusfp2( &x86_sw, &sse2_sw );
941 /* FIXME: there's no definition for ambiguous status, just return all status bits for now */
942 return x86_sw | sse2_sw;
943 #else
944 FIXME( "not implemented\n" );
945 return 0;
946 #endif
949 /*********************************************************************
950 * _clearfp (MSVCRT.@)
952 unsigned int CDECL _clearfp(void)
954 unsigned int flags = 0;
955 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
956 unsigned long fpword;
958 __asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
959 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
960 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
961 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
962 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
963 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
964 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
966 if (sse2_supported)
968 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
969 if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
970 if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
971 if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
972 if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
973 if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
974 if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
975 fpword &= ~0x3f;
976 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
978 #else
979 FIXME( "not implemented\n" );
980 #endif
981 return flags;
984 /*********************************************************************
985 * __fpecode (MSVCRT.@)
987 int * CDECL __fpecode(void)
989 return &msvcrt_get_thread_data()->fpecode;
992 /*********************************************************************
993 * ldexp (MSVCRT.@)
995 double CDECL MSVCRT_ldexp(double num, MSVCRT_long exp)
997 double z = ldexp(num,exp);
999 if (!isfinite(z))
1000 *MSVCRT__errno() = MSVCRT_ERANGE;
1001 else if (z == 0 && signbit(z))
1002 z = 0.0; /* Convert -0 -> +0 */
1003 return z;
1006 /*********************************************************************
1007 * _cabs (MSVCRT.@)
1009 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
1011 return sqrt(num.x * num.x + num.y * num.y);
1014 /*********************************************************************
1015 * _chgsign (MSVCRT.@)
1017 double CDECL MSVCRT__chgsign(double num)
1019 /* FIXME: +-infinity,Nan not tested */
1020 return -num;
1023 /*********************************************************************
1024 * __control87_2 (MSVCRT.@)
1026 * Not exported by native msvcrt, added in msvcr80.
1028 #if defined(__i386__) || defined(__x86_64__)
1029 int CDECL __control87_2( unsigned int newval, unsigned int mask,
1030 unsigned int *x86_cw, unsigned int *sse2_cw )
1032 #ifdef __GNUC__
1033 unsigned long fpword;
1034 unsigned int flags;
1036 if (x86_cw)
1038 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) );
1040 /* Convert into mask constants */
1041 flags = 0;
1042 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
1043 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
1044 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
1045 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
1046 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
1047 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
1048 switch (fpword & 0xc00)
1050 case 0xc00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1051 case 0x800: flags |= MSVCRT__RC_UP; break;
1052 case 0x400: flags |= MSVCRT__RC_DOWN; break;
1054 switch (fpword & 0x300)
1056 case 0x0: flags |= MSVCRT__PC_24; break;
1057 case 0x200: flags |= MSVCRT__PC_53; break;
1058 case 0x300: flags |= MSVCRT__PC_64; break;
1060 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
1062 TRACE( "x86 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1063 if (mask)
1065 flags = (flags & ~mask) | (newval & mask);
1067 /* Convert (masked) value back to fp word */
1068 fpword = 0;
1069 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
1070 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
1071 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
1072 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
1073 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
1074 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
1075 switch (flags & MSVCRT__MCW_RC)
1077 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00; break;
1078 case MSVCRT__RC_UP: fpword |= 0x800; break;
1079 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
1081 switch (flags & MSVCRT__MCW_PC)
1083 case MSVCRT__PC_64: fpword |= 0x300; break;
1084 case MSVCRT__PC_53: fpword |= 0x200; break;
1085 case MSVCRT__PC_24: fpword |= 0x0; break;
1087 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
1089 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
1091 *x86_cw = flags;
1094 if (!sse2_cw) return 1;
1096 if (sse2_supported)
1098 __asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
1100 /* Convert into mask constants */
1101 flags = 0;
1102 if (fpword & 0x80) flags |= MSVCRT__EM_INVALID;
1103 if (fpword & 0x100) flags |= MSVCRT__EM_DENORMAL;
1104 if (fpword & 0x200) flags |= MSVCRT__EM_ZERODIVIDE;
1105 if (fpword & 0x400) flags |= MSVCRT__EM_OVERFLOW;
1106 if (fpword & 0x800) flags |= MSVCRT__EM_UNDERFLOW;
1107 if (fpword & 0x1000) flags |= MSVCRT__EM_INEXACT;
1108 switch (fpword & 0x6000)
1110 case 0x6000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
1111 case 0x4000: flags |= MSVCRT__RC_UP; break;
1112 case 0x2000: flags |= MSVCRT__RC_DOWN; break;
1114 switch (fpword & 0x8040)
1116 case 0x0040: flags |= MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS; break;
1117 case 0x8000: flags |= MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS; break;
1118 case 0x8040: flags |= MSVCRT__DN_FLUSH; break;
1121 TRACE( "sse2 flags=%08x newval=%08x mask=%08x\n", flags, newval, mask );
1122 if (mask)
1124 flags = (flags & ~mask) | (newval & mask);
1126 /* Convert (masked) value back to fp word */
1127 fpword = 0;
1128 if (flags & MSVCRT__EM_INVALID) fpword |= 0x80;
1129 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x100;
1130 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x200;
1131 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x400;
1132 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x800;
1133 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x1000;
1134 switch (flags & MSVCRT__MCW_RC)
1136 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0x6000; break;
1137 case MSVCRT__RC_UP: fpword |= 0x4000; break;
1138 case MSVCRT__RC_DOWN: fpword |= 0x2000; break;
1140 switch (flags & MSVCRT__MCW_DN)
1142 case MSVCRT__DN_FLUSH_OPERANDS_SAVE_RESULTS: fpword |= 0x0040; break;
1143 case MSVCRT__DN_SAVE_OPERANDS_FLUSH_RESULTS: fpword |= 0x8000; break;
1144 case MSVCRT__DN_FLUSH: fpword |= 0x8040; break;
1146 __asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
1148 *sse2_cw = flags;
1150 else *sse2_cw = 0;
1152 return 1;
1153 #else
1154 FIXME( "not implemented\n" );
1155 return 0;
1156 #endif
1158 #endif
1160 /*********************************************************************
1161 * _control87 (MSVCRT.@)
1163 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
1165 #if defined(__i386__) || defined(__x86_64__)
1166 unsigned int x86_cw, sse2_cw;
1168 __control87_2( newval, mask, &x86_cw, &sse2_cw );
1170 if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS;
1171 return x86_cw;
1172 #else
1173 FIXME( "not implemented\n" );
1174 return 0;
1175 #endif
1178 /*********************************************************************
1179 * _controlfp (MSVCRT.@)
1181 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
1183 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
1186 /*********************************************************************
1187 * _set_controlfp (MSVCRT.@)
1189 void CDECL _set_controlfp( unsigned int newval, unsigned int mask )
1191 _controlfp( newval, mask );
1194 /*********************************************************************
1195 * _controlfp_s (MSVCRT.@)
1197 int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
1199 static const unsigned int all_flags = (MSVCRT__MCW_EM | MSVCRT__MCW_IC | MSVCRT__MCW_RC |
1200 MSVCRT__MCW_PC | MSVCRT__MCW_DN);
1201 unsigned int val;
1203 if (!MSVCRT_CHECK_PMT( !(newval & mask & ~all_flags) ))
1205 if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
1206 return MSVCRT_EINVAL;
1208 val = _controlfp( newval, mask );
1209 if (cur) *cur = val;
1210 return 0;
1213 /*********************************************************************
1214 * _copysign (MSVCRT.@)
1216 double CDECL MSVCRT__copysign(double num, double sign)
1218 /* FIXME: Behaviour for Nan/Inf? */
1219 if (sign < 0.0)
1220 return num < 0.0 ? num : -num;
1221 return num < 0.0 ? -num : num;
1224 /*********************************************************************
1225 * _finite (MSVCRT.@)
1227 int CDECL MSVCRT__finite(double num)
1229 return isfinite(num) != 0; /* See comment for _isnan() */
1232 /*********************************************************************
1233 * _fpreset (MSVCRT.@)
1235 void CDECL _fpreset(void)
1237 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1238 const unsigned int x86_cw = 0x27f;
1239 __asm__ __volatile__( "fninit; fldcw %0" : : "m" (x86_cw) );
1240 if (sse2_supported)
1242 const unsigned long sse2_cw = 0x1f80;
1243 __asm__ __volatile__( "ldmxcsr %0" : : "m" (sse2_cw) );
1245 #else
1246 FIXME( "not implemented\n" );
1247 #endif
1250 /*********************************************************************
1251 * _isnan (MSVCRT.@)
1253 INT CDECL MSVCRT__isnan(double num)
1255 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
1256 * Do the same, as the result may be used in calculations
1258 return isnan(num) != 0;
1261 /*********************************************************************
1262 * _j0 (MSVCRT.@)
1264 double CDECL MSVCRT__j0(double num)
1266 /* FIXME: errno handling */
1267 return j0(num);
1270 /*********************************************************************
1271 * _j1 (MSVCRT.@)
1273 double CDECL MSVCRT__j1(double num)
1275 /* FIXME: errno handling */
1276 return j1(num);
1279 /*********************************************************************
1280 * _jn (MSVCRT.@)
1282 double CDECL MSVCRT__jn(int n, double num)
1284 /* FIXME: errno handling */
1285 return jn(n, num);
1288 /*********************************************************************
1289 * _y0 (MSVCRT.@)
1291 double CDECL MSVCRT__y0(double num)
1293 double retval;
1294 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1295 retval = y0(num);
1296 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1298 *MSVCRT__errno() = MSVCRT_EDOM;
1299 retval = sqrt(-1);
1301 return retval;
1304 /*********************************************************************
1305 * _y1 (MSVCRT.@)
1307 double CDECL MSVCRT__y1(double num)
1309 double retval;
1310 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1311 retval = y1(num);
1312 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1314 *MSVCRT__errno() = MSVCRT_EDOM;
1315 retval = sqrt(-1);
1317 return retval;
1320 /*********************************************************************
1321 * _yn (MSVCRT.@)
1323 double CDECL MSVCRT__yn(int order, double num)
1325 double retval;
1326 if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
1327 retval = yn(order,num);
1328 if (MSVCRT__fpclass(retval) == MSVCRT__FPCLASS_NINF)
1330 *MSVCRT__errno() = MSVCRT_EDOM;
1331 retval = sqrt(-1);
1333 return retval;
1336 /*********************************************************************
1337 * _nextafter (MSVCRT.@)
1339 double CDECL MSVCRT__nextafter(double num, double next)
1341 double retval;
1342 if (!isfinite(num) || !isfinite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
1343 retval = nextafter(num,next);
1344 return retval;
1347 /*********************************************************************
1348 * _ecvt (MSVCRT.@)
1350 char * CDECL MSVCRT__ecvt( double number, int ndigits, int *decpt, int *sign )
1352 int prec, len;
1353 thread_data_t *data = msvcrt_get_thread_data();
1354 /* FIXME: check better for overflow (native supports over 300 chars) */
1355 ndigits = min( ndigits, 80 - 7); /* 7 : space for dec point, 1 for "e",
1356 * 4 for exponent and one for
1357 * terminating '\0' */
1358 if (!data->efcvt_buffer)
1359 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1361 if( number < 0) {
1362 *sign = TRUE;
1363 number = -number;
1364 } else
1365 *sign = FALSE;
1366 /* handle cases with zero ndigits or less */
1367 prec = ndigits;
1368 if( prec < 1) prec = 2;
1369 len = snprintf(data->efcvt_buffer, 80, "%.*le", prec - 1, number);
1370 /* take the decimal "point away */
1371 if( prec != 1)
1372 memmove( data->efcvt_buffer + 1, data->efcvt_buffer + 2, len - 1 );
1373 /* take the exponential "e" out */
1374 data->efcvt_buffer[ prec] = '\0';
1375 /* read the exponent */
1376 sscanf( data->efcvt_buffer + prec + 1, "%d", decpt);
1377 (*decpt)++;
1378 /* adjust for some border cases */
1379 if( data->efcvt_buffer[0] == '0')/* value is zero */
1380 *decpt = 0;
1381 /* handle cases with zero ndigits or less */
1382 if( ndigits < 1){
1383 if( data->efcvt_buffer[ 0] >= '5')
1384 (*decpt)++;
1385 data->efcvt_buffer[ 0] = '\0';
1387 TRACE("out=\"%s\"\n",data->efcvt_buffer);
1388 return data->efcvt_buffer;
1391 /*********************************************************************
1392 * _ecvt_s (MSVCRT.@)
1394 int CDECL MSVCRT__ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
1396 int prec, len;
1397 char *result;
1398 const char infret[] = "1#INF";
1400 if (!MSVCRT_CHECK_PMT(buffer != NULL)) return MSVCRT_EINVAL;
1401 if (!MSVCRT_CHECK_PMT(decpt != NULL)) return MSVCRT_EINVAL;
1402 if (!MSVCRT_CHECK_PMT(sign != NULL)) return MSVCRT_EINVAL;
1403 if (!MSVCRT_CHECK_PMT_ERR( length > 2, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1404 if (!MSVCRT_CHECK_PMT_ERR(ndigits < (int)length - 1, MSVCRT_ERANGE )) return MSVCRT_ERANGE;
1406 /* special case - inf */
1407 if(number == HUGE_VAL || number == -HUGE_VAL)
1409 memset(buffer, '0', ndigits);
1410 memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
1411 buffer[ndigits] = '\0';
1412 (*decpt) = 1;
1413 if(number == -HUGE_VAL)
1414 (*sign) = 1;
1415 else
1416 (*sign) = 0;
1417 return 0;
1419 /* handle cases with zero ndigits or less */
1420 prec = ndigits;
1421 if( prec < 1) prec = 2;
1422 result = MSVCRT_malloc(prec + 7);
1424 if( number < 0) {
1425 *sign = TRUE;
1426 number = -number;
1427 } else
1428 *sign = FALSE;
1429 len = snprintf(result, prec + 7, "%.*le", prec - 1, number);
1430 /* take the decimal "point away */
1431 if( prec != 1)
1432 memmove( result + 1, result + 2, len - 1 );
1433 /* take the exponential "e" out */
1434 result[ prec] = '\0';
1435 /* read the exponent */
1436 sscanf( result + prec + 1, "%d", decpt);
1437 (*decpt)++;
1438 /* adjust for some border cases */
1439 if( result[0] == '0')/* value is zero */
1440 *decpt = 0;
1441 /* handle cases with zero ndigits or less */
1442 if( ndigits < 1){
1443 if( result[ 0] >= '5')
1444 (*decpt)++;
1445 result[ 0] = '\0';
1447 memcpy( buffer, result, max(ndigits + 1, 1) );
1448 MSVCRT_free( result );
1449 return 0;
1452 /***********************************************************************
1453 * _fcvt (MSVCRT.@)
1455 char * CDECL MSVCRT__fcvt( double number, int ndigits, int *decpt, int *sign )
1457 thread_data_t *data = msvcrt_get_thread_data();
1458 int stop, dec1, dec2;
1459 char *ptr1, *ptr2, *first;
1460 char buf[80]; /* ought to be enough */
1462 if (!data->efcvt_buffer)
1463 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
1465 if (number < 0)
1467 *sign = 1;
1468 number = -number;
1469 } else *sign = 0;
1471 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1472 ptr1 = buf;
1473 ptr2 = data->efcvt_buffer;
1474 first = NULL;
1475 dec1 = 0;
1476 dec2 = 0;
1478 /* For numbers below the requested resolution, work out where
1479 the decimal point will be rather than finding it in the string */
1480 if (number < 1.0 && number > 0.0) {
1481 dec2 = log10(number + 1e-10);
1482 if (-dec2 <= ndigits) dec2 = 0;
1485 /* If requested digits is zero or less, we will need to truncate
1486 * the returned string */
1487 if (ndigits < 1) {
1488 stop = strlen(buf) + ndigits;
1489 } else {
1490 stop = strlen(buf);
1493 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1494 while (*ptr1 != '\0' && *ptr1 != '.') {
1495 if (!first) first = ptr2;
1496 if ((ptr1 - buf) < stop) {
1497 *ptr2++ = *ptr1++;
1498 } else {
1499 ptr1++;
1501 dec1++;
1504 if (ndigits > 0) {
1505 ptr1++;
1506 if (!first) {
1507 while (*ptr1 == '0') { /* Process leading zeroes */
1508 *ptr2++ = *ptr1++;
1509 dec1--;
1512 while (*ptr1 != '\0') {
1513 if (!first) first = ptr2;
1514 *ptr2++ = *ptr1++;
1518 *ptr2 = '\0';
1520 /* We never found a non-zero digit, then our number is either
1521 * smaller than the requested precision, or 0.0 */
1522 if (!first) {
1523 if (number > 0.0) {
1524 first = ptr2;
1525 } else {
1526 first = data->efcvt_buffer;
1527 dec1 = 0;
1531 *decpt = dec2 ? dec2 : dec1;
1532 return first;
1535 /***********************************************************************
1536 * _fcvt_s (MSVCRT.@)
1538 int CDECL MSVCRT__fcvt_s(char* outbuffer, MSVCRT_size_t size, double number, int ndigits, int *decpt, int *sign)
1540 int stop, dec1, dec2;
1541 char *ptr1, *ptr2, *first;
1542 char buf[80]; /* ought to be enough */
1544 if (!outbuffer || !decpt || !sign || size == 0)
1546 *MSVCRT__errno() = MSVCRT_EINVAL;
1547 return MSVCRT_EINVAL;
1550 if (number < 0)
1552 *sign = 1;
1553 number = -number;
1554 } else *sign = 0;
1556 snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number);
1557 ptr1 = buf;
1558 ptr2 = outbuffer;
1559 first = NULL;
1560 dec1 = 0;
1561 dec2 = 0;
1563 /* For numbers below the requested resolution, work out where
1564 the decimal point will be rather than finding it in the string */
1565 if (number < 1.0 && number > 0.0) {
1566 dec2 = log10(number + 1e-10);
1567 if (-dec2 <= ndigits) dec2 = 0;
1570 /* If requested digits is zero or less, we will need to truncate
1571 * the returned string */
1572 if (ndigits < 1) {
1573 stop = strlen(buf) + ndigits;
1574 } else {
1575 stop = strlen(buf);
1578 while (*ptr1 == '0') ptr1++; /* Skip leading zeroes */
1579 while (*ptr1 != '\0' && *ptr1 != '.') {
1580 if (!first) first = ptr2;
1581 if ((ptr1 - buf) < stop) {
1582 if (size > 1) {
1583 *ptr2++ = *ptr1++;
1584 size--;
1586 } else {
1587 ptr1++;
1589 dec1++;
1592 if (ndigits > 0) {
1593 ptr1++;
1594 if (!first) {
1595 while (*ptr1 == '0') { /* Process leading zeroes */
1596 if (number == 0.0 && size > 1) {
1597 *ptr2++ = '0';
1598 size--;
1600 ptr1++;
1601 dec1--;
1604 while (*ptr1 != '\0') {
1605 if (!first) first = ptr2;
1606 if (size > 1) {
1607 *ptr2++ = *ptr1++;
1608 size--;
1613 *ptr2 = '\0';
1615 /* We never found a non-zero digit, then our number is either
1616 * smaller than the requested precision, or 0.0 */
1617 if (!first && (number <= 0.0))
1618 dec1 = 0;
1620 *decpt = dec2 ? dec2 : dec1;
1621 return 0;
1624 /***********************************************************************
1625 * _gcvt (MSVCRT.@)
1627 char * CDECL MSVCRT__gcvt( double number, int ndigit, char *buff )
1629 if(!buff) {
1630 *MSVCRT__errno() = MSVCRT_EINVAL;
1631 return NULL;
1634 if(ndigit < 0) {
1635 *MSVCRT__errno() = MSVCRT_ERANGE;
1636 return NULL;
1639 MSVCRT_sprintf(buff, "%.*g", ndigit, number);
1640 return buff;
1643 /***********************************************************************
1644 * _gcvt_s (MSVCRT.@)
1646 int CDECL MSVCRT__gcvt_s(char *buff, MSVCRT_size_t size, double number, int digits)
1648 int len;
1650 if(!buff) {
1651 *MSVCRT__errno() = MSVCRT_EINVAL;
1652 return MSVCRT_EINVAL;
1655 if( digits<0 || digits>=size) {
1656 if(size)
1657 buff[0] = '\0';
1659 *MSVCRT__errno() = MSVCRT_ERANGE;
1660 return MSVCRT_ERANGE;
1663 len = MSVCRT__scprintf("%.*g", digits, number);
1664 if(len > size) {
1665 buff[0] = '\0';
1666 *MSVCRT__errno() = MSVCRT_ERANGE;
1667 return MSVCRT_ERANGE;
1670 MSVCRT_sprintf(buff, "%.*g", digits, number);
1671 return 0;
1674 #include <stdlib.h> /* div_t, ldiv_t */
1676 /*********************************************************************
1677 * div (MSVCRT.@)
1678 * VERSION
1679 * [i386] Windows binary compatible - returns the struct in eax/edx.
1681 #ifdef __i386__
1682 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
1684 div_t dt = div(num,denom);
1685 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
1687 #else
1688 /*********************************************************************
1689 * div (MSVCRT.@)
1690 * VERSION
1691 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1693 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
1695 div_t dt = div(num,denom);
1696 MSVCRT_div_t ret;
1697 ret.quot = dt.quot;
1698 ret.rem = dt.rem;
1700 return ret;
1703 #endif /* ifdef __i386__ */
1706 /*********************************************************************
1707 * ldiv (MSVCRT.@)
1708 * VERSION
1709 * [i386] Windows binary compatible - returns the struct in eax/edx.
1711 #ifdef __i386__
1712 unsigned __int64 CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1714 ldiv_t ldt = ldiv(num,denom);
1715 return ((unsigned __int64)ldt.rem << 32) | (MSVCRT_ulong)ldt.quot;
1717 #else
1718 /*********************************************************************
1719 * ldiv (MSVCRT.@)
1720 * VERSION
1721 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
1723 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(MSVCRT_long num, MSVCRT_long denom)
1725 ldiv_t result = ldiv(num,denom);
1727 MSVCRT_ldiv_t ret;
1728 ret.quot = result.quot;
1729 ret.rem = result.rem;
1731 return ret;
1733 #endif /* ifdef __i386__ */
1735 #ifdef __i386__
1737 /*********************************************************************
1738 * _adjust_fdiv (MSVCRT.@)
1739 * Used by the MSVC compiler to work around the Pentium FDIV bug.
1741 int MSVCRT__adjust_fdiv = 0;
1743 /***********************************************************************
1744 * _adj_fdiv_m16i (MSVCRT.@)
1746 * NOTE
1747 * I _think_ this function is intended to work around the Pentium
1748 * fdiv bug.
1750 void __stdcall _adj_fdiv_m16i( short arg )
1752 TRACE("(): stub\n");
1755 /***********************************************************************
1756 * _adj_fdiv_m32 (MSVCRT.@)
1758 * NOTE
1759 * I _think_ this function is intended to work around the Pentium
1760 * fdiv bug.
1762 void __stdcall _adj_fdiv_m32( unsigned int arg )
1764 TRACE("(): stub\n");
1767 /***********************************************************************
1768 * _adj_fdiv_m32i (MSVCRT.@)
1770 * NOTE
1771 * I _think_ this function is intended to work around the Pentium
1772 * fdiv bug.
1774 void __stdcall _adj_fdiv_m32i( int arg )
1776 TRACE("(): stub\n");
1779 /***********************************************************************
1780 * _adj_fdiv_m64 (MSVCRT.@)
1782 * NOTE
1783 * I _think_ this function is intended to work around the Pentium
1784 * fdiv bug.
1786 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1788 TRACE("(): stub\n");
1791 /***********************************************************************
1792 * _adj_fdiv_r (MSVCRT.@)
1793 * FIXME
1794 * This function is likely to have the wrong number of arguments.
1796 * NOTE
1797 * I _think_ this function is intended to work around the Pentium
1798 * fdiv bug.
1800 void _adj_fdiv_r(void)
1802 TRACE("(): stub\n");
1805 /***********************************************************************
1806 * _adj_fdivr_m16i (MSVCRT.@)
1808 * NOTE
1809 * I _think_ this function is intended to work around the Pentium
1810 * fdiv bug.
1812 void __stdcall _adj_fdivr_m16i( short arg )
1814 TRACE("(): stub\n");
1817 /***********************************************************************
1818 * _adj_fdivr_m32 (MSVCRT.@)
1820 * NOTE
1821 * I _think_ this function is intended to work around the Pentium
1822 * fdiv bug.
1824 void __stdcall _adj_fdivr_m32( unsigned int arg )
1826 TRACE("(): stub\n");
1829 /***********************************************************************
1830 * _adj_fdivr_m32i (MSVCRT.@)
1832 * NOTE
1833 * I _think_ this function is intended to work around the Pentium
1834 * fdiv bug.
1836 void __stdcall _adj_fdivr_m32i( int arg )
1838 TRACE("(): stub\n");
1841 /***********************************************************************
1842 * _adj_fdivr_m64 (MSVCRT.@)
1844 * NOTE
1845 * I _think_ this function is intended to work around the Pentium
1846 * fdiv bug.
1848 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1850 TRACE("(): stub\n");
1853 /***********************************************************************
1854 * _adj_fpatan (MSVCRT.@)
1855 * FIXME
1856 * This function is likely to have the wrong number of arguments.
1858 * NOTE
1859 * I _think_ this function is intended to work around the Pentium
1860 * fdiv bug.
1862 void _adj_fpatan(void)
1864 TRACE("(): stub\n");
1867 /***********************************************************************
1868 * _adj_fprem (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_fprem(void)
1878 TRACE("(): stub\n");
1881 /***********************************************************************
1882 * _adj_fprem1 (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_fprem1(void)
1892 TRACE("(): stub\n");
1895 /***********************************************************************
1896 * _adj_fptan (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_fptan(void)
1906 TRACE("(): stub\n");
1909 /***********************************************************************
1910 * _safe_fdiv (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 _safe_fdiv(void)
1920 TRACE("(): stub\n");
1923 /***********************************************************************
1924 * _safe_fdivr (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_fdivr(void)
1934 TRACE("(): stub\n");
1937 /***********************************************************************
1938 * _safe_fprem (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_fprem(void)
1948 TRACE("(): stub\n");
1951 /***********************************************************************
1952 * _safe_fprem1 (MSVCRT.@)
1954 * FIXME
1955 * This function is likely to have the wrong number of arguments.
1957 * NOTE
1958 * I _think_ this function is intended to work around the Pentium
1959 * fdiv bug.
1961 void _safe_fprem1(void)
1963 TRACE("(): stub\n");
1966 /***********************************************************************
1967 * __libm_sse2_acos (MSVCRT.@)
1969 void __cdecl __libm_sse2_acos(void)
1971 double d;
1972 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1973 d = acos( d );
1974 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
1977 /***********************************************************************
1978 * __libm_sse2_acosf (MSVCRT.@)
1980 void __cdecl __libm_sse2_acosf(void)
1982 float f;
1983 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
1984 f = acosf( f );
1985 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
1988 /***********************************************************************
1989 * __libm_sse2_asin (MSVCRT.@)
1991 void __cdecl __libm_sse2_asin(void)
1993 double d;
1994 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
1995 d = asin( d );
1996 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
1999 /***********************************************************************
2000 * __libm_sse2_asinf (MSVCRT.@)
2002 void __cdecl __libm_sse2_asinf(void)
2004 float f;
2005 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2006 f = asinf( f );
2007 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2010 /***********************************************************************
2011 * __libm_sse2_atan (MSVCRT.@)
2013 void __cdecl __libm_sse2_atan(void)
2015 double d;
2016 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2017 d = atan( d );
2018 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2021 /***********************************************************************
2022 * __libm_sse2_atan2 (MSVCRT.@)
2024 void __cdecl __libm_sse2_atan2(void)
2026 double d1, d2;
2027 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2028 d1 = atan2( d1, d2 );
2029 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2032 /***********************************************************************
2033 * __libm_sse2_atanf (MSVCRT.@)
2035 void __cdecl __libm_sse2_atanf(void)
2037 float f;
2038 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2039 f = atanf( f );
2040 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2043 /***********************************************************************
2044 * __libm_sse2_cos (MSVCRT.@)
2046 void __cdecl __libm_sse2_cos(void)
2048 double d;
2049 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2050 d = cos( d );
2051 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2054 /***********************************************************************
2055 * __libm_sse2_cosf (MSVCRT.@)
2057 void __cdecl __libm_sse2_cosf(void)
2059 float f;
2060 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2061 f = cosf( f );
2062 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2065 /***********************************************************************
2066 * __libm_sse2_exp (MSVCRT.@)
2068 void __cdecl __libm_sse2_exp(void)
2070 double d;
2071 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2072 d = exp( d );
2073 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2076 /***********************************************************************
2077 * __libm_sse2_expf (MSVCRT.@)
2079 void __cdecl __libm_sse2_expf(void)
2081 float f;
2082 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2083 f = expf( f );
2084 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2087 /***********************************************************************
2088 * __libm_sse2_log (MSVCRT.@)
2090 void __cdecl __libm_sse2_log(void)
2092 double d;
2093 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2094 d = log( d );
2095 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2098 /***********************************************************************
2099 * __libm_sse2_log10 (MSVCRT.@)
2101 void __cdecl __libm_sse2_log10(void)
2103 double d;
2104 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2105 d = log10( d );
2106 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2109 /***********************************************************************
2110 * __libm_sse2_log10f (MSVCRT.@)
2112 void __cdecl __libm_sse2_log10f(void)
2114 float f;
2115 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2116 f = log10f( f );
2117 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2120 /***********************************************************************
2121 * __libm_sse2_logf (MSVCRT.@)
2123 void __cdecl __libm_sse2_logf(void)
2125 float f;
2126 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2127 f = logf( f );
2128 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2131 /***********************************************************************
2132 * __libm_sse2_pow (MSVCRT.@)
2134 void __cdecl __libm_sse2_pow(void)
2136 double d1, d2;
2137 __asm__ __volatile__( "movq %%xmm0,%0; movq %%xmm1,%1 " : "=m" (d1), "=m" (d2) );
2138 d1 = pow( d1, d2 );
2139 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d1) );
2142 /***********************************************************************
2143 * __libm_sse2_powf (MSVCRT.@)
2145 void __cdecl __libm_sse2_powf(void)
2147 float f1, f2;
2148 __asm__ __volatile__( "movd %%xmm0,%0; movd %%xmm1,%1" : "=g" (f1), "=g" (f2) );
2149 f1 = powf( f1, f2 );
2150 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f1) );
2153 /***********************************************************************
2154 * __libm_sse2_sin (MSVCRT.@)
2156 void __cdecl __libm_sse2_sin(void)
2158 double d;
2159 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2160 d = sin( d );
2161 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2164 /***********************************************************************
2165 * __libm_sse2_sinf (MSVCRT.@)
2167 void __cdecl __libm_sse2_sinf(void)
2169 float f;
2170 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2171 f = sinf( f );
2172 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2175 /***********************************************************************
2176 * __libm_sse2_tan (MSVCRT.@)
2178 void __cdecl __libm_sse2_tan(void)
2180 double d;
2181 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2182 d = tan( d );
2183 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2186 /***********************************************************************
2187 * __libm_sse2_tanf (MSVCRT.@)
2189 void __cdecl __libm_sse2_tanf(void)
2191 float f;
2192 __asm__ __volatile__( "movd %%xmm0,%0" : "=g" (f) );
2193 f = tanf( f );
2194 __asm__ __volatile__( "movd %0,%%xmm0" : : "g" (f) );
2197 /***********************************************************************
2198 * __libm_sse2_sqrt_precise (MSVCR110.@)
2200 void __cdecl __libm_sse2_sqrt_precise(void)
2202 double d;
2203 __asm__ __volatile__( "movq %%xmm0,%0" : "=m" (d) );
2204 d = sqrt( d );
2205 __asm__ __volatile__( "movq %0,%%xmm0" : : "m" (d) );
2208 #endif /* __i386__ */
2210 /*********************************************************************
2211 * cbrt (MSVCR120.@)
2213 double CDECL MSVCR120_cbrt(double x)
2215 #ifdef HAVE_CBRT
2216 return cbrt(x);
2217 #else
2218 return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
2219 #endif
2222 /*********************************************************************
2223 * cbrtf (MSVCR120.@)
2225 float CDECL MSVCR120_cbrtf(float x)
2227 #ifdef HAVE_CBRTF
2228 return cbrtf(x);
2229 #else
2230 return MSVCR120_cbrt(x);
2231 #endif
2234 /*********************************************************************
2235 * cbrtl (MSVCR120.@)
2237 LDOUBLE CDECL MSVCR120_cbrtl(LDOUBLE x)
2239 return MSVCR120_cbrt(x);
2242 /*********************************************************************
2243 * exp2 (MSVCR120.@)
2245 double CDECL MSVCR120_exp2(double x)
2247 #ifdef HAVE_EXP2
2248 return exp2(x);
2249 #else
2250 return pow(2, x);
2251 #endif
2254 /*********************************************************************
2255 * exp2f (MSVCR120.@)
2257 float CDECL MSVCR120_exp2f(float x)
2259 #ifdef HAVE_EXP2F
2260 return exp2f(x);
2261 #else
2262 return MSVCR120_exp2(x);
2263 #endif
2266 /*********************************************************************
2267 * exp2l (MSVCR120.@)
2269 LDOUBLE CDECL MSVCR120_exp2l(LDOUBLE x)
2271 return MSVCR120_exp2(x);
2274 /*********************************************************************
2275 * log2 (MSVCR120.@)
2277 double CDECL MSVCR120_log2(double x)
2279 #ifdef HAVE_LOG2
2280 return log2(x);
2281 #else
2282 return log(x) / log(2);
2283 #endif
2286 /*********************************************************************
2287 * log2f (MSVCR120.@)
2289 float CDECL MSVCR120_log2f(float x)
2291 #ifdef HAVE_LOG2F
2292 return log2f(x);
2293 #else
2294 return MSVCR120_log2(x);
2295 #endif
2298 /*********************************************************************
2299 * log2l (MSVCR120.@)
2301 LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
2303 return MSVCR120_log2(x);
2306 /*********************************************************************
2307 * rint (MSVCR120.@)
2309 double CDECL MSVCR120_rint(double x)
2311 #ifdef HAVE_RINT
2312 return rint(x);
2313 #else
2314 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
2315 #endif
2318 /*********************************************************************
2319 * rintf (MSVCR120.@)
2321 float CDECL MSVCR120_rintf(float x)
2323 #ifdef HAVE_RINTF
2324 return rintf(x);
2325 #else
2326 return MSVCR120_rint(x);
2327 #endif
2330 /*********************************************************************
2331 * rintl (MSVCR120.@)
2333 LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
2335 return MSVCR120_rint(x);
2338 /*********************************************************************
2339 * lrint (MSVCR120.@)
2341 MSVCRT_long CDECL MSVCR120_lrint(double x)
2343 #ifdef HAVE_LRINT
2344 return lrint(x);
2345 #else
2346 return MSVCR120_rint(x);
2347 #endif
2350 /*********************************************************************
2351 * lrintf (MSVCR120.@)
2353 MSVCRT_long CDECL MSVCR120_lrintf(float x)
2355 #ifdef HAVE_LRINTF
2356 return lrintf(x);
2357 #else
2358 return MSVCR120_lrint(x);
2359 #endif
2362 /*********************************************************************
2363 * lrintl (MSVCR120.@)
2365 MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
2367 return MSVCR120_lrint(x);
2370 /*********************************************************************
2371 * llrint (MSVCR120.@)
2373 MSVCRT_longlong CDECL MSVCR120_llrint(double x)
2375 #ifdef HAVE_LLRINT
2376 return llrint(x);
2377 #else
2378 return MSVCR120_rint(x);
2379 #endif
2382 /*********************************************************************
2383 * llrintf (MSVCR120.@)
2385 MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
2387 #ifdef HAVE_LLRINTF
2388 return llrintf(x);
2389 #else
2390 return MSVCR120_llrint(x);
2391 #endif
2394 /*********************************************************************
2395 * rintl (MSVCR120.@)
2397 MSVCRT_longlong CDECL MSVCR120_llrintl(LDOUBLE x)
2399 return MSVCR120_llrint(x);
2402 /*********************************************************************
2403 * round (MSVCR120.@)
2405 double CDECL MSVCR120_round(double x)
2407 #ifdef HAVE_ROUND
2408 return round(x);
2409 #else
2410 return MSVCR120_rint(x);
2411 #endif
2414 /*********************************************************************
2415 * roundf (MSVCR120.@)
2417 float CDECL MSVCR120_roundf(float x)
2419 #ifdef HAVE_ROUNDF
2420 return roundf(x);
2421 #else
2422 return MSVCR120_round(x);
2423 #endif
2426 /*********************************************************************
2427 * roundl (MSVCR120.@)
2429 LDOUBLE CDECL MSVCR120_roundl(LDOUBLE x)
2431 return MSVCR120_round(x);
2434 /*********************************************************************
2435 * lround (MSVCR120.@)
2437 MSVCRT_long CDECL MSVCR120_lround(double x)
2439 #ifdef HAVE_LROUND
2440 return lround(x);
2441 #else
2442 return MSVCR120_round(x);
2443 #endif
2446 /*********************************************************************
2447 * lroundf (MSVCR120.@)
2449 MSVCRT_long CDECL MSVCR120_lroundf(float x)
2451 #ifdef HAVE_LROUNDF
2452 return lroundf(x);
2453 #else
2454 return MSVCR120_lround(x);
2455 #endif
2458 /*********************************************************************
2459 * lroundl (MSVCR120.@)
2461 MSVCRT_long CDECL MSVCR120_lroundl(LDOUBLE x)
2463 return MSVCR120_lround(x);
2466 /*********************************************************************
2467 * llround (MSVCR120.@)
2469 MSVCRT_longlong CDECL MSVCR120_llround(double x)
2471 #ifdef HAVE_LLROUND
2472 return llround(x);
2473 #else
2474 return MSVCR120_round(x);
2475 #endif
2478 /*********************************************************************
2479 * llroundf (MSVCR120.@)
2481 MSVCRT_longlong CDECL MSVCR120_llroundf(float x)
2483 #ifdef HAVE_LLROUNDF
2484 return llroundf(x);
2485 #else
2486 return MSVCR120_llround(x);
2487 #endif
2490 /*********************************************************************
2491 * roundl (MSVCR120.@)
2493 MSVCRT_longlong CDECL MSVCR120_llroundl(LDOUBLE x)
2495 return MSVCR120_llround(x);
2498 /*********************************************************************
2499 * trunc (MSVCR120.@)
2501 double CDECL MSVCR120_trunc(double x)
2503 #ifdef HAVE_TRUNC
2504 return trunc(x);
2505 #else
2506 return (x > 0) ? floor(x) : ceil(x);
2507 #endif
2510 /*********************************************************************
2511 * truncf (MSVCR120.@)
2513 float CDECL MSVCR120_truncf(float x)
2515 #ifdef HAVE_TRUNCF
2516 return truncf(x);
2517 #else
2518 return MSVCR120_trunc(x);
2519 #endif
2522 /*********************************************************************
2523 * truncl (MSVCR120.@)
2525 LDOUBLE CDECL MSVCR120_truncl(LDOUBLE x)
2527 return MSVCR120_trunc(x);
2530 /*********************************************************************
2531 * _dclass (MSVCR120.@)
2533 short CDECL MSVCR120__dclass(double x)
2535 switch (MSVCRT__fpclass(x)) {
2536 case MSVCRT__FPCLASS_QNAN:
2537 case MSVCRT__FPCLASS_SNAN:
2538 return MSVCRT_FP_NAN;
2539 case MSVCRT__FPCLASS_NINF:
2540 case MSVCRT__FPCLASS_PINF:
2541 return MSVCRT_FP_INFINITE;
2542 case MSVCRT__FPCLASS_ND:
2543 case MSVCRT__FPCLASS_PD:
2544 return MSVCRT_FP_SUBNORMAL;
2545 case MSVCRT__FPCLASS_NN:
2546 case MSVCRT__FPCLASS_PN:
2547 default:
2548 return MSVCRT_FP_NORMAL;
2549 case MSVCRT__FPCLASS_NZ:
2550 case MSVCRT__FPCLASS_PZ:
2551 return MSVCRT_FP_ZERO;
2555 /*********************************************************************
2556 * _fdclass (MSVCR120.@)
2558 short CDECL MSVCR120__fdclass(float x)
2560 return MSVCR120__dclass(x);
2563 /*********************************************************************
2564 * _ldclass (MSVCR120.@)
2566 short CDECL MSVCR120__ldclass(LDOUBLE x)
2568 return MSVCR120__dclass(x);