@@ -480,9 +480,21 @@ extension ${Self}: BinaryFloatingPoint {
480
480
/// // y > x
481
481
@_inlineable // FIXME(sil-serialize-all)
482
482
public static var infinity : ${ Self} {
483
+ % if bits == 32 :
484
+ return ${ Self} ( bitPattern: 0b0_11111111_00000000000000000000000 )
485
+ % elif bits == 64 :
486
+ return ${ Self} (
487
+ bitPattern: 0b0_11111111111_0000000000000000000000000000000000000000000000000000 )
488
+ % elif bits == 80 :
489
+ let rep = _Float80Representation (
490
+ explicitSignificand: ${ Self} . _explicitBitMask,
491
+ signAndExponent: 0b0_111111111111111 )
492
+ return unsafeBitCast( rep, to: ${ Self} . self)
493
+ % else:
483
494
return ${ Self} ( sign: . plus,
484
495
exponentBitPattern: _infinityExponent,
485
496
significandBitPattern: 0 )
497
+ % end
486
498
}
487
499
488
500
/// A quiet NaN ("not a number").
@@ -507,7 +519,19 @@ extension ${Self}: BinaryFloatingPoint {
507
519
/// // Prints "true"
508
520
@_inlineable // FIXME(sil-serialize-all)
509
521
public static var nan : ${ Self} {
522
+ % if bits == 32 :
523
+ return ${ Self} ( bitPattern: 0b0_11111111_10000000000000000000000 )
524
+ % elif bits == 64 :
525
+ return ${ Self} (
526
+ bitPattern: 0b0_11111111111_1000000000000000000000000000000000000000000000000000 )
527
+ % elif bits == 80 :
528
+ let rep = _Float80Representation (
529
+ explicitSignificand: ${ Self} . _explicitBitMask | ${ Self} . _quietNaNMask,
530
+ signAndExponent: 0b0_111111111111111 )
531
+ return unsafeBitCast( rep, to: ${ Self} . self)
532
+ % else:
510
533
return ${ Self} ( nan: 0 , signaling: false )
534
+ % end
511
535
}
512
536
513
537
/// A signaling NaN ("not a number").
@@ -531,7 +555,7 @@ extension ${Self}: BinaryFloatingPoint {
531
555
}
532
556
533
557
@available ( * , unavailable, renamed: " nan " )
534
- public static var quietNaN : ${ Self} { Builtin. unreachable( ) }
558
+ public static var quietNaN : ${ Self} { Builtin. unreachable( ) }
535
559
536
560
/// The greatest finite number representable by this type.
537
561
///
@@ -543,9 +567,17 @@ extension ${Self}: BinaryFloatingPoint {
543
567
/// `infinity` is greater than this value.
544
568
@_inlineable // FIXME(sil-serialize-all)
545
569
public static var greatestFiniteMagnitude : ${ Self} {
570
+ % if bits == 32 :
571
+ return 0x1 . fffffep127
572
+ % elif bits == 64 :
573
+ return 0x1 . fffffffffffffp1023
574
+ % elif bits == 80 :
575
+ return 0x1 . fffffffffffffffep16383
576
+ % else:
546
577
return ${ Self} ( sign: . plus,
547
578
exponentBitPattern: _infinityExponent - 1 ,
548
579
significandBitPattern: _significandMask)
580
+ % end
549
581
}
550
582
551
583
/// The mathematical constant pi.
@@ -627,9 +659,17 @@ extension ${Self}: BinaryFloatingPoint {
627
659
/// subnormals, zeros, and negative numbers are smaller than this value.
628
660
@_inlineable // FIXME(sil-serialize-all)
629
661
public static var leastNormalMagnitude : ${ Self} {
662
+ % if bits == 32 :
663
+ return 0x1 p- 126
664
+ % elif bits == 64 :
665
+ return 0x1 p- 1022
666
+ % elif bits == 80 :
667
+ return 0x1 p- 16382
668
+ % else:
630
669
return ${ Self} ( sign: . plus,
631
670
exponentBitPattern: 1 ,
632
671
significandBitPattern: 0 )
672
+ % end
633
673
}
634
674
635
675
/// The least positive number.
@@ -643,12 +683,36 @@ extension ${Self}: BinaryFloatingPoint {
643
683
#if arch(arm)
644
684
return leastNormalMagnitude
645
685
#else
686
+ % if bits == 32 :
687
+ return 0x1 p- 149
688
+ % elif bits == 64 :
689
+ return 0x1 p- 1074
690
+ % elif bits == 80 :
691
+ return 0x1 p- 16445
692
+ % else:
646
693
return ${ Self} ( sign: . plus,
647
694
exponentBitPattern: 0 ,
648
695
significandBitPattern: 1 )
696
+ % end
649
697
#endif
650
698
}
651
699
700
+ /// The unit in the last place of 1.0.
701
+ ///
702
+ /// The positive difference between 1.0 and the next greater representable
703
+ /// number. The `ulpOfOne` constant corresponds to the C macros
704
+ /// `FLT_EPSILON`, `DBL_EPSILON`, and others with a similar purpose.
705
+ @_inlineable // FIXME(sil-serialize-all)
706
+ public static var ulpOfOne : ${ Self} {
707
+ % if bits == 32 :
708
+ return 0x1 p- 23
709
+ % elif bits == 64 :
710
+ return 0x1 p- 52
711
+ % elif bits == 80 :
712
+ return 0x1 p- 63
713
+ % end
714
+ }
715
+
652
716
/// The exponent of the floating-point value.
653
717
///
654
718
/// The *exponent* of a floating-point value is the integer part of the
0 commit comments