| ... | ... | @@ -31,10 +31,25 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | test "math.sqrt" { |
| 34 | assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0)); |
| 34 | 35 | assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0)); |
| 35 | 36 | assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0)); |
| 36 | 37 | } |
| 37 | 38 | |
| 39 | test "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 | |
| 38 | 53 | test "math.sqrt32" { |
| 39 | 54 | const epsilon = 0.000001; |
| 40 | 55 | |
| ... | ... | @@ -63,6 +78,14 @@ test "math.sqrt64" { |
| 63 | 78 | assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon)); |
| 64 | 79 | } |
| 65 | 80 | |
| 81 | test "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 | |
| 66 | 89 | test "math.sqrt32.special" { |
| 67 | 90 | assert(math.isPositiveInf(@sqrt(f32, math.inf(f32)))); |
| 68 | 91 | assert(@sqrt(f32, 0.0) == 0.0); |