std: Implement isFinite for f128

This commit is contained in:
LemonBoy 2021-04-29 09:05:33 +02:00
parent 236dba8ba9
commit 06b2fee05e

View File

@ -24,6 +24,10 @@ pub fn isFinite(x: anytype) bool {
const bits = @bitCast(u64, x);
return bits & (maxInt(u64) >> 1) < (0x7FF << 52);
},
f128 => {
const bits = @bitCast(u128, x);
return bits & (maxInt(u128) >> 1) < (0x7FFF << 112);
},
else => {
@compileError("isFinite not implemented for " ++ @typeName(T));
},
@ -37,10 +41,24 @@ test "math.isFinite" {
expect(isFinite(@as(f32, -0.0)));
expect(isFinite(@as(f64, 0.0)));
expect(isFinite(@as(f64, -0.0)));
expect(isFinite(@as(f128, 0.0)));
expect(isFinite(@as(f128, -0.0)));
expect(!isFinite(math.inf(f16)));
expect(!isFinite(-math.inf(f16)));
expect(!isFinite(math.inf(f32)));
expect(!isFinite(-math.inf(f32)));
expect(!isFinite(math.inf(f64)));
expect(!isFinite(-math.inf(f64)));
expect(!isFinite(math.inf(f128)));
expect(!isFinite(-math.inf(f128)));
expect(!isFinite(math.nan(f16)));
expect(!isFinite(-math.nan(f16)));
expect(!isFinite(math.nan(f32)));
expect(!isFinite(-math.nan(f32)));
expect(!isFinite(math.nan(f64)));
expect(!isFinite(-math.nan(f64)));
expect(!isFinite(math.nan(f128)));
expect(!isFinite(-math.nan(f128)));
}