diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-17 15:00:17 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-17 15:00:17 -0500 |
| commit | de18ece29436290cae3608d2c942e7e0a69f1a44 (patch) | |
| tree | d4355be5590c62d5e66d36f16ba8b53c65f9d1dd /std | |
| parent | 6cf38369d216ef676a21fc014a869042a924029d (diff) | |
| parent | fcf65f06c4eb42c8ecffbe9b7558f9cb84ef44e2 (diff) | |
| download | zig-de18ece29436290cae3608d2c942e7e0a69f1a44.tar.gz zig-de18ece29436290cae3608d2c942e7e0a69f1a44.zip | |
Merge pull request #1975 from BenoitJGirard/master
Fix std.math.powi so powi(x, +-0) = 1 for any x.
Diffstat (limited to 'std')
| -rw-r--r-- | std/math/powi.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/std/math/powi.zig b/std/math/powi.zig index 9c2a4a4965..dffb564da7 100644 --- a/std/math/powi.zig +++ b/std/math/powi.zig @@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{ // powi(x, +-0) = 1 for any x if (y == 0 or y == -0) { - return 0; + return 1; } switch (x) { @@ -174,4 +174,11 @@ test "math.powi.special" { testing.expectError(error.Overflow, powi(u64, 2, 64)); testing.expectError(error.Overflow, powi(u17, 2, 17)); testing.expectError(error.Overflow, powi(u42, 2, 42)); + + testing.expect((try powi(u8, 6, 0)) == 1); + testing.expect((try powi(u16, 5, 0)) == 1); + testing.expect((try powi(u32, 12, 0)) == 1); + testing.expect((try powi(u64, 34, 0)) == 1); + testing.expect((try powi(u17, 16, 0)) == 1); + testing.expect((try powi(u42, 34, 0)) == 1); } |
