authorgravatar for info@bnoordhuis.nlBen Noordhuis <info@bnoordhuis.nl> 2018-06-30 01:44:54+02:00
committergravatar for info@bnoordhuis.nlBen Noordhuis <info@bnoordhuis.nl> 2018-06-30 01:58:17+02:00
log30cfc0ab2c56ad73dca9b9935731d10010c93b32
tree4b1bbf13c8d521270a1dc64fadcf1700193c8136
parentbe361790645971446b64dabf21c27a595a40c8fd

test std.math f16 sqrt support

refs #1122

1 files changed, 23 insertions(+), 0 deletions(-)

std/math/sqrt.zig+23
...@@ -31,10 +31,25 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ...@@ -31,10 +31,25 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
31}31}
3232
33test "math.sqrt" {33test "math.sqrt" {
34 assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
34 assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0));35 assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
35 assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0));36 assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
36}37}
3738
39test "math.sqrt16" {
40 const epsilon = 0.000001;
41
42 assert(@sqrt(f16, 0.0) == 0.0);
43 assert(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon));
44 assert(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon));
45 assert(@sqrt(f16, 4.0) == 2.0);
46 assert(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon));
47 assert(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon));
48 assert(@sqrt(f16, 64.0) == 8.0);
49 assert(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon));
50 assert(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon));
51}
52
38test "math.sqrt32" {53test "math.sqrt32" {
39 const epsilon = 0.000001;54 const epsilon = 0.000001;
4055
...@@ -63,6 +78,14 @@ test "math.sqrt64" {...@@ -63,6 +78,14 @@ test "math.sqrt64" {
63 assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));78 assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));
64}79}
6580
81test "math.sqrt16.special" {
82 assert(math.isPositiveInf(@sqrt(f16, math.inf(f16))));
83 assert(@sqrt(f16, 0.0) == 0.0);
84 assert(@sqrt(f16, -0.0) == -0.0);
85 assert(math.isNan(@sqrt(f16, -1.0)));
86 assert(math.isNan(@sqrt(f16, math.nan(f16))));
87}
88
66test "math.sqrt32.special" {89test "math.sqrt32.special" {
67 assert(math.isPositiveInf(@sqrt(f32, math.inf(f32))));90 assert(math.isPositiveInf(@sqrt(f32, math.inf(f32))));
68 assert(@sqrt(f32, 0.0) == 0.0);91 assert(@sqrt(f32, 0.0) == 0.0);