mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
std: Implement isFinite for f128
This commit is contained in:
parent
236dba8ba9
commit
06b2fee05e
@ -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)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user