authorgravatar for dev@jhert.comJeremy Hertel <dev@jhert.com> 2024-08-29 22:26:07-05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-09-02 00:10:22+03:00
log227fb4875f5084cdb3436c40c4a08809bd3e4f50
treee323903b66e7ac5c98935ae811d1467aecea69b9
parent28383d4d985cd04c897f6b6a63bd2107d8e2a8e9

std.math: rename make_f80 to F80.toFloat and break_f80 to F80.fromFloat


8 files changed, 22 insertions(+), 22 deletions(-)

lib/compiler_rt/comparef.zig+2-2
...@@ -61,8 +61,8 @@ pub inline fn cmpf2(comptime T: type, comptime RT: type, a: T, b: T) RT {...@@ -61,8 +61,8 @@ pub inline fn cmpf2(comptime T: type, comptime RT: type, a: T, b: T) RT {
61}61}
6262
63pub inline fn cmp_f80(comptime RT: type, a: f80, b: f80) RT {63pub inline fn cmp_f80(comptime RT: type, a: f80, b: f80) RT {
64 const a_rep = std.math.break_f80(a);64 const a_rep = std.math.F80.fromFloat(a);
65 const b_rep = std.math.break_f80(b);65 const b_rep = std.math.F80.fromFloat(b);
66 const sig_bits = std.math.floatMantissaBits(f80);66 const sig_bits = std.math.floatMantissaBits(f80);
67 const int_bit = 0x8000000000000000;67 const int_bit = 0x8000000000000000;
68 const sign_bit = 0x8000;68 const sign_bit = 0x8000;
lib/compiler_rt/extendf.zig+1-1
...@@ -131,7 +131,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI...@@ -131,7 +131,7 @@ pub inline fn extend_f80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeI
131 }131 }
132132
133 dst.exp |= sign;133 dst.exp |= sign;
134 return std.math.make_f80(dst);134 return dst.toFloat();
135}135}
136136
137test {137test {
lib/compiler_rt/extendxftf2.zig+1-1
...@@ -18,7 +18,7 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {...@@ -18,7 +18,7 @@ fn __extendxftf2(a: f80) callconv(.C) f128 {
18 const dst_min_normal = @as(u128, 1) << dst_sig_bits;18 const dst_min_normal = @as(u128, 1) << dst_sig_bits;
1919
20 // Break a into a sign and representation of the absolute value20 // Break a into a sign and representation of the absolute value
21 var a_rep = std.math.break_f80(a);21 var a_rep = std.math.F80.fromFloat(a);
22 const sign = a_rep.exp & 0x8000;22 const sign = a_rep.exp & 0x8000;
23 a_rep.exp &= 0x7FFF;23 a_rep.exp &= 0x7FFF;
24 var abs_result: u128 = undefined;24 var abs_result: u128 = undefined;
lib/compiler_rt/subxf3.zig+2-2
...@@ -8,8 +8,8 @@ comptime {...@@ -8,8 +8,8 @@ comptime {
8}8}
99
10fn __subxf3(a: f80, b: f80) callconv(.C) f80 {10fn __subxf3(a: f80, b: f80) callconv(.C) f80 {
11 var b_rep = std.math.break_f80(b);11 var b_rep = std.math.F80.fromFloat(b);
12 b_rep.exp ^= 0x8000;12 b_rep.exp ^= 0x8000;
13 const neg_b = std.math.make_f80(b_rep);13 const neg_b = b_rep.toFloat();
14 return a + neg_b;14 return a + neg_b;
15}15}
lib/compiler_rt/truncf.zig+1-1
...@@ -121,7 +121,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -121,7 +121,7 @@ pub inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
121 const dst_nan_mask = dst_qnan - 1;121 const dst_nan_mask = dst_qnan - 1;
122122
123 // Break a into a sign and representation of the absolute value123 // Break a into a sign and representation of the absolute value
124 var a_rep = std.math.break_f80(a);124 var a_rep = std.math.F80.fromFloat(a);
125 const sign = a_rep.exp & 0x8000;125 const sign = a_rep.exp & 0x8000;
126 a_rep.exp &= 0x7FFF;126 a_rep.exp &= 0x7FFF;
127 a_rep.fraction &= 0x7FFFFFFFFFFFFFFF;127 a_rep.fraction &= 0x7FFFFFFFFFFFFFFF;
lib/compiler_rt/trunctfxf2.zig+1-1
...@@ -64,5 +64,5 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {...@@ -64,5 +64,5 @@ pub fn __trunctfxf2(a: f128) callconv(.C) f80 {
64 }64 }
6565
66 res.exp |= sign;66 res.exp |= sign;
67 return math.make_f80(res);67 return res.toFloat();
68}68}
lib/std/math.zig+12-12
...@@ -1720,20 +1720,20 @@ pub fn comptimeMod(num: anytype, comptime denom: comptime_int) IntFittingRange(0...@@ -1720,20 +1720,20 @@ pub fn comptimeMod(num: anytype, comptime denom: comptime_int) IntFittingRange(0
1720pub const F80 = struct {1720pub const F80 = struct {
1721 fraction: u64,1721 fraction: u64,
1722 exp: u16,1722 exp: u16,
1723};
17241723
1725pub fn make_f80(repr: F80) f80 {1724 pub fn toFloat(self: F80) f80 {
1726 const int = (@as(u80, repr.exp) << 64) | repr.fraction;1725 const int = (@as(u80, self.exp) << 64) | self.fraction;
1727 return @as(f80, @bitCast(int));1726 return @as(f80, @bitCast(int));
1728}1727 }
17291728
1730pub fn break_f80(x: f80) F80 {1729 pub fn fromFloat(x: f80) F80 {
1731 const int = @as(u80, @bitCast(x));1730 const int = @as(u80, @bitCast(x));
1732 return .{1731 return .{
1733 .fraction = @as(u64, @truncate(int)),1732 .fraction = @as(u64, @truncate(int)),
1734 .exp = @as(u16, @truncate(int >> 64)),1733 .exp = @as(u16, @truncate(int >> 64)),
1735 };1734 };
1736}1735 }
1736};
17371737
1738/// Returns -1, 0, or 1.1738/// Returns -1, 0, or 1.
1739/// Supports integer and float types and vectors of integer and float types.1739/// Supports integer and float types and vectors of integer and float types.
lib/std/math/nextafter.zig+2-2
...@@ -61,7 +61,7 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {...@@ -61,7 +61,7 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {
61 const integer_bit_mask = 1 << math.floatFractionalBits(f80);61 const integer_bit_mask = 1 << math.floatFractionalBits(f80);
62 const exponent_bits_mask = (1 << math.floatExponentBits(f80)) - 1;62 const exponent_bits_mask = (1 << math.floatExponentBits(f80)) - 1;
6363
64 var x_parts = math.break_f80(x);64 var x_parts = math.F80.fromFloat(x);
6565
66 // Bitwise increment/decrement the fractional part while also taking care to update the66 // Bitwise increment/decrement the fractional part while also taking care to update the
67 // exponent if we overflow the fractional part. This might flip the integer bit; this is67 // exponent if we overflow the fractional part. This might flip the integer bit; this is
...@@ -88,7 +88,7 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {...@@ -88,7 +88,7 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {
88 // set to cleared (if the old value was normal) or remained cleared (if the old value was88 // set to cleared (if the old value was normal) or remained cleared (if the old value was
89 // subnormal), both of which are the outcomes we want.89 // subnormal), both of which are the outcomes we want.
9090
91 return math.make_f80(x_parts);91 return x_parts.toFloat();
92 } else {92 } else {
93 const Bits = std.meta.Int(.unsigned, @bitSizeOf(T));93 const Bits = std.meta.Int(.unsigned, @bitSizeOf(T));
94 var x_bits: Bits = @bitCast(x);94 var x_bits: Bits = @bitCast(x);