/
math.d
4764 lines (4217 loc) · 109 KB
/
math.d
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
/**
* D header file for C99.
*
* $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_math.h.html, _math.h)
*
* Copyright: Copyright Sean Kelly 2005 - 2012.
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Sean Kelly
* Source: $(DRUNTIMESRC core/stdc/_math.d)
*/
module core.stdc.math;
import core.stdc.config;
version (OSX)
version = Darwin;
else version (iOS)
version = Darwin;
else version (TVOS)
version = Darwin;
else version (WatchOS)
version = Darwin;
version (ARM) version = ARM_Any;
version (AArch64) version = ARM_Any;
version (HPPA) version = HPPA_Any;
version (MIPS32) version = MIPS_Any;
version (MIPS64) version = MIPS_Any;
version (PPC) version = PPC_Any;
version (PPC64) version = PPC_Any;
version (RISCV32) version = RISCV_Any;
version (RISCV64) version = RISCV_Any;
version (S390) version = IBMZ_Any;
version (SPARC) version = SPARC_Any;
version (SPARC64) version = SPARC_Any;
version (SystemZ) version = IBMZ_Any;
version (X86) version = X86_Any;
version (X86_64) version = X86_Any;
extern (C):
@trusted: // All functions here operate on floating point and integer values only.
nothrow:
@nogc:
///
alias float float_t;
///
alias double double_t;
///
enum double HUGE_VAL = double.infinity;
///
enum double HUGE_VALF = float.infinity;
///
enum double HUGE_VALL = real.infinity;
///
enum float INFINITY = float.infinity;
///
enum float NAN = float.nan;
version (FreeBSD)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (NetBSD)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (OpenBSD)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (DragonFlyBSD)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (Solaris)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (CRuntime_Bionic)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (CRuntime_UClibc)
{
version (X86_Any)
{
///
enum int FP_ILOGB0 = int.min;
///
enum int FP_ILOGBNAN = int.min;
}
else version (MIPS_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (ARM)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else
{
static assert(false, "Architecture not supported.");
}
}
else version (CRuntime_Glibc)
{
version (X86_Any)
{
///
enum int FP_ILOGB0 = int.min;
///
enum int FP_ILOGBNAN = int.min;
}
else version (ARM_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (HPPA_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (MIPS_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (PPC_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (RISCV_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (SPARC_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else version (IBMZ_Any)
{
///
enum int FP_ILOGB0 = -int.max;
///
enum int FP_ILOGBNAN = int.max;
}
else
{
static assert(false, "Architecture not supported.");
}
}
else
{
///
enum int FP_ILOGB0 = int.min;
///
enum int FP_ILOGBNAN = int.min;
}
///
enum int MATH_ERRNO = 1;
///
enum int MATH_ERREXCEPT = 2;
///
enum int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT;
version (none)
{
//
// these functions are all macros in C
//
//int fpclassify(real-floating x);
pure int fpclassify(float x);
pure int fpclassify(double x);
pure int fpclassify(real x);
//int isfinite(real-floating x);
pure int isfinite(float x);
pure int isfinite(double x);
pure int isfinite(real x);
//int isinf(real-floating x);
pure int isinf(float x);
pure int isinf(double x);
pure int isinf(real x);
//int isnan(real-floating x);
pure int isnan(float x);
pure int isnan(double x);
pure int isnan(real x);
//int isnormal(real-floating x);
pure int isnormal(float x);
pure int isnormal(double x);
pure int isnormal(real x);
//int signbit(real-floating x);
pure int signbit(float x);
pure int signbit(double x);
pure int signbit(real x);
//int isgreater(real-floating x, real-floating y);
pure int isgreater(float x, float y);
pure int isgreater(double x, double y);
pure int isgreater(real x, real y);
//int isgreaterequal(real-floating x, real-floating y);
pure int isgreaterequal(float x, float y);
pure int isgreaterequal(double x, double y);
pure int isgreaterequal(real x, real y);
//int isless(real-floating x, real-floating y);
pure int isless(float x, float y);
pure int isless(double x, double y);
pure int isless(real x, real y);
//int islessequal(real-floating x, real-floating y);
pure int islessequal(float x, float y);
pure int islessequal(double x, double y);
pure int islessequal(real x, real y);
//int islessgreater(real-floating x, real-floating y);
pure int islessgreater(float x, float y);
pure int islessgreater(double x, double y);
pure int islessgreater(real x, real y);
//int isunordered(real-floating x, real-floating y);
pure int isunordered(float x, float y);
pure int isunordered(double x, double y);
pure int isunordered(real x, real y);
}
version (CRuntime_DigitalMars)
{
enum
{
///
FP_NANS = 0,
///
FP_NANQ = 1,
///
FP_INFINITE = 2,
///
FP_NORMAL = 3,
///
FP_SUBNORMAL = 4,
///
FP_ZERO = 5,
///
FP_NAN = FP_NANQ,
///
FP_EMPTY = 6,
///
FP_UNSUPPORTED = 7,
}
enum
{
///
FP_FAST_FMA = 0,
///
FP_FAST_FMAF = 0,
///
FP_FAST_FMAL = 0,
}
pure uint __fpclassify_f(float x);
pure uint __fpclassify_d(double x);
pure uint __fpclassify_ld(real x);
//int fpclassify(real-floating x);
///
pragma(mangle, "__fpclassify_f") pure int fpclassify(float x);
///
pragma(mangle, "__fpclassify_d") pure int fpclassify(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify_d" : "__fpclassify_ld")
pure int fpclassify(real x);
extern (D)
{
//int isfinite(real-floating x);
///
pure int isfinite(float x) { return fpclassify(x) >= FP_NORMAL; }
///
pure int isfinite(double x) { return fpclassify(x) >= FP_NORMAL; }
///
pure int isfinite(real x) { return fpclassify(x) >= FP_NORMAL; }
//int isinf(real-floating x);
///
pure int isinf(float x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf(double x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf(real x) { return fpclassify(x) == FP_INFINITE; }
//int isnan(real-floating x);
///
pure int isnan(float x) { return fpclassify(x) <= FP_NANQ; }
///
pure int isnan(double x) { return fpclassify(x) <= FP_NANQ; }
///
pure int isnan(real x) { return fpclassify(x) <= FP_NANQ; }
//int isnormal(real-floating x);
///
pure int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
///
pure int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
///
pure int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
//int signbit(real-floating x);
///
pure int signbit(float x) { return (cast(short*)&(x))[1] & 0x8000; }
///
pure int signbit(double x) { return (cast(short*)&(x))[3] & 0x8000; }
///
pure int signbit(real x)
{
return (real.sizeof == double.sizeof)
? (cast(short*)&(x))[3] & 0x8000
: (cast(short*)&(x))[4] & 0x8000;
}
}
}
else version (CRuntime_Microsoft) // fully supported since MSVCRT 12 (VS 2013) only
{
version (all) // legacy stuff to be removed in the future
{
enum
{
_FPCLASS_SNAN = 1,
_FPCLASS_QNAN = 2,
_FPCLASS_NINF = 4,
_FPCLASS_NN = 8,
_FPCLASS_ND = 0x10,
_FPCLASS_NZ = 0x20,
_FPCLASS_PZ = 0x40,
_FPCLASS_PD = 0x80,
_FPCLASS_PN = 0x100,
_FPCLASS_PINF = 0x200,
}
//deprecated("Please use the standard C99 function copysignf() instead.")
pure float _copysignf(float x, float s);
//deprecated("_chgsignf(x) is a non-standard MS extension. Please consider using -x instead.")
pure float _chgsignf(float x);
version (Win64) // not available in 32-bit runtimes
{
//deprecated("Please use the standard C99 function isfinite() instead.")
pure int _finitef(float x);
//deprecated("Please use the standard C99 function isnan() instead.")
pure int _isnanf(float x);
//deprecated("Please use the standard C99 function fpclassify() instead.")
pure int _fpclassf(float x);
}
//deprecated("Please use the standard C99 function copysign() instead.")
pure double _copysign(double x, double s);
//deprecated("_chgsign(x) is a non-standard MS extension. Please consider using -x instead.")
pure double _chgsign(double x);
//deprecated("Please use the standard C99 function isfinite() instead.")
pure int _finite(double x);
//deprecated("Please use the standard C99 function isnan() instead.")
pure int _isnan(double x);
//deprecated("Please use the standard C99 function fpclassify() instead.")
pure int _fpclass(double x);
}
version (MinGW)
{
enum
{
///
FP_NAN = 0x0100,
///
FP_NORMAL = 0x0400,
///
FP_INFINITE = FP_NAN | FP_NORMAL,
///
FP_ZERO = 0x0400,
///
FP_SUBNORMAL = FP_NORMAL | FP_ZERO
}
pure int __fpclassifyf(float x);
pure int __fpclassify(double x);
pure int __fpclassifyl(real x);
pure int __isnanf(float x);
pure int __isnan(double x);
pure int __isnanl(real x);
pure int __signbitf(float x);
pure int __signbit(double x);
pure int __signbitl(real x);
//int fpclassify(real-floating x);
///
pragma(mangle, "__fpclassifyf") pure int fpclassify(float x);
///
pragma(mangle, "__fpclassify") pure int fpclassify(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl")
pure int fpclassify(real x);
extern (D)
{
//int isfinite(real-floating x);
///
pure int isfinite(float x) { return (fpclassify(x) & FP_NORMAL) == 0; }
///
pure int isfinite(double x) { return (fpclassify(x) & FP_NORMAL) == 0; }
///
pure int isfinite(real x) { return (fpclassify(x) & FP_NORMAL) == 0; }
//int isinf(real-floating x);
///
pure int isinf(float x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf(double x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf(real x) { return fpclassify(x) == FP_INFINITE; }
}
//int isnan(real-floating x);
///
pragma(mangle, "__isnanf") pure int isnan(float x);
///
pragma(mangle, "__isnan") pure int isnan(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__isnan" : "__isnanl")
pure int isnan(real x);
extern (D)
{
//int isnormal(real-floating x);
///
int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
}
//int signbit(real-floating x);
///
pragma(mangle, "__signbitf") pure int signbit(float x);
///
pragma(mangle, "__signbit") pure int signbit(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl")
int signbit(real x);
}
else
{
enum
{
///
FP_SUBNORMAL = -2,
///
FP_NORMAL = -1,
///
FP_ZERO = 0,
///
FP_INFINITE = 1,
///
FP_NAN = 2,
}
extern(D)
{
//int fpclassify(real-floating x);
///
extern(C) pragma(mangle, "_fdclass") pure int fpclassify(float x);
///
extern(C) pragma(mangle, "_dclass") pure int fpclassify(double x);
///
pure int fpclassify()(real x)
{
static if (real.sizeof == double.sizeof)
return fpclassify(cast(double) x);
else
static assert(false, "fpclassify(real) not supported by MS C runtime");
}
//int isfinite(real-floating x);
///
pure int isfinite()(float x) { return fpclassify(x) <= 0; }
///
pure int isfinite()(double x) { return fpclassify(x) <= 0; }
///
pure int isfinite()(real x) { return fpclassify(x) <= 0; }
//int isinf(real-floating x);
///
pure int isinf()(float x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf()(double x) { return fpclassify(x) == FP_INFINITE; }
///
pure int isinf()(real x) { return fpclassify(x) == FP_INFINITE; }
//int isnan(real-floating x);
version (none) // requires MSVCRT 12+ (VS 2013)
{
///
pure int isnan(float x) { return fpclassify(x) == FP_NAN; }
///
pure int isnan(double x) { return fpclassify(x) == FP_NAN; }
///
pure int isnan(real x) { return fpclassify(x) == FP_NAN; }
}
else // for backward compatibility with older runtimes
{
///
pure int isnan(float x) { version (Win64) return _isnanf(x); else return _isnan(cast(double) x); }
///
extern(C) pragma(mangle, "_isnan") pure int isnan(double x);
///
pure int isnan(real x) { return _isnan(cast(double) x); }
}
//int isnormal(real-floating x);
///
pure int isnormal()(float x) { return fpclassify(x) == FP_NORMAL; }
///
pure int isnormal()(double x) { return fpclassify(x) == FP_NORMAL; }
///
pure int isnormal()(real x) { return fpclassify(x) == FP_NORMAL; }
//int signbit(real-floating x);
///
extern(C) pragma(mangle, "_fdsign") pure int signbit(float x);
///
extern(C) pragma(mangle, "_dsign") pure int signbit(double x);
///
pure int signbit()(real x)
{
static if (real.sizeof == double.sizeof)
return signbit(cast(double) x);
else
return (cast(short*)&(x))[4] & 0x8000;
}
}
}
}
else version (CRuntime_Glibc)
{
enum
{
///
FP_NAN,
///
FP_INFINITE,
///
FP_ZERO,
///
FP_SUBNORMAL,
///
FP_NORMAL,
}
enum
{
///
FP_FAST_FMA = 0,
///
FP_FAST_FMAF = 0,
///
FP_FAST_FMAL = 0,
}
pure int __fpclassifyf(float x);
pure int __fpclassify(double x);
pure int __fpclassifyl(real x);
pure int __finitef(float x);
pure int __finite(double x);
pure int __finitel(real x);
pure int __isinff(float x);
pure int __isinf(double x);
pure int __isinfl(real x);
pure int __isnanf(float x);
pure int __isnan(double x);
pure int __isnanl(real x);
pure int __signbitf(float x);
pure int __signbit(double x);
pure int __signbitl(real x);
//int fpclassify(real-floating x);
///
pragma(mangle, "__fpclassifyf") pure int fpclassify(float x);
///
pragma(mangle, "__fpclassify") pure int fpclassify(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl")
pure int fpclassify(real x);
//int isfinite(real-floating x);
///
pragma(mangle, "__finitef") pure int isfinite(float x);
///
pragma(mangle, "__finite") pure int isfinite(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__finite" : "__finitel")
pure int isfinite(real x);
//int isinf(real-floating x);
///
pragma(mangle, "__isinff") pure int isinf(float x);
///
pragma(mangle, "__isinf") pure int isinf(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__isinf" : "__isinfl")
pure int isinf(real x);
//int isnan(real-floating x);
///
pragma(mangle, "__isnanf") pure int isnan(float x);
///
pragma(mangle, "__isnan") pure int isnan(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__isnan" : "__isnanl")
pure int isnan(real x);
//int isnormal(real-floating x);
///
extern (D) pure int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
///
extern (D) pure int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
///
extern (D) pure int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
//int signbit(real-floating x);
///
pragma(mangle, "__signbitf") pure int signbit(float x);
///
pragma(mangle, "__signbit") pure int signbit(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl")
pure int signbit(real x);
}
else version (CRuntime_Musl)
{
enum
{
///
FP_NAN,
///
FP_INFINITE,
///
FP_ZERO,
///
FP_SUBNORMAL,
///
FP_NORMAL,
}
enum
{
///
FP_FAST_FMA = 0,
///
FP_FAST_FMAF = 0,
///
FP_FAST_FMAL = 0,
}
pure {
int __fpclassifyf(float x);
int __fpclassify(double x);
int __fpclassifyl(real x);
int __signbitf(float x);
int __signbit(double x);
int __signbitl(real x);
}
//int fpclassify(real-floating x);
///
pragma(mangle, "__fpclassifyf") pure int fpclassify(float x);
///
pragma(mangle, "__fpclassify") pure int fpclassify(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl")
pure int fpclassify(real x);
extern (D) pure
{
private uint __FLOAT_BITS(float __f)
{
union __u_t {
float __f;
uint __i;
}
__u_t __u;
__u.__f = __f;
return __u.__i;
}
private ulong __DOUBLE_BITS(double __f)
{
union __u_t {
double __f;
ulong __i;
}
__u_t __u;
__u.__f = __f;
return __u.__i;
}
//int isfinite(real-floating x);
///
int isfinite(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000; }
///
int isfinite(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) < 0x7ffUL<<52; }
///
int isfinite(real x)
{
return (real.sizeof == double.sizeof)
? isfinite(cast(double)x)
: __fpclassifyl(x) > FP_INFINITE;
}
//int isinf(real-floating x);
///
int isinf(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000; }
///
int isinf(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) == 0x7ffUL<<52; }
///
int isinf(real x)
{
return (real.sizeof == double.sizeof)
? isinf(cast(double)x)
: __fpclassifyl(x) == FP_INFINITE;
}
//int isnan(real-floating x);
///
int isnan(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000; }
///
int isnan(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) > 0x7ffUL<<52; }
///
int isnan(real x)
{
return (real.sizeof == double.sizeof)
? isnan(cast(double)x)
: __fpclassifyl(x) == FP_NAN;
}
//int isnormal(real-floating x);
///
int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
}
//int signbit(real-floating x);
///
pragma(mangle, "__signbitf") pure int signbit(float x);
///
pragma(mangle, "__signbit") pure int signbit(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl")
pure int signbit(real x);
}
else version (CRuntime_UClibc)
{
enum
{
///
FP_NAN,
///
FP_INFINITE,
///
FP_ZERO,
///
FP_SUBNORMAL,
///
FP_NORMAL,
}
enum
{
///
FP_FAST_FMA = 0,
///
FP_FAST_FMAF = 0,
///
FP_FAST_FMAL = 0,
}
pure int __fpclassifyf(float x);
pure int __fpclassify(double x);
pure int __fpclassifyl(real x);
pure int __finitef(float x);
pure int __finite(double x);
pure int __finitel(real x);
pure int __isinff(float x);
pure int __isinf(double x);
pure int __isinfl(real x);
pure int __isnanf(float x);
pure int __isnan(double x);
pure int __isnanl(real x);
pure int __signbitf(float x);
pure int __signbit(double x);
pure int __signbitl(real x);
///
pragma(mangle, "__fpclassifyf") pure int fpclassify(float x);
///
pragma(mangle, "__fpclassify") pure int fpclassify(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl")
pure int fpclassify(real x);
///
pragma(mangle, "__finitef") pure int isfinite(float x);
///
pragma(mangle, "__finite") pure int isfinite(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__finite" : "__finitel")
pure int isfinite(real x);
///
pragma(mangle, "__isinff") pure int isinf(float x);
///
pragma(mangle, "__isinf") pure int isinf(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__isinf" : "__isinfl")
pure int isinf(real x);
///
pragma(mangle, "__isnanf") pure int isnan(float x);
///
pragma(mangle, "__isnan") pure int isnan(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__isnan" : "__isnanl")
pure int isnan(real x);
extern (D) pure
{
///
int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
///
int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
}
///
pragma(mangle, "__signbitf") pure int signbit(float x);
///
pragma(mangle, "__signbit") pure int signbit(double x);
///
pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl")
pure int signbit(real x);
}
else version (Darwin)
{
enum
{
///
FP_NAN = 1,
///
FP_INFINITE = 2,
///
FP_ZERO = 3,
///
FP_NORMAL = 4,
///
FP_SUBNORMAL = 5,
}
enum
{
///
FP_FAST_FMA = 0,
///
FP_FAST_FMAF = 0,
///
FP_FAST_FMAL = 0,
}
pure int __fpclassifyf(float x);
pure int __fpclassifyd(double x);
pure int __isfinitef(float x);
pure int __isfinited(double x);
pure int __isinff(float x);
pure int __isinfd(double x);
pure int __isnanf(float x);
pure int __isnand(double x);
// __isnormal family exists, but iOS implementation returns wrong results
// for subnormals
pure int __signbitf(float x);
pure int __signbitd(double x);
pure int __signbitl(real x);
// Support of OSX < 10.8 needs legacy function names without "l" suffix
// with exception of __signbitl. Otherwise could use else version like
// other Darwins
version (OSX)
{
version (AArch64)
{
// Available in macOS ARM
pure int __fpclassifyl(real x);
pure int __isfinitel(real x);
pure int __isinfl(real x);
pure int __isnanl(real x);
}
else
{
pure int __fpclassify(real x);
pure int __isfinite(real x);
pure int __isinf(real x);
pure int __isnan(real x);
alias __fpclassifyl = __fpclassify;
alias __isfinitel = __isfinite;
alias __isinfl = __isinf;
alias __isnanl = __isnan;
}
}
else
{
// Available OSX >= 10.8, iOS >= 6.0, all TVOS and WatchOS
pure int __fpclassifyl(real x);
pure int __isfinitel(real x);
pure int __isinfl(real x);
pure int __isnanl(real x);
}