Add f128 support for fabs, isinf, isnan, inf and nan functions
This commit is contained in:
@@ -14,6 +14,7 @@ pub fn fabs(x: var) @typeOf(x) {
|
||||
f16 => fabs16(x),
|
||||
f32 => fabs32(x),
|
||||
f64 => fabs64(x),
|
||||
f128 => fabs128(x),
|
||||
else => @compileError("fabs not implemented for " ++ @typeName(T)),
|
||||
};
|
||||
}
|
||||
@@ -36,10 +37,17 @@ fn fabs64(x: f64) f64 {
|
||||
return @bitCast(f64, u);
|
||||
}
|
||||
|
||||
fn fabs128(x: f128) f128 {
|
||||
var u = @bitCast(u128, x);
|
||||
u &= maxInt(u128) >> 1;
|
||||
return @bitCast(f128, u);
|
||||
}
|
||||
|
||||
test "math.fabs" {
|
||||
expect(fabs(f16(1.0)) == fabs16(1.0));
|
||||
expect(fabs(f32(1.0)) == fabs32(1.0));
|
||||
expect(fabs(f64(1.0)) == fabs64(1.0));
|
||||
expect(fabs(f128(1.0)) == fabs128(1.0));
|
||||
}
|
||||
|
||||
test "math.fabs16" {
|
||||
@@ -57,6 +65,11 @@ test "math.fabs64" {
|
||||
expect(fabs64(-1.0) == 1.0);
|
||||
}
|
||||
|
||||
test "math.fabs128" {
|
||||
expect(fabs128(1.0) == 1.0);
|
||||
expect(fabs128(-1.0) == 1.0);
|
||||
}
|
||||
|
||||
test "math.fabs16.special" {
|
||||
expect(math.isPositiveInf(fabs(math.inf(f16))));
|
||||
expect(math.isPositiveInf(fabs(-math.inf(f16))));
|
||||
@@ -74,3 +87,9 @@ test "math.fabs64.special" {
|
||||
expect(math.isPositiveInf(fabs(-math.inf(f64))));
|
||||
expect(math.isNan(fabs(math.nan(f64))));
|
||||
}
|
||||
|
||||
test "math.fabs128.special" {
|
||||
expect(math.isPositiveInf(fabs(math.inf(f128))));
|
||||
expect(math.isPositiveInf(fabs(-math.inf(f128))));
|
||||
expect(math.isNan(fabs(math.nan(f128))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user