File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -18,3 +18,40 @@ public func fold_inf_inf_cmp() -> Bool {
18
18
0x1 . 0 p128 < Float . infinity
19
19
}
20
20
21
+ public struct FP32 : FixedPoint {
22
+ public var bits : Int32
23
+
24
+ public init ( bits: Bits ) {
25
+ self . bits = bits
26
+ }
27
+ }
28
+
29
+ // CHECK-LABEL: sil @$s4test0A19FloatLiteralFoldingAA4FP32VyF :
30
+ // CHECK: [[L:%.*]] = integer_literal $Builtin.Int32, 65536
31
+ // CHECK: [[I:%.*]] = struct $Int32 ([[L]])
32
+ // CHECK: [[F:%.*]] = struct $FP32 ([[I]])
33
+ // CHECK: return [[F]]
34
+ // CHECK: } // end sil function '$s4test0A19FloatLiteralFoldingAA4FP32VyF'
35
+ public func testFloatLiteralFolding( ) -> FP32 {
36
+ return 1.0
37
+ }
38
+
39
+ public protocol FixedPoint : ExpressibleByFloatLiteral {
40
+ associatedtype Bits : FixedWidthInteger
41
+ var bits : Bits { get set }
42
+
43
+ init ( bits: Bits )
44
+ }
45
+
46
+ extension FixedPoint {
47
+ public init ( floatLiteral value: Double ) {
48
+ self . init ( value)
49
+ }
50
+
51
+ init < F: BinaryFloatingPoint > ( _ value: F ) {
52
+ let s = F ( sign: . plus, exponent: F . Exponent ( 16 ) , significand: 1 )
53
+ let r = ( s * value) . rounded ( . toNearestOrEven)
54
+ self . init ( bits: Bits ( exactly: r) !)
55
+ }
56
+ }
57
+
You can’t perform that action at this time.
0 commit comments