forked from wine-mirror/wine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
math.c
2713 lines (2435 loc) · 67.4 KB
/
math.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* msvcrt.dll math functions
*
* Copyright 2000 Jon Griffiths
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#define __USE_ISOC9X 1
#define __USE_ISOC99 1
#include <math.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#include "msvcrt.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
#ifndef HAVE_FINITEF
#define finitef(x) isfinite(x)
#endif
#ifndef HAVE_ISNANF
#ifdef HAVE_ISNAN
#define isnanf(x) isnan(x)
#else
#define isnanf(x) 0
#endif
#endif
/* FIXME: Does not work with -NAN and -0. */
#ifndef signbit
#define signbit(x) ((x) < 0)
#endif
typedef int (CDECL *MSVCRT_matherr_func)(struct MSVCRT__exception *);
typedef double LDOUBLE; /* long double is just a double */
static MSVCRT_matherr_func MSVCRT_default_matherr_func = NULL;
static BOOL sse2_supported;
static BOOL sse2_enabled;
void msvcrt_init_math(void)
{
sse2_supported = sse2_enabled = IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE );
}
/*********************************************************************
* _set_SSE2_enable (MSVCRT.@)
*/
int CDECL MSVCRT__set_SSE2_enable(int flag)
{
sse2_enabled = flag && sse2_supported;
return sse2_enabled;
}
#if defined(__x86_64__) || defined(__arm__) || _MSVCR_VER>=120
/*********************************************************************
* _chgsignf (MSVCRT.@)
*/
float CDECL MSVCRT__chgsignf( float num )
{
/* FIXME: +-infinity,Nan not tested */
return -num;
}
/*********************************************************************
* _copysignf (MSVCRT.@)
*/
float CDECL MSVCRT__copysignf( float num, float sign )
{
if (signbit(sign))
return signbit(num) ? num : -num;
return signbit(num) ? -num : num;
}
/*********************************************************************
* _nextafterf (MSVCRT.@)
*/
float CDECL MSVCRT__nextafterf( float num, float next )
{
if (!finitef(num) || !finitef(next)) *MSVCRT__errno() = MSVCRT_EDOM;
return nextafterf( num, next );
}
#endif
#if defined(__x86_64__) || defined(__arm__)
/*********************************************************************
* _finitef (MSVCRT.@)
*/
int CDECL MSVCRT__finitef( float num )
{
return finitef(num) != 0; /* See comment for _isnan() */
}
/*********************************************************************
* _isnanf (MSVCRT.@)
*/
INT CDECL MSVCRT__isnanf( float num )
{
/* Some implementations return -1 for true(glibc), msvcrt/crtdll return 1.
* Do the same, as the result may be used in calculations
*/
return isnanf(num) != 0;
}
/*********************************************************************
* _logbf (MSVCRT.@)
*/
float CDECL MSVCRT__logbf( float num )
{
if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
return logbf(num);
}
/*********************************************************************
* MSVCRT_acosf (MSVCRT.@)
*/
float CDECL MSVCRT_acosf( float x )
{
if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
/* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
* asin() uses a similar construction. This is bad because as x gets nearer to
* 1 the error in the expression "1 - x^2" can get relatively large due to
* cancellation. The sqrt() makes things worse. A safer way to calculate
* acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
return atan2f(sqrtf((1 - x) * (1 + x)), x);
}
/*********************************************************************
* MSVCRT_asinf (MSVCRT.@)
*/
float CDECL MSVCRT_asinf( float x )
{
if (x < -1.0 || x > 1.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atan2f(x, sqrtf((1 - x) * (1 + x)));
}
/*********************************************************************
* MSVCRT_atanf (MSVCRT.@)
*/
float CDECL MSVCRT_atanf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atanf(x);
}
/*********************************************************************
* MSVCRT_atan2f (MSVCRT.@)
*/
float CDECL MSVCRT_atan2f( float x, float y )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atan2f(x,y);
}
/*********************************************************************
* MSVCRT_cosf (MSVCRT.@)
*/
float CDECL MSVCRT_cosf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return cosf(x);
}
/*********************************************************************
* MSVCRT_coshf (MSVCRT.@)
*/
float CDECL MSVCRT_coshf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return coshf(x);
}
/*********************************************************************
* MSVCRT_expf (MSVCRT.@)
*/
float CDECL MSVCRT_expf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return expf(x);
}
/*********************************************************************
* MSVCRT_fmodf (MSVCRT.@)
*/
float CDECL MSVCRT_fmodf( float x, float y )
{
if (!finitef(x) || !finitef(y)) *MSVCRT__errno() = MSVCRT_EDOM;
return fmodf(x,y);
}
/*********************************************************************
* MSVCRT_logf (MSVCRT.@)
*/
float CDECL MSVCRT_logf( float x)
{
if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
return logf(x);
}
/*********************************************************************
* MSVCRT_log10f (MSVCRT.@)
*/
float CDECL MSVCRT_log10f( float x )
{
if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
return log10f(x);
}
/*********************************************************************
* MSVCRT_powf (MSVCRT.@)
*/
float CDECL MSVCRT_powf( float x, float y )
{
/* FIXME: If x < 0 and y is not integral, set EDOM */
float z = powf(x,y);
if (!finitef(z)) *MSVCRT__errno() = MSVCRT_EDOM;
return z;
}
/*********************************************************************
* MSVCRT_sinf (MSVCRT.@)
*/
float CDECL MSVCRT_sinf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sinf(x);
}
/*********************************************************************
* MSVCRT_sinhf (MSVCRT.@)
*/
float CDECL MSVCRT_sinhf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sinhf(x);
}
/*********************************************************************
* MSVCRT_sqrtf (MSVCRT.@)
*/
float CDECL MSVCRT_sqrtf( float x )
{
if (x < 0.0 || !finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sqrtf(x);
}
/*********************************************************************
* MSVCRT_tanf (MSVCRT.@)
*/
float CDECL MSVCRT_tanf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return tanf(x);
}
/*********************************************************************
* MSVCRT_tanhf (MSVCRT.@)
*/
float CDECL MSVCRT_tanhf( float x )
{
if (!finitef(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return tanhf(x);
}
/*********************************************************************
* ceilf (MSVCRT.@)
*/
float CDECL MSVCRT_ceilf( float x )
{
return ceilf(x);
}
/*********************************************************************
* fabsf (MSVCRT.@)
*/
float CDECL MSVCRT_fabsf( float x )
{
return fabsf(x);
}
/*********************************************************************
* floorf (MSVCRT.@)
*/
float CDECL MSVCRT_floorf( float x )
{
return floorf(x);
}
/*********************************************************************
* frexpf (MSVCRT.@)
*/
float CDECL MSVCRT_frexpf( float x, int *exp )
{
return frexpf( x, exp );
}
/*********************************************************************
* _scalbf (MSVCRT.@)
*/
float CDECL MSVCRT__scalbf(float num, MSVCRT_long power)
{
if (!finitef(num)) *MSVCRT__errno() = MSVCRT_EDOM;
return ldexpf(num, power);
}
/*********************************************************************
* modff (MSVCRT.@)
*/
double CDECL MSVCRT_modff( float x, float *iptr )
{
return modff( x, iptr );
}
#endif
/*********************************************************************
* MSVCRT_acos (MSVCRT.@)
*/
double CDECL MSVCRT_acos( double x )
{
if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
/* glibc implements acos() as the FPU equivalent of atan2(sqrt(1 - x ^ 2), x).
* asin() uses a similar construction. This is bad because as x gets nearer to
* 1 the error in the expression "1 - x^2" can get relatively large due to
* cancellation. The sqrt() makes things worse. A safer way to calculate
* acos() is to use atan2(sqrt((1 - x) * (1 + x)), x). */
return atan2(sqrt((1 - x) * (1 + x)), x);
}
/*********************************************************************
* MSVCRT_asin (MSVCRT.@)
*/
double CDECL MSVCRT_asin( double x )
{
if (x < -1.0 || x > 1.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atan2(x, sqrt((1 - x) * (1 + x)));
}
/*********************************************************************
* MSVCRT_atan (MSVCRT.@)
*/
double CDECL MSVCRT_atan( double x )
{
if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atan(x);
}
/*********************************************************************
* MSVCRT_atan2 (MSVCRT.@)
*/
double CDECL MSVCRT_atan2( double x, double y )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return atan2(x,y);
}
/*********************************************************************
* MSVCRT_cos (MSVCRT.@)
*/
double CDECL MSVCRT_cos( double x )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return cos(x);
}
/*********************************************************************
* MSVCRT_cosh (MSVCRT.@)
*/
double CDECL MSVCRT_cosh( double x )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return cosh(x);
}
/*********************************************************************
* MSVCRT_exp (MSVCRT.@)
*/
double CDECL MSVCRT_exp( double x )
{
if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return exp(x);
}
/*********************************************************************
* MSVCRT_fmod (MSVCRT.@)
*/
double CDECL MSVCRT_fmod( double x, double y )
{
if (!isfinite(x) || !isfinite(y)) *MSVCRT__errno() = MSVCRT_EDOM;
return fmod(x,y);
}
/*********************************************************************
* MSVCRT_log (MSVCRT.@)
*/
double CDECL MSVCRT_log( double x)
{
if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
return log(x);
}
/*********************************************************************
* MSVCRT_log10 (MSVCRT.@)
*/
double CDECL MSVCRT_log10( double x )
{
if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
if (x == 0.0) *MSVCRT__errno() = MSVCRT_ERANGE;
return log10(x);
}
/*********************************************************************
* MSVCRT_pow (MSVCRT.@)
*/
double CDECL MSVCRT_pow( double x, double y )
{
/* FIXME: If x < 0 and y is not integral, set EDOM */
double z = pow(x,y);
if (!isfinite(z)) *MSVCRT__errno() = MSVCRT_EDOM;
return z;
}
/*********************************************************************
* MSVCRT_sin (MSVCRT.@)
*/
double CDECL MSVCRT_sin( double x )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sin(x);
}
/*********************************************************************
* MSVCRT_sinh (MSVCRT.@)
*/
double CDECL MSVCRT_sinh( double x )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sinh(x);
}
/*********************************************************************
* MSVCRT_sqrt (MSVCRT.@)
*/
double CDECL MSVCRT_sqrt( double x )
{
if (x < 0.0 || !isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return sqrt(x);
}
/*********************************************************************
* MSVCRT_tan (MSVCRT.@)
*/
double CDECL MSVCRT_tan( double x )
{
if (!isfinite(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return tan(x);
}
/*********************************************************************
* MSVCRT_tanh (MSVCRT.@)
*/
double CDECL MSVCRT_tanh( double x )
{
if (isnan(x)) *MSVCRT__errno() = MSVCRT_EDOM;
return tanh(x);
}
#if defined(__GNUC__) && defined(__i386__)
#define FPU_DOUBLE(var) double var; \
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
#define FPU_DOUBLES(var1,var2) double var1,var2; \
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
__asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
/*********************************************************************
* _CIacos (MSVCRT.@)
*/
double CDECL _CIacos(void)
{
FPU_DOUBLE(x);
return MSVCRT_acos(x);
}
/*********************************************************************
* _CIasin (MSVCRT.@)
*/
double CDECL _CIasin(void)
{
FPU_DOUBLE(x);
return MSVCRT_asin(x);
}
/*********************************************************************
* _CIatan (MSVCRT.@)
*/
double CDECL _CIatan(void)
{
FPU_DOUBLE(x);
return MSVCRT_atan(x);
}
/*********************************************************************
* _CIatan2 (MSVCRT.@)
*/
double CDECL _CIatan2(void)
{
FPU_DOUBLES(x,y);
return MSVCRT_atan2(x,y);
}
/*********************************************************************
* _CIcos (MSVCRT.@)
*/
double CDECL _CIcos(void)
{
FPU_DOUBLE(x);
return MSVCRT_cos(x);
}
/*********************************************************************
* _CIcosh (MSVCRT.@)
*/
double CDECL _CIcosh(void)
{
FPU_DOUBLE(x);
return MSVCRT_cosh(x);
}
/*********************************************************************
* _CIexp (MSVCRT.@)
*/
double CDECL _CIexp(void)
{
FPU_DOUBLE(x);
return MSVCRT_exp(x);
}
/*********************************************************************
* _CIfmod (MSVCRT.@)
*/
double CDECL _CIfmod(void)
{
FPU_DOUBLES(x,y);
return MSVCRT_fmod(x,y);
}
/*********************************************************************
* _CIlog (MSVCRT.@)
*/
double CDECL _CIlog(void)
{
FPU_DOUBLE(x);
return MSVCRT_log(x);
}
/*********************************************************************
* _CIlog10 (MSVCRT.@)
*/
double CDECL _CIlog10(void)
{
FPU_DOUBLE(x);
return MSVCRT_log10(x);
}
/*********************************************************************
* _CIpow (MSVCRT.@)
*/
double CDECL _CIpow(void)
{
FPU_DOUBLES(x,y);
return MSVCRT_pow(x,y);
}
/*********************************************************************
* _CIsin (MSVCRT.@)
*/
double CDECL _CIsin(void)
{
FPU_DOUBLE(x);
return MSVCRT_sin(x);
}
/*********************************************************************
* _CIsinh (MSVCRT.@)
*/
double CDECL _CIsinh(void)
{
FPU_DOUBLE(x);
return MSVCRT_sinh(x);
}
/*********************************************************************
* _CIsqrt (MSVCRT.@)
*/
double CDECL _CIsqrt(void)
{
FPU_DOUBLE(x);
return MSVCRT_sqrt(x);
}
/*********************************************************************
* _CItan (MSVCRT.@)
*/
double CDECL _CItan(void)
{
FPU_DOUBLE(x);
return MSVCRT_tan(x);
}
/*********************************************************************
* _CItanh (MSVCRT.@)
*/
double CDECL _CItanh(void)
{
FPU_DOUBLE(x);
return MSVCRT_tanh(x);
}
/*********************************************************************
* _ftol (MSVCRT.@)
*/
LONGLONG CDECL MSVCRT__ftol(void)
{
FPU_DOUBLE(x);
return (LONGLONG)x;
}
#endif /* defined(__GNUC__) && defined(__i386__) */
/*********************************************************************
* _fpclass (MSVCRT.@)
*/
int CDECL MSVCRT__fpclass(double num)
{
#if defined(HAVE_FPCLASS) || defined(fpclass)
switch (fpclass( num ))
{
#ifdef FP_SNAN
case FP_SNAN: return MSVCRT__FPCLASS_SNAN;
#endif
#ifdef FP_QNAN
case FP_QNAN: return MSVCRT__FPCLASS_QNAN;
#endif
#ifdef FP_NINF
case FP_NINF: return MSVCRT__FPCLASS_NINF;
#endif
#ifdef FP_PINF
case FP_PINF: return MSVCRT__FPCLASS_PINF;
#endif
#ifdef FP_NDENORM
case FP_NDENORM: return MSVCRT__FPCLASS_ND;
#endif
#ifdef FP_PDENORM
case FP_PDENORM: return MSVCRT__FPCLASS_PD;
#endif
#ifdef FP_NZERO
case FP_NZERO: return MSVCRT__FPCLASS_NZ;
#endif
#ifdef FP_PZERO
case FP_PZERO: return MSVCRT__FPCLASS_PZ;
#endif
#ifdef FP_NNORM
case FP_NNORM: return MSVCRT__FPCLASS_NN;
#endif
#ifdef FP_PNORM
case FP_PNORM: return MSVCRT__FPCLASS_PN;
#endif
default: return MSVCRT__FPCLASS_PN;
}
#elif defined (fpclassify)
switch (fpclassify( num ))
{
case FP_NAN: return MSVCRT__FPCLASS_QNAN;
case FP_INFINITE: return signbit(num) ? MSVCRT__FPCLASS_NINF : MSVCRT__FPCLASS_PINF;
case FP_SUBNORMAL: return signbit(num) ?MSVCRT__FPCLASS_ND : MSVCRT__FPCLASS_PD;
case FP_ZERO: return signbit(num) ? MSVCRT__FPCLASS_NZ : MSVCRT__FPCLASS_PZ;
}
return signbit(num) ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN;
#else
if (!isfinite(num))
return MSVCRT__FPCLASS_QNAN;
return num == 0.0 ? MSVCRT__FPCLASS_PZ : (num < 0 ? MSVCRT__FPCLASS_NN : MSVCRT__FPCLASS_PN);
#endif
}
/*********************************************************************
* _rotl (MSVCRT.@)
*/
unsigned int CDECL _rotl(unsigned int num, int shift)
{
shift &= 31;
return (num << shift) | (num >> (32-shift));
}
/*********************************************************************
* _lrotl (MSVCRT.@)
*/
MSVCRT_ulong CDECL MSVCRT__lrotl(MSVCRT_ulong num, int shift)
{
shift &= 0x1f;
return (num << shift) | (num >> (32-shift));
}
/*********************************************************************
* _lrotr (MSVCRT.@)
*/
MSVCRT_ulong CDECL MSVCRT__lrotr(MSVCRT_ulong num, int shift)
{
shift &= 0x1f;
return (num >> shift) | (num << (32-shift));
}
/*********************************************************************
* _rotr (MSVCRT.@)
*/
unsigned int CDECL _rotr(unsigned int num, int shift)
{
shift &= 0x1f;
return (num >> shift) | (num << (32-shift));
}
/*********************************************************************
* _rotl64 (MSVCRT.@)
*/
unsigned __int64 CDECL _rotl64(unsigned __int64 num, int shift)
{
shift &= 63;
return (num << shift) | (num >> (64-shift));
}
/*********************************************************************
* _rotr64 (MSVCRT.@)
*/
unsigned __int64 CDECL _rotr64(unsigned __int64 num, int shift)
{
shift &= 63;
return (num >> shift) | (num << (64-shift));
}
/*********************************************************************
* abs (MSVCRT.@)
*/
int CDECL MSVCRT_abs( int n )
{
return n >= 0 ? n : -n;
}
/*********************************************************************
* labs (MSVCRT.@)
*/
MSVCRT_long CDECL MSVCRT_labs( MSVCRT_long n )
{
return n >= 0 ? n : -n;
}
/*********************************************************************
* llabs (MSVCRT.@)
*/
MSVCRT_longlong CDECL MSVCRT_llabs( MSVCRT_longlong n )
{
return n >= 0 ? n : -n;
}
/*********************************************************************
* _abs64 (MSVCRT.@)
*/
__int64 CDECL _abs64( __int64 n )
{
return n >= 0 ? n : -n;
}
/*********************************************************************
* _logb (MSVCRT.@)
*/
double CDECL MSVCRT__logb(double num)
{
if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
return logb(num);
}
/*********************************************************************
* _scalb (MSVCRT.@)
*/
double CDECL MSVCRT__scalb(double num, MSVCRT_long power)
{
if (!isfinite(num)) *MSVCRT__errno() = MSVCRT_EDOM;
return ldexp(num, power);
}
/*********************************************************************
* _hypot (MSVCRT.@)
*/
double CDECL _hypot(double x, double y)
{
/* FIXME: errno handling */
return hypot( x, y );
}
/*********************************************************************
* _hypotf (MSVCRT.@)
*/
float CDECL MSVCRT__hypotf(float x, float y)
{
/* FIXME: errno handling */
return hypotf( x, y );
}
/*********************************************************************
* ceil (MSVCRT.@)
*/
double CDECL MSVCRT_ceil( double x )
{
return ceil(x);
}
/*********************************************************************
* floor (MSVCRT.@)
*/
double CDECL MSVCRT_floor( double x )
{
return floor(x);
}
/*********************************************************************
* fabs (MSVCRT.@)
*/
double CDECL MSVCRT_fabs( double x )
{
return fabs(x);
}
/*********************************************************************
* frexp (MSVCRT.@)
*/
double CDECL MSVCRT_frexp( double x, int *exp )
{
return frexp( x, exp );
}
/*********************************************************************
* modf (MSVCRT.@)
*/
double CDECL MSVCRT_modf( double x, double *iptr )
{
return modf( x, iptr );
}
/*********************************************************************
* _matherr (MSVCRT.@)
*/
int CDECL MSVCRT__matherr(struct MSVCRT__exception *e)
{
if (e)
TRACE("(%p = %d, %s, %g %g %g)\n",e, e->type, e->name, e->arg1, e->arg2,
e->retval);
else
TRACE("(null)\n");
if (MSVCRT_default_matherr_func)
return MSVCRT_default_matherr_func(e);
ERR(":Unhandled math error!\n");
return 0;
}
/*********************************************************************
* __setusermatherr (MSVCRT.@)
*/
void CDECL MSVCRT___setusermatherr(MSVCRT_matherr_func func)
{
MSVCRT_default_matherr_func = func;
TRACE(":new matherr handler %p\n", func);
}
/**********************************************************************
* _statusfp2 (MSVCRT.@)
*
* Not exported by native msvcrt, added in msvcr80.
*/
#if defined(__i386__) || defined(__x86_64__)
void CDECL _statusfp2( unsigned int *x86_sw, unsigned int *sse2_sw )
{
#ifdef __GNUC__
unsigned int flags;
unsigned long fpword;
if (x86_sw)
{
__asm__ __volatile__( "fstsw %0" : "=m" (fpword) );
flags = 0;
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
*x86_sw = flags;
}
if (!sse2_sw) return;
if (sse2_supported)
{
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
flags = 0;
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
*sse2_sw = flags;
}
else *sse2_sw = 0;
#else
FIXME( "not implemented\n" );
#endif
}
#endif
/**********************************************************************
* _statusfp (MSVCRT.@)
*/
unsigned int CDECL _statusfp(void)
{
#if defined(__i386__) || defined(__x86_64__)
unsigned int x86_sw, sse2_sw;
_statusfp2( &x86_sw, &sse2_sw );
/* FIXME: there's no definition for ambiguous status, just return all status bits for now */
return x86_sw | sse2_sw;
#else
FIXME( "not implemented\n" );
return 0;
#endif
}
/*********************************************************************
* _clearfp (MSVCRT.@)
*/
unsigned int CDECL _clearfp(void)
{
unsigned int flags = 0;
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
unsigned long fpword;
__asm__ __volatile__( "fnstsw %0; fnclex" : "=m" (fpword) );
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
if (sse2_supported)
{
__asm__ __volatile__( "stmxcsr %0" : "=m" (fpword) );
if (fpword & 0x1) flags |= MSVCRT__SW_INVALID;
if (fpword & 0x2) flags |= MSVCRT__SW_DENORMAL;
if (fpword & 0x4) flags |= MSVCRT__SW_ZERODIVIDE;
if (fpword & 0x8) flags |= MSVCRT__SW_OVERFLOW;
if (fpword & 0x10) flags |= MSVCRT__SW_UNDERFLOW;
if (fpword & 0x20) flags |= MSVCRT__SW_INEXACT;
fpword &= ~0x3f;
__asm__ __volatile__( "ldmxcsr %0" : : "m" (fpword) );
}
#else
FIXME( "not implemented\n" );
#endif
return flags;
}
/*********************************************************************
* __fpecode (MSVCRT.@)