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
//! A pure-Rust floating point math library with support for native floating
//! point and soft-floats.
//!
//! This crate is `no_std`.
//!
//! The following math functions are implemented:
//!
//! * Sign operations ([`abs`], [`copysign`]).
//! * Rounding ([`round`], [`trunc`], [`ceil`], [`floor`]).
//! * Exponential ([`exp`], [`exp_m1`], [`exp2`], [`exp10`]).
//! * Logarithmic ([`log`], [`log_1p`], [`log2`], [`log10`]).
//! * Power ([`pow`], [`powi`]).
//! * Trigonometric
//! - Radians ([`sin`], [`cos`], [`sin_cos`], [`tan`]).
//! - Degrees ([`sind`], [`cosd`], [`sind_cosd`], [`tand`]).
//! - Half-revolutions ([`sinpi`], [`cospi`], [`sinpi_cospi`], [`tanpi`]).
//! * Inverse trigonometric
//! - Radians ([`asin`], [`acos`], [`atan`], [`atan2`]).
//! - Degrees ([`asind`], [`acosd`], [`atand`], [`atan2d`]).
//! - Half-revolutions ([`asinpi`], [`acospi`], [`atanpi`], [`atan2pi`]).
//! * Hyperbolic ([`sinh`], [`cosh`], [`sinh_cosh`], [`tanh`]).
//! * Inverse hyperbolic ([`asinh`], [`acosh`], [`atanh`]).
//! * Gamma ([`tgamma`], [`lgamma`]).
//!
//! All functions are implemted for the native floating point types [`prim@f32`]
//! and [`prim@f64`].
//!
//! The soft-float types [`SoftF32`] and [`SoftF64`] are also provided. They
//! also support all the above functions and provide consistent bit-to-bit
//! behavior across platforms. They are available when the `soft-float` feature
//! is enabled (disabled by default).
//!
//! The [`FloatMath`] trait is used to identify types that support the math
//! functions.
// TODO:
// * Error function and complementary (erf, erfc)
// * Bessel functions (j0, y0, j1, y1, jn, yn)
// Uncomment to use `dbg!`
//extern crate std;
pub use SoftF32;
pub use SoftF64;
/// Floating point types with math functions.
/// Calculates the absolute value of `x`
/// Returns a value with the magnitude of `x` and the sign of `y`
/// Rounds `x` to the nearest integer, ties round away from zero
/// Rounds `x` to the nearest integer that is not greater in magnitude than `x`
/// Rounds `x` to the nearest integer that is not less than `x`
/// Rounds `x` to the nearest integer that is not greater than `x`
/// Calculates `x` times two raised to `y`.
/// Splits `x` into mantissa and exponent.
///
/// Returns `(m, e)` such as:
/// * `0.5 <= m < 1.0`
/// * `x = m * 2^e`
///
/// When `x` is zero, infinity or NaN, returns `x` as mantissa and zero as
/// exponent.
/// Calculates the Pythagorean addition of `x` and `y` with and error of less
/// than 1 ULP
///
/// The Pythagorean addition of `x` and `y` is equal to the length of the
/// hypotenuse of a triangle with sides of length `x` and `y`.
///
/// Special cases:
/// * Returns positive infinity if `x` or `y` is infinity
/// * Returns NaN if `x` or `y` is NaN and neither is infinity
/// Calculates the square root of `x` with an error of less than 0.5 ULP.
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns NaN if `x` is NaN or negative non-zero (including infinity)
/// Calculates the cube root of `x` with and error of less than 1 ULP.
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns negative infinity if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates Euler's number raised to `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns positive infinity if `x` is positive infinity
/// * Returns zero if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates `exp(x) - 1.0` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns minus one if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates 2 raised to `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns positive infinity if `x` is positive infinity
/// * Returns zero if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates 10 raised to `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns positive infinity if `x` is positive infinity
/// * Returns zero if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates the natural logarithm of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative infinity if `x` is positive or negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns NaN if `x` is NaN or negative non-zero (including infinity)
/// Calculates the natural logarithm of `x + 1` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns negative infinity if `x` is minus one
/// * Returns positive infinity if `x` is positive infinity
/// * Returns NaN if `x` is NaN or less than minus one (including negative
/// infinity)
/// Calculates the base-2 logarithm of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative infinity if `x` is positive or negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns NaN if `x` is NaN or negative non-zero (including infinity)
/// Calculates the base-10 logarithm of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative infinity if `x` is positive or negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns NaN if `x` is NaN or negative non-zero (including infinity)
/// Calculates `x` raised to `y` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns 1 when `x` is 1 or `y` is zero
/// * Returns 1 when `x` is -1 and `y` is positive or negative infinity
/// * Returns NaN when `x` is NaN and `y` is not zero
/// * Returns NaN when `y` is NaN and `z` is not 1
/// * Returns positive zero when `x` is positive zero and `y` is positive
/// * Returns positive zero when `x` is positive infinity and `y` is negative
/// * Returns positive infinity when `x` is positive infinity and `y` is
/// positive
/// * Returns positive infinity when `x` is positive zero and `y` is negative
/// * Returns positive zero when `x` is negative zero and `y` is positive and
/// not an odd integer
/// * Returns positive zero when `x` is negative infinity and `y` is negative
/// and not an odd integer
/// * Returns positive infinity when `x` is negative infinity and `y` is
/// positive and not an odd integer
/// * Returns positive infinity when `x` is negative zero and `y` is negative
/// and not an odd integer
/// * Returns negative zero when `x` is negative zero and `y` is positive and an
/// odd integer
/// * Returns negative zero when `x` is negative infinity and `y` is negative
/// and an odd integer
/// * Returns negative infinity when `x` is negative infinity and `y` is
/// positive and an odd integer
/// * Returns negative infinity when `x` is negative zero and `y` is negative
/// and an odd integer
/// * Returns positive zero when the absolute value of `x` is less than one and
/// `y` is positive infinity
/// * Returns positive zero when the absolute value of `x` is greater than one
/// and `y` is negative infinity
/// * Returns positive infinity when the absolute value of `x` is less than one
/// and `y` is negative infinity
/// * Returns positive infinity when the absolute value of `x` is greater than
/// one and `y` is positive infinity
/// * Returns NaN when `x` is negative and `y` is finite and not integer
/// Calculates `x` raised to `y` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns 1 when `x` is 1 or `y` is zero
/// * Returns NaN when `x` is NaN and `y` is not zero
/// * Returns NaN when `y` is NaN and `z` is not 1
/// * Returns positive zero when `x` is positive zero and `y` is positive
/// * Returns positive zero when `x` is positive infinity and `y` is negative
/// * Returns positive infinity when `x` is positive infinity and `y` is
/// positive
/// * Returns positive infinity when `x` is positive zero and `y` is negative
/// * Returns positive zero when `x` is negative zero and `y` is positive and
/// even
/// * Returns positive zero when `x` is negative infinity and `y` is negative
/// and even
/// * Returns positive infinity when `x` is negative infinity and `y` is
/// positive and even
/// * Returns positive infinity when `x` is negative zero and `y` is negative
/// and even
/// * Returns negative zero when `x` is negative zero and `y` is positive and
/// odd
/// * Returns negative zero when `x` is negative infinity and `y` is negative
/// and odd
/// * Returns negative infinity when `x` is negative infinity and `y` is
/// positive and odd
/// * Returns negative infinity when `x` is negative zero and `y` is negative
/// and odd
/// Calculates the sine of `x` radians with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the cosine of `x` radians with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the sine and the cosine of `x` radians
///
/// The same accuracy and special cases of [`sin`] and [`cos`] also
/// apply to this function. Using this function can be faster than
/// using [`sin`] and [`cos`] separately.
/// Calculates the tangent of `x` radians with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the sine of `x` degrees with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the cosine of `x` degrees with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the sine and the cosine of `x` degrees
///
/// The same accuracy and special cases of [`sind`] and [`cosd`] also apply to
/// this function. Using this function can be faster than using [`sind`] and
/// [`cosd`] separately.
/// Calculates the tangent of `x` degrees with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the sine of `x` half-revolutions with an error of less
/// than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the cosine of `x` half-revolutions with an error of
/// less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the sine and the cosine of `x` half-revolutions
///
/// The same accuracy and special cases of [`sinpi`] and [`cospi`] also apply to
/// this function. Using this function can be faster than using [`sinpi`] and
/// [`cospi`] separately.
/// Calculates the tangent of `x` half-revolutions with an error of less than 1
/// ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is infinity or NaN
/// Calculates the arcsine of `x`, returning the result in radians, with an
/// error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arccosine of `x`, returning the result in radians, with an
/// error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arctangent of `x`, returning the result in radians,
/// with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN
/// * Returns π/2 if `x` is positive infinity
/// * Returns -Ï€/2 if `x` is negative infinity
/// Calculates the 2-argument arctangent of `x` and 'y', returning the
/// result in radians with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or `y` is NaN
/// * Returns positive zero if `y` is positive zero `x` is positive (zero,
/// finite or infinity)
/// * Returns negative zero if `y` is negative zero `x` is positive (zero,
/// finite or infinity)
/// * Returns π if `y` is positive zero `x` is positive (zero, finite or
/// infinity)
/// * Returns -Ï€ if `y` is negative zero `x` is negative (zero, finite or
/// infinity)
/// * Returns π/2 if `y` is positive infinity and `x` is zero or finite
/// * Returns -Ï€/2 if `y` is negative infinity and `x` is zero or finite
/// * Returns positive zero if `x` is positive infinity and `y` is positive
/// (zero or finite)
/// * Returns negative zero if `x` is positive infinity and `y` is negative
/// (zero or finite)
/// * Returns π if `x` is negative infinity and `y` is positive (zero or finite)
/// * Returns -Ï€ if `x` is negative infinity and `y` is negative (zero or
/// finite)
/// * Returns π/4 if `x` is positive infinity and `y` is positive infinity
/// * Returns -Ï€/4 if `x` is positive infinity and `y` is negative infinity
/// * Returns 3Ï€/4 if `x` is negative infinity and `y` is positive infinity
/// * Returns -3Ï€/4 if `x` is negative infinity and `y` is negative infinity
/// Calculates the arcsine of `x`, returning the result in degrees, with an
/// error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arccosine of `x`, returning the result in degrees, with an
/// error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arctangent of `x`, returning the result in degrees, with an
/// error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN
/// * Returns 90 if `x` is positive infinity
/// * Returns -90 if `x` is negative infinity
/// Calculates the 2-argument arctangent of `x` and 'y', returning the result in
/// degrees, with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or `y` is NaN
/// * Returns positive zero if `y` is positive zero `x` is positive (zero,
/// finite or infinity)
/// * Returns negative zero if `y` is negative zero `x` is positive (zero,
/// finite or infinity)
/// * Returns 180 if `y` is positive zero `x` is positive (zero, finite or
/// infinity)
/// * Returns -180 if `y` is negative zero `x` is negative (zero, finite or
/// infinity)
/// * Returns 90 if `y` is positive infinity and `x` is zero or finite
/// * Returns -90 if `y` is negative infinity and `x` is zero or finite
/// * Returns positive zero if `x` is positive infinity and `y` is positive
/// (zero or finite)
/// * Returns negative zero if `x` is positive infinity and `y` is negative
/// (zero or finite)
/// * Returns 180 if `x` is negative infinity and `y` is positive (zero or
/// finite)
/// * Returns -180 if `x` is negative infinity and `y` is negative (zero or
/// finite)
/// * Returns 45 if `x` is positive infinity and `y` is positive infinity
/// * Returns -45 if `x` is positive infinity and `y` is negative infinity
/// * Returns 135 if `x` is negative infinity and `y` is positive infinity
/// * Returns -135 if `x` is negative infinity and `y` is negative infinity
/// Calculates the arcsine of `x`, returning the result in half-revolutions,
/// with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arccosine of `x`, returning the result in half-revolutions,
/// with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or greater than one in magnitude (including
/// infinity)
/// Calculates the arctangent of `x`, returning the result in half-revolutions,
/// with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns NaN if `x` is NaN
/// * Returns 0.5 if `x` is positive infinity
/// * Returns -0.5 if `x` is negative infinity
/// Calculates the 2-argument arctangent of `x` and 'y', returning the result in
/// half-revolutions, with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or `y` is NaN
/// * Returns positive zero if `y` is positive zero `x` is positive (zero,
/// finite or infinity)
/// * Returns negative zero if `y` is negative zero `x` is positive (zero,
/// finite or infinity)
/// * Returns 1 if `y` is positive zero `x` is positive (zero, finite or
/// infinity)
/// * Returns -1 if `y` is negative zero `x` is negative (zero, finite or
/// infinity)
/// * Returns 0.5 if `y` is positive infinity and `x` is zero or finite
/// * Returns -0.5 if `y` is negative infinity and `x` is zero or finite
/// * Returns positive zero if `x` is positive infinity and `y` is positive
/// (zero or finite)
/// * Returns negative zero if `x` is positive infinity and `y` is negative
/// (zero or finite)
/// * Returns 1 if `x` is negative infinity and `y` is positive (zero or finite)
/// * Returns -1 if `x` is negative infinity and `y` is negative (zero or
/// finite)
/// * Returns 0.25 if `x` is positive infinity and `y` is positive infinity
/// * Returns -0.25 if `x` is positive infinity and `y` is negative infinity
/// * Returns 0.75 if `x` is negative infinity and `y` is positive infinity
/// * Returns -0.75 if `x` is negative infinity and `y` is negative infinity
/// Calculates the hyperbolic sine of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns negative infinity if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates the hyperbolic cosine of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns positive infinity if `x` is positive or negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates the hyerbolic sine and hyerbolic cosine of `x`
///
/// The same accuracy and special cases of [`sinh`] and [`cosh`] also apply to
/// this function. Using this function can be faster than using [`sinh`] and
/// [`cosh`] separately.
/// Calculates the hyperbolic tangent of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns negative zero if `x` is negative zero
/// * Returns one if `x` is positive infinity
/// * Returns minus one if `x` is negative infinity
/// * Returns NaN if `x` is NaN
/// Calculates the hyperbolic arcsine of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is positive infinity
/// * Returns negative infinity if `x` is negative infinity
/// Calculates the hyperbolic arccosine of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or less than one (including negative infinity)
/// * Returns positive infinity if `x` is positive infinity
/// Calculates the hyperbolic arctangent of `x` with an error of less than 1 ULP
///
/// Special cases:
/// * Returns NaN if `x` is NaN or greater than 1 in magnitude
/// * Returns negative zero if `x` is negative zero
/// * Returns positive infinity if `x` is 1
/// * Returns negative infinity if `x` is -1
/// Calculates the gamma function of `x`
///
/// When `x` is greater than 0.5, the error is less than 1 ULP, otherwise the
/// error is less than 2 ULP.
///
/// Special cases:
/// * Returns NaN if `x` is NaN, negative infinity or a negative integer
/// * Returns positive infinity if `x` is positive infinity
/// * Returns positive infinity if `x` is positive zero
/// * Returns negative infinity if `x` is negative zero
/// Calculates the logarithm of the absolute value of the gamma function of `x`
///
/// The integer field of the returned tuple is `1` when the gamma function of
/// `x` is positive, `-1` when the gamma function of `x` is negative, and `0`
/// when the sign of the gamma function of `x` is not defined.
///
/// The error is less than 2 ULP in most cases. However, for some negative
/// values of `x`, the error can be in the order of 200 ULP.
///
/// Special cases:
/// * Returns NaN if `x` is NaN or negative infinity
/// * Returns positive infinity if `x` is positive infinity
/// * Returns positive infinity if `x` is zero or a negative integer
///
/// The sign is considered undefined when `x` is NaN, a negative integer or
/// negative infinity.