push bc3e5bf5ba806943a97979264a1f2e4a4dde5c94
[wine/hacks.git] / dlls / msvcrt / math.c
blobf06166bdaab19ab391cebbe5d3fd1533748612e5
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"
22 #include <stdio.h>
23 #define __USE_ISOC9X 1
24 #define __USE_ISOC99 1
25 #include <math.h>
26 #ifdef HAVE_IEEEFP_H
27 #include <ieeefp.h>
28 #endif
30 #include "msvcrt.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
36 #ifndef HAVE_FINITE
37 #ifndef finite /* Could be a macro */
38 #ifdef isfinite
39 #define finite(x) isfinite(x)
40 #else
41 #define finite(x) (!isnan(x)) /* At least catch some cases */
42 #endif
43 #endif
44 #endif
46 #ifndef signbit
47 #define signbit(x) 0
48 #endif
50 typedef int (*MSVCRT_matherr_func)(struct MSVCRT__exception *);
52 static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
54 /*********************************************************************
55 * MSVCRT_acos (MSVCRT.@)
57 double CDECL MSVCRT_acos( double x )
59 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
60 return acos(x);
63 /*********************************************************************
64 * MSVCRT_asin (MSVCRT.@)
66 double CDECL MSVCRT_asin( double x )
68 if (x < -1.0 || x > 1.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
69 return asin(x);
72 /*********************************************************************
73 * MSVCRT_atan (MSVCRT.@)
75 double CDECL MSVCRT_atan( double x )
77 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
78 return atan(x);
81 /*********************************************************************
82 * MSVCRT_atan2 (MSVCRT.@)
84 double CDECL MSVCRT_atan2( double x, double y )
86 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
87 return atan2(x,y);
90 /*********************************************************************
91 * MSVCRT_cos (MSVCRT.@)
93 double CDECL MSVCRT_cos( double x )
95 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
96 return cos(x);
99 /*********************************************************************
100 * MSVCRT_cosh (MSVCRT.@)
102 double CDECL MSVCRT_cosh( double x )
104 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
105 return cosh(x);
108 /*********************************************************************
109 * MSVCRT_exp (MSVCRT.@)
111 double CDECL MSVCRT_exp( double x )
113 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
114 return exp(x);
117 /*********************************************************************
118 * MSVCRT_fmod (MSVCRT.@)
120 double CDECL MSVCRT_fmod( double x, double y )
122 if (!finite(x) || !finite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
123 return fmod(x,y);
126 /*********************************************************************
127 * MSVCRT_log (MSVCRT.@)
129 double CDECL MSVCRT_log( double x)
131 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
132 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
133 return log(x);
136 /*********************************************************************
137 * MSVCRT_log10 (MSVCRT.@)
139 double CDECL MSVCRT_log10( double x )
141 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
142 if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
143 return log10(x);
146 /*********************************************************************
147 * MSVCRT_pow (MSVCRT.@)
149 double CDECL MSVCRT_pow( double x, double y )
151 /* FIXME: If x < 0 and y is not integral, set EDOM */
152 double z = pow(x,y);
153 if (!finite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
154 return z;
157 /*********************************************************************
158 * MSVCRT_sin (MSVCRT.@)
160 double CDECL MSVCRT_sin( double x )
162 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
163 return sin(x);
166 /*********************************************************************
167 * MSVCRT_sinh (MSVCRT.@)
169 double CDECL MSVCRT_sinh( double x )
171 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
172 return sinh(x);
175 /*********************************************************************
176 * MSVCRT_sqrt (MSVCRT.@)
178 double CDECL MSVCRT_sqrt( double x )
180 if (x < 0.0 || !finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
181 return sqrt(x);
184 /*********************************************************************
185 * MSVCRT_tan (MSVCRT.@)
187 double CDECL MSVCRT_tan( double x )
189 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
190 return tan(x);
193 /*********************************************************************
194 * MSVCRT_tanh (MSVCRT.@)
196 double CDECL MSVCRT_tanh( double x )
198 if (!finite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
199 return tanh(x);
203 #if defined(__GNUC__) && defined(__i386__)
205 #define FPU_DOUBLE(var) double var; \
206 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
207 #define FPU_DOUBLES(var1,var2) double var1,var2; \
208 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
209 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
211 /*********************************************************************
212 * _CIacos (MSVCRT.@)
214 double CDECL _CIacos(void)
216 FPU_DOUBLE(x);
217 return MSVCRT_acos(x);
220 /*********************************************************************
221 * _CIasin (MSVCRT.@)
223 double CDECL _CIasin(void)
225 FPU_DOUBLE(x);
226 return MSVCRT_asin(x);
229 /*********************************************************************
230 * _CIatan (MSVCRT.@)
232 double CDECL _CIatan(void)
234 FPU_DOUBLE(x);
235 return MSVCRT_atan(x);
238 /*********************************************************************
239 * _CIatan2 (MSVCRT.@)
241 double CDECL _CIatan2(void)
243 FPU_DOUBLES(x,y);
244 return MSVCRT_atan2(x,y);
247 /*********************************************************************
248 * _CIcos (MSVCRT.@)
250 double CDECL _CIcos(void)
252 FPU_DOUBLE(x);
253 return MSVCRT_cos(x);
256 /*********************************************************************
257 * _CIcosh (MSVCRT.@)
259 double CDECL _CIcosh(void)
261 FPU_DOUBLE(x);
262 return MSVCRT_cosh(x);
265 /*********************************************************************
266 * _CIexp (MSVCRT.@)
268 double CDECL _CIexp(void)
270 FPU_DOUBLE(x);
271 return MSVCRT_exp(x);
274 /*********************************************************************
275 * _CIfmod (MSVCRT.@)
277 double CDECL _CIfmod(void)
279 FPU_DOUBLES(x,y);
280 return MSVCRT_fmod(x,y);
283 /*********************************************************************
284 * _CIlog (MSVCRT.@)
286 double CDECL _CIlog(void)
288 FPU_DOUBLE(x);
289 return MSVCRT_log(x);
292 /*********************************************************************
293 * _CIlog10 (MSVCRT.@)
295 double CDECL _CIlog10(void)
297 FPU_DOUBLE(x);
298 return MSVCRT_log10(x);
301 /*********************************************************************
302 * _CIpow (MSVCRT.@)
304 double CDECL _CIpow(void)
306 FPU_DOUBLES(x,y);
307 return MSVCRT_pow(x,y);
310 /*********************************************************************
311 * _CIsin (MSVCRT.@)
313 double CDECL _CIsin(void)
315 FPU_DOUBLE(x);
316 return MSVCRT_sin(x);
319 /*********************************************************************
320 * _CIsinh (MSVCRT.@)
322 double CDECL _CIsinh(void)
324 FPU_DOUBLE(x);
325 return MSVCRT_sinh(x);
328 /*********************************************************************
329 * _CIsqrt (MSVCRT.@)
331 double CDECL _CIsqrt(void)
333 FPU_DOUBLE(x);
334 return MSVCRT_sqrt(x);
337 /*********************************************************************
338 * _CItan (MSVCRT.@)
340 double CDECL _CItan(void)
342 FPU_DOUBLE(x);
343 return MSVCRT_tan(x);
346 /*********************************************************************
347 * _CItanh (MSVCRT.@)
349 double CDECL _CItanh(void)
351 FPU_DOUBLE(x);
352 return MSVCRT_tanh(x);
355 #else /* defined(__GNUC__) && defined(__i386__) */
357 /* The above cannot be called on non x86 platforms, stub them for linking */
359 #define IX86_ONLY(func) double func(void) { return 0.0; }
361 IX86_ONLY(_CIacos)
362 IX86_ONLY(_CIasin)
363 IX86_ONLY(_CIatan)
364 IX86_ONLY(_CIatan2)
365 IX86_ONLY(_CIcos)
366 IX86_ONLY(_CIcosh)
367 IX86_ONLY(_CIexp)
368 IX86_ONLY(_CIfmod)
369 IX86_ONLY(_CIlog)
370 IX86_ONLY(_CIlog10)
371 IX86_ONLY(_CIpow)
372 IX86_ONLY(_CIsin)
373 IX86_ONLY(_CIsinh)
374 IX86_ONLY(_CIsqrt)
375 IX86_ONLY(_CItan)
376 IX86_ONLY(_CItanh)
378 #endif /* defined(__GNUC__) && defined(__i386__) */
380 /*********************************************************************
381 * _fpclass (MSVCRT.@)
383 int CDECL _fpclass(double num)
385 #if defined(HAVE_FPCLASS) || defined(fpclass)
386 switch (fpclass( num ))
388 #ifdef FP_SNAN
389 case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
390 #endif
391 #ifdef FP_QNAN
392 case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
393 #endif
394 #ifdef FP_NINF
395 case FP_NINF: return MSVCRT__FPCLASS_NINF;
396 #endif
397 #ifdef FP_PINF
398 case FP_PINF: return MSVCRT__FPCLASS_PINF;
399 #endif
400 #ifdef FP_NDENORM
401 case FP_NDENORM: return MSVCRT__FPCLASS_ND;
402 #endif
403 #ifdef FP_PDENORM
404 case FP_PDENORM: return MSVCRT__FPCLASS_PD;
405 #endif
406 #ifdef FP_NZERO
407 case FP_NZERO: return MSVCRT__FPCLASS_NZ;
408 #endif
409 #ifdef FP_PZERO
410 case FP_PZERO: return MSVCRT__FPCLASS_PZ;
411 #endif
412 #ifdef FP_NNORM
413 case FP_NNORM: return MSVCRT__FPCLASS_NN;
414 #endif
415 #ifdef FP_PNORM
416 case FP_PNORM: return MSVCRT__FPCLASS_PN;
417 #endif
419 return MSVCRT__FPCLASS_PN;
420 #elif defined (fpclassify)
421 switch (fpclassify( num ))
423 case FP_NAN: return MSVCRT__FPCLASS_QNAN;
424 case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
425 case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
426 case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
428 return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
429 #else
430 if (!finite(num))
431 return MSVCRT__FPCLASS_QNAN;
432 return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
433 #endif
436 /*********************************************************************
437 * _rotl (MSVCRT.@)
439 unsigned int CDECL _rotl(unsigned int num, int shift)
441 shift &= 31;
442 return (num << shift) | (num >> (32-shift));
445 /*********************************************************************
446 * _logb (MSVCRT.@)
448 double CDECL _logb(double num)
450 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
451 return logb(num);
454 /*********************************************************************
455 * _lrotl (MSVCRT.@)
457 unsigned long CDECL _lrotl(unsigned long num, int shift)
459 shift &= 0x1f;
460 return (num << shift) | (num >> (32-shift));
463 /*********************************************************************
464 * _lrotr (MSVCRT.@)
466 unsigned long CDECL _lrotr(unsigned long num, int shift)
468 shift &= 0x1f;
469 return (num >> shift) | (num << (32-shift));
472 /*********************************************************************
473 * _rotr (MSVCRT.@)
475 unsigned int CDECL _rotr(unsigned int num, int shift)
477 shift &= 0x1f;
478 return (num >> shift) | (num << (32-shift));
481 /*********************************************************************
482 * _scalb (MSVCRT.@)
484 double CDECL _scalb(double num, long power)
486 /* Note - Can't forward directly as libc expects y as double */
487 double dblpower = (double)power;
488 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
489 return scalb(num, dblpower);
492 /*********************************************************************
493 * _hypot (MSVCRT.@)
495 double CDECL _hypot(double x, double y)
497 /* FIXME: errno handling */
498 return hypot( x, y );
501 /*********************************************************************
502 * ceil (MSVCRT.@)
504 double CDECL MSVCRT_ceil( double x )
506 return ceil(x);
509 /*********************************************************************
510 * floor (MSVCRT.@)
512 double CDECL MSVCRT_floor( double x )
514 return floor(x);
517 /*********************************************************************
518 * fabs (MSVCRT.@)
520 double CDECL MSVCRT_fabs( double x )
522 return fabs(x);
525 /*********************************************************************
526 * frexp (MSVCRT.@)
528 double CDECL MSVCRT_frexp( double x, int *exp )
530 return frexp( x, exp );
533 /*********************************************************************
534 * modf (MSVCRT.@)
536 double CDECL MSVCRT_modf( double x, double *iptr )
538 return modf( x, iptr );
541 /*********************************************************************
542 * _matherr (MSVCRT.@)
544 int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
546 if (e)
547 TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
548 e->retval);
549 else
550 TRACE("(null)\n");
551 if (MSVCRT_default_matherr_func)
552 return MSVCRT_default_matherr_func(e);
553 ERR(":Unhandled math error!\n");
554 return 0;
557 /*********************************************************************
558 * __setusermatherr (MSVCRT.@)
560 void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
562 MSVCRT_default_matherr_func = func;
563 TRACE(":new matherr handler %p\n", func);
566 /**********************************************************************
567 * _statusfp (MSVCRT.@)
569 unsigned int CDECL _statusfp(void)
571 unsigned int retVal = 0;
572 #if defined(__GNUC__) && defined(__i386__)
573 unsigned int fpword;
575 __asm__ __volatile__( "fstsw %0" : "=m" (fpword) : );
576 if (fpword & 0x1) retVal |= MSVCRT__SW_INVALID;
577 if (fpword & 0x2) retVal |= MSVCRT__SW_DENORMAL;
578 if (fpword & 0x4) retVal |= MSVCRT__SW_ZERODIVIDE;
579 if (fpword & 0x8) retVal |= MSVCRT__SW_OVERFLOW;
580 if (fpword & 0x10) retVal |= MSVCRT__SW_UNDERFLOW;
581 if (fpword & 0x20) retVal |= MSVCRT__SW_INEXACT;
582 #else
583 FIXME(":Not implemented!\n");
584 #endif
585 return retVal;
588 /*********************************************************************
589 * _clearfp (MSVCRT.@)
591 unsigned int CDECL _clearfp(void)
593 unsigned int retVal = _statusfp();
594 #if defined(__GNUC__) && defined(__i386__)
595 __asm__ __volatile__( "fnclex" );
596 #else
597 FIXME(":Not Implemented\n");
598 #endif
599 return retVal;
602 /*********************************************************************
603 * __fpecode (MSVCRT.@)
605 int * CDECL __fpecode(void)
607 return &msvcrt_get_thread_data()->fpecode;
610 /*********************************************************************
611 * ldexp (MSVCRT.@)
613 double CDECL MSVCRT_ldexp(double num, long exp)
615 double z = ldexp(num,exp);
617 if (!finite(z))
618 *MSVCRT__errno() = MSVCRT_ERANGE;
619 else if (z == 0 && signbit(z))
620 z = 0.0; /* Convert -0 -> +0 */
621 return z;
624 /*********************************************************************
625 * _cabs (MSVCRT.@)
627 double CDECL MSVCRT__cabs(struct MSVCRT__complex num)
629 return sqrt(num.x * num.x + num.y * num.y);
632 /*********************************************************************
633 * _chgsign (MSVCRT.@)
635 double CDECL _chgsign(double num)
637 /* FIXME: +-infinity,Nan not tested */
638 return -num;
641 /*********************************************************************
642 * _control87 (MSVCRT.@)
644 unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
646 #if defined(__GNUC__) && defined(__i386__)
647 unsigned int fpword = 0;
648 unsigned int flags = 0;
650 TRACE("(%08x, %08x): Called\n", newval, mask);
652 /* Get fp control word */
653 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) : );
655 TRACE("Control word before : %08x\n", fpword);
657 /* Convert into mask constants */
658 if (fpword & 0x1) flags |= MSVCRT__EM_INVALID;
659 if (fpword & 0x2) flags |= MSVCRT__EM_DENORMAL;
660 if (fpword & 0x4) flags |= MSVCRT__EM_ZERODIVIDE;
661 if (fpword & 0x8) flags |= MSVCRT__EM_OVERFLOW;
662 if (fpword & 0x10) flags |= MSVCRT__EM_UNDERFLOW;
663 if (fpword & 0x20) flags |= MSVCRT__EM_INEXACT;
664 switch(fpword & 0xC00) {
665 case 0xC00: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break;
666 case 0x800: flags |= MSVCRT__RC_UP; break;
667 case 0x400: flags |= MSVCRT__RC_DOWN; break;
669 switch(fpword & 0x300) {
670 case 0x0: flags |= MSVCRT__PC_24; break;
671 case 0x200: flags |= MSVCRT__PC_53; break;
672 case 0x300: flags |= MSVCRT__PC_64; break;
674 if (fpword & 0x1000) flags |= MSVCRT__IC_AFFINE;
676 /* Mask with parameters */
677 flags = (flags & ~mask) | (newval & mask);
679 /* Convert (masked) value back to fp word */
680 fpword = 0;
681 if (flags & MSVCRT__EM_INVALID) fpword |= 0x1;
682 if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x2;
683 if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x4;
684 if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x8;
685 if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x10;
686 if (flags & MSVCRT__EM_INEXACT) fpword |= 0x20;
687 switch(flags & (MSVCRT__RC_UP | MSVCRT__RC_DOWN)) {
688 case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xC00; break;
689 case MSVCRT__RC_UP: fpword |= 0x800; break;
690 case MSVCRT__RC_DOWN: fpword |= 0x400; break;
692 switch (flags & (MSVCRT__PC_24 | MSVCRT__PC_53)) {
693 case MSVCRT__PC_64: fpword |= 0x300; break;
694 case MSVCRT__PC_53: fpword |= 0x200; break;
695 case MSVCRT__PC_24: fpword |= 0x0; break;
697 if (flags & MSVCRT__IC_AFFINE) fpword |= 0x1000;
699 TRACE("Control word after : %08x\n", fpword);
701 /* Put fp control word */
702 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
704 return flags;
705 #else
706 FIXME(":Not Implemented!\n");
707 return 0;
708 #endif
711 /*********************************************************************
712 * _controlfp (MSVCRT.@)
714 unsigned int CDECL _controlfp(unsigned int newval, unsigned int mask)
716 #ifdef __i386__
717 return _control87( newval, mask & ~MSVCRT__EM_DENORMAL );
718 #else
719 FIXME(":Not Implemented!\n");
720 return 0;
721 #endif
724 /*********************************************************************
725 * _copysign (MSVCRT.@)
727 double CDECL _copysign(double num, double sign)
729 /* FIXME: Behaviour for Nan/Inf? */
730 if (sign < 0.0)
731 return num < 0.0 ? num : -num;
732 return num < 0.0 ? -num : num;
735 /*********************************************************************
736 * _finite (MSVCRT.@)
738 int CDECL _finite(double num)
740 return (finite(num)?1:0); /* See comment for _isnan() */
743 /*********************************************************************
744 * _fpreset (MSVCRT.@)
746 void CDECL _fpreset(void)
748 #if defined(__GNUC__) && defined(__i386__)
749 __asm__ __volatile__( "fninit" );
750 #else
751 FIXME(":Not Implemented!\n");
752 #endif
755 /*********************************************************************
756 * _isnan (MSVCRT.@)
758 INT CDECL _isnan(double num)
760 /* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
761 * Do the same, as the result may be used in calculations
763 return isnan(num) ? 1 : 0;
766 /*********************************************************************
767 * _j0 (MSVCRT.@)
769 double CDECL _j0(double num)
771 /* FIXME: errno handling */
772 return j0(num);
775 /*********************************************************************
776 * _j1 (MSVCRT.@)
778 double CDECL _j1(double num)
780 /* FIXME: errno handling */
781 return j1(num);
784 /*********************************************************************
785 * jn (MSVCRT.@)
787 double CDECL _jn(int n, double num)
789 /* FIXME: errno handling */
790 return jn(n, num);
793 /*********************************************************************
794 * _y0 (MSVCRT.@)
796 double CDECL _y0(double num)
798 double retval;
799 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
800 retval = y0(num);
801 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
803 *MSVCRT__errno() = MSVCRT_EDOM;
804 retval = sqrt(-1);
806 return retval;
809 /*********************************************************************
810 * _y1 (MSVCRT.@)
812 double CDECL _y1(double num)
814 double retval;
815 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
816 retval = y1(num);
817 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
819 *MSVCRT__errno() = MSVCRT_EDOM;
820 retval = sqrt(-1);
822 return retval;
825 /*********************************************************************
826 * _yn (MSVCRT.@)
828 double CDECL _yn(int order, double num)
830 double retval;
831 if (!finite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
832 retval = yn(order,num);
833 if (_fpclass(retval) == MSVCRT__FPCLASS_NINF)
835 *MSVCRT__errno() = MSVCRT_EDOM;
836 retval = sqrt(-1);
838 return retval;
841 /*********************************************************************
842 * _nextafter (MSVCRT.@)
844 double CDECL _nextafter(double num, double next)
846 double retval;
847 if (!finite(num) || !finite(next)) *MSVCRT__errno() = MSVCRT_EDOM;
848 retval = nextafter(num,next);
849 return retval;
852 /*********************************************************************
853 * _ecvt (MSVCRT.@)
855 char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
857 thread_data_t *data = msvcrt_get_thread_data();
858 char *dec;
860 if (!data->efcvt_buffer)
861 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
863 snprintf(data->efcvt_buffer, 80, "%.*e", ndigits /* FIXME wrong */, number);
864 *sign = (number < 0);
865 dec = strchr(data->efcvt_buffer, '.');
866 *decpt = (dec) ? dec - data->efcvt_buffer : -1;
867 return data->efcvt_buffer;
870 /***********************************************************************
871 * _fcvt (MSVCRT.@)
873 char * CDECL _fcvt( double number, int ndigits, int *decpt, int *sign )
875 thread_data_t *data = msvcrt_get_thread_data();
876 char *dec;
878 if (!data->efcvt_buffer)
879 data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
881 snprintf(data->efcvt_buffer, 80, "%.*e", ndigits, number);
882 *sign = (number < 0);
883 dec = strchr(data->efcvt_buffer, '.');
884 *decpt = (dec) ? dec - data->efcvt_buffer : -1;
885 return data->efcvt_buffer;
888 /***********************************************************************
889 * _gcvt (MSVCRT.@)
891 * FIXME: uses both E and F.
893 char * CDECL _gcvt( double number, int ndigit, char *buff )
895 sprintf(buff, "%.*E", ndigit, number);
896 return buff;
899 #include <stdlib.h> /* div_t, ldiv_t */
901 /*********************************************************************
902 * div (MSVCRT.@)
903 * VERSION
904 * [i386] Windows binary compatible - returns the struct in eax/edx.
906 #ifdef __i386__
907 unsigned __int64 CDECL MSVCRT_div(int num, int denom)
909 div_t dt = div(num,denom);
910 return ((unsigned __int64)dt.rem << 32) | (unsigned int)dt.quot;
912 #else
913 /*********************************************************************
914 * div (MSVCRT.@)
915 * VERSION
916 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
918 MSVCRT_div_t CDECL MSVCRT_div(int num, int denom)
920 div_t dt = div(num,denom);
921 MSVCRT_div_t ret;
922 ret.quot = dt.quot;
923 ret.rem = dt.rem;
925 return ret;
928 #endif /* ifdef __i386__ */
931 /*********************************************************************
932 * ldiv (MSVCRT.@)
933 * VERSION
934 * [i386] Windows binary compatible - returns the struct in eax/edx.
936 #ifdef __i386__
937 unsigned __int64 CDECL MSVCRT_ldiv(long num, long denom)
939 ldiv_t ldt = ldiv(num,denom);
940 return ((unsigned __int64)ldt.rem << 32) | (unsigned long)ldt.quot;
942 #else
943 /*********************************************************************
944 * ldiv (MSVCRT.@)
945 * VERSION
946 * [!i386] Non-x86 can't run win32 apps so we don't need binary compatibility
948 MSVCRT_ldiv_t CDECL MSVCRT_ldiv(long num, long denom)
950 ldiv_t result = ldiv(num,denom);
952 MSVCRT_ldiv_t ret;
953 ret.quot = result.quot;
954 ret.rem = result.rem;
956 return ret;
958 #endif /* ifdef __i386__ */
960 /***********************************************************************
961 * _adj_fdiv_m16i (MSVCRT.@)
963 * NOTE
964 * I _think_ this function is intended to work around the Pentium
965 * fdiv bug.
967 void __stdcall _adj_fdiv_m16i( short arg )
969 TRACE("(): stub\n");
972 /***********************************************************************
973 * _adj_fdiv_m32 (MSVCRT.@)
975 * NOTE
976 * I _think_ this function is intended to work around the Pentium
977 * fdiv bug.
979 void __stdcall _adj_fdiv_m32( unsigned int arg )
981 TRACE("(): stub\n");
984 /***********************************************************************
985 * _adj_fdiv_m32i (MSVCRT.@)
987 * NOTE
988 * I _think_ this function is intended to work around the Pentium
989 * fdiv bug.
991 void __stdcall _adj_fdiv_m32i( int arg )
993 TRACE("(): stub\n");
996 /***********************************************************************
997 * _adj_fdiv_m64 (MSVCRT.@)
999 * NOTE
1000 * I _think_ this function is intended to work around the Pentium
1001 * fdiv bug.
1003 void __stdcall _adj_fdiv_m64( unsigned __int64 arg )
1005 TRACE("(): stub\n");
1008 /***********************************************************************
1009 * _adj_fdiv_r (MSVCRT.@)
1010 * FIXME
1011 * This function is likely to have the wrong number of arguments.
1013 * NOTE
1014 * I _think_ this function is intended to work around the Pentium
1015 * fdiv bug.
1017 void _adj_fdiv_r(void)
1019 TRACE("(): stub\n");
1022 /***********************************************************************
1023 * _adj_fdivr_m16i (MSVCRT.@)
1025 * NOTE
1026 * I _think_ this function is intended to work around the Pentium
1027 * fdiv bug.
1029 void __stdcall _adj_fdivr_m16i( short arg )
1031 TRACE("(): stub\n");
1034 /***********************************************************************
1035 * _adj_fdivr_m32 (MSVCRT.@)
1037 * NOTE
1038 * I _think_ this function is intended to work around the Pentium
1039 * fdiv bug.
1041 void __stdcall _adj_fdivr_m32( unsigned int arg )
1043 TRACE("(): stub\n");
1046 /***********************************************************************
1047 * _adj_fdivr_m32i (MSVCRT.@)
1049 * NOTE
1050 * I _think_ this function is intended to work around the Pentium
1051 * fdiv bug.
1053 void __stdcall _adj_fdivr_m32i( int arg )
1055 TRACE("(): stub\n");
1058 /***********************************************************************
1059 * _adj_fdivr_m64 (MSVCRT.@)
1061 * NOTE
1062 * I _think_ this function is intended to work around the Pentium
1063 * fdiv bug.
1065 void __stdcall _adj_fdivr_m64( unsigned __int64 arg )
1067 TRACE("(): stub\n");
1070 /***********************************************************************
1071 * _adj_fpatan (MSVCRT.@)
1072 * FIXME
1073 * This function is likely to have the wrong number of arguments.
1075 * NOTE
1076 * I _think_ this function is intended to work around the Pentium
1077 * fdiv bug.
1079 void _adj_fpatan(void)
1081 TRACE("(): stub\n");
1084 /***********************************************************************
1085 * _adj_fprem (MSVCRT.@)
1086 * FIXME
1087 * This function is likely to have the wrong number of arguments.
1089 * NOTE
1090 * I _think_ this function is intended to work around the Pentium
1091 * fdiv bug.
1093 void _adj_fprem(void)
1095 TRACE("(): stub\n");
1098 /***********************************************************************
1099 * _adj_fprem1 (MSVCRT.@)
1100 * FIXME
1101 * This function is likely to have the wrong number of arguments.
1103 * NOTE
1104 * I _think_ this function is intended to work around the Pentium
1105 * fdiv bug.
1107 void _adj_fprem1(void)
1109 TRACE("(): stub\n");
1112 /***********************************************************************
1113 * _adj_fptan (MSVCRT.@)
1114 * FIXME
1115 * This function is likely to have the wrong number of arguments.
1117 * NOTE
1118 * I _think_ this function is intended to work around the Pentium
1119 * fdiv bug.
1121 void _adj_fptan(void)
1123 TRACE("(): stub\n");
1126 /***********************************************************************
1127 * _adjust_fdiv (MSVCRT.@)
1128 * FIXME
1129 * I _think_ this function should be a variable indicating whether
1130 * Pentium fdiv bug safe code should be used.
1132 void _adjust_fdiv(void)
1134 TRACE("(): stub\n");
1137 /***********************************************************************
1138 * _safe_fdiv (MSVCRT.@)
1139 * FIXME
1140 * This function is likely to have the wrong number of arguments.
1142 * NOTE
1143 * I _think_ this function is intended to work around the Pentium
1144 * fdiv bug.
1146 void _safe_fdiv(void)
1148 TRACE("(): stub\n");
1151 /***********************************************************************
1152 * _safe_fdivr (MSVCRT.@)
1153 * FIXME
1154 * This function is likely to have the wrong number of arguments.
1156 * NOTE
1157 * I _think_ this function is intended to work around the Pentium
1158 * fdiv bug.
1160 void _safe_fdivr(void)
1162 TRACE("(): stub\n");
1165 /***********************************************************************
1166 * _safe_fprem (MSVCRT.@)
1167 * FIXME
1168 * This function is likely to have the wrong number of arguments.
1170 * NOTE
1171 * I _think_ this function is intended to work around the Pentium
1172 * fdiv bug.
1174 void _safe_fprem(void)
1176 TRACE("(): stub\n");
1179 /***********************************************************************
1180 * _safe_fprem1 (MSVCRT.@)
1182 * FIXME
1183 * This function is likely to have the wrong number of arguments.
1185 * NOTE
1186 * I _think_ this function is intended to work around the Pentium
1187 * fdiv bug.
1189 void _safe_fprem1(void)
1191 TRACE("(): stub\n");