authorgravatar for bjg-coding@agaguk.netBenoit Jauvin-Girard <bjg-coding@agaguk.net> 2019-02-17 14:52:40-05:00
committergravatar for bjg-coding@agaguk.netBenoit Jauvin-Girard <bjg-coding@agaguk.net> 2019-02-17 14:52:40-05:00
logfcf65f06c4eb42c8ecffbe9b7558f9cb84ef44e2
treefdccc3faeb40148e4c1db07301b14d09b0d9f1cb
parent6daa041932ae5ab03eed953dacf3ca506078390c

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{...@@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
2525
26 // powi(x, +-0) = 1 for any x26 // powi(x, +-0) = 1 for any x
27 if (y == 0 or y == -0) {27 if (y == 0 or y == -0) {
28 return 0;28 return 1;
29 }29 }
3030
31 switch (x) {31 switch (x) {
...@@ -174,4 +174,11 @@ test "math.powi.special" {...@@ -174,4 +174,11 @@ test "math.powi.special" {
174 testing.expectError(error.Overflow, powi(u64, 2, 64));174 testing.expectError(error.Overflow, powi(u64, 2, 64));
175 testing.expectError(error.Overflow, powi(u17, 2, 17));175 testing.expectError(error.Overflow, powi(u17, 2, 17));
176 testing.expectError(error.Overflow, powi(u42, 2, 42));176 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);
177}184}