From 30cfc0ab2c56ad73dca9b9935731d10010c93b32 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 30 Jun 2018 01:44:54 +0200 Subject: [PATCH] test std.math f16 sqrt support refs #1122 --- std/math/sqrt.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/std/math/sqrt.zig b/std/math/sqrt.zig index 599008acff..e12ecf9683 100644 --- a/std/math/sqrt.zig +++ b/std/math/sqrt.zig @@ -31,10 +31,25 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ } test "math.sqrt" { + assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); } +test "math.sqrt16" { + const epsilon = 0.000001; + + assert(@sqrt(f16, 0.0) == 0.0); + assert(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon)); + assert(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon)); + assert(@sqrt(f16, 4.0) == 2.0); + assert(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon)); + assert(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon)); + assert(@sqrt(f16, 64.0) == 8.0); + assert(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon)); + assert(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon)); +} + test "math.sqrt32" { const epsilon = 0.000001; @@ -63,6 +78,14 @@ test "math.sqrt64" { assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon)); } +test "math.sqrt16.special" { + assert(math.isPositiveInf(@sqrt(f16, math.inf(f16)))); + assert(@sqrt(f16, 0.0) == 0.0); + assert(@sqrt(f16, -0.0) == -0.0); + assert(math.isNan(@sqrt(f16, -1.0))); + assert(math.isNan(@sqrt(f16, math.nan(f16)))); +} + test "math.sqrt32.special" { assert(math.isPositiveInf(@sqrt(f32, math.inf(f32)))); assert(@sqrt(f32, 0.0) == 0.0);