authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-17 15:00:17-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-02-17 15:00:17-05:00
logde18ece29436290cae3608d2c942e7e0a69f1a44
treed4355be5590c62d5e66d36f16ba8b53c65f9d1dd
parent6cf38369d216ef676a21fc014a869042a924029d
parentfcf65f06c4eb42c8ecffbe9b7558f9cb84ef44e2
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1975 from BenoitJGirard/master

Fix std.math.powi so powi(x, +-0) = 1 for any x.

1 files changed, 8 insertions(+), 1 deletions(-)

std/math/powi.zig+8-1
......@@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
2525
2626 // powi(x, +-0) = 1 for any x
2727 if (y == 0 or y == -0) {
28 return 0;
28 return 1;
2929 }
3030
3131 switch (x) {
......@@ -174,4 +174,11 @@ test "math.powi.special" {
174174 testing.expectError(error.Overflow, powi(u64, 2, 64));
175175 testing.expectError(error.Overflow, powi(u17, 2, 17));
176176 testing.expectError(error.Overflow, powi(u42, 2, 42));
177
178 testing.expect((try powi(u8, 6, 0)) == 1);
179 testing.expect((try powi(u16, 5, 0)) == 1);
180 testing.expect((try powi(u32, 12, 0)) == 1);
181 testing.expect((try powi(u64, 34, 0)) == 1);
182 testing.expect((try powi(u17, 16, 0)) == 1);
183 testing.expect((try powi(u42, 34, 0)) == 1);
177184}