-
Notifications
You must be signed in to change notification settings - Fork 13.3k
N.pow(M)
returns zero, does not overflow for unsigned N
and both N
and M
even (sometimes)
#34913
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
#28248 was supposed to fix this; looks like it missed the unsigned version? |
This playpen says that |
I meant that #28248 fixed this for pow() on signed integers, but not on unsigned integers; it looks like the implementation is copy-pasted for some reason. |
Could I take a stab at this? |
Sure; feel free to ask if you have questions. |
Is overflow checking off in the libcore tests? It'd be nice to be able to write some standard |
Overflow checking in unit tests ( If you need to specify the overflow mode, you can use a separate test which explicitly specifies |
The pow() method for unsigned integers produced 0 instead of trapping overflow for certain inputs. Calls such as 2u32.pow(1024) produced 0 when they should trap an overflow. This also adds tests for the correctly handling overflow in unsigned pow(). For issue number rust-lang#34913
Fix overflow checking in unsigned pow() The pow() method for unsigned integers produced 0 instead of trapping overflow for certain inputs. Calls such as 2u32.pow(1024) produced 0 when they should trap an overflow. This also adds tests for the correctly handling overflow in unsigned pow(). This was previously fixed for signed integers in #28248, but it seems unsigned integers got missed that time. For issue number #34913
This has since been fixed, in #34942, which it looks like also added a test, so closing. |
Today I learned that eight to the power of eight is zero. Who'da thunk?
Incorrect:
2u8.pow(500)
➡️0
❌8u8.pow(8)
➡️0
❌4u32.pow(1000)
➡️0
❌Correct:
8u8.pow(7)
➡️ overflow ✅8i8.pow(8)
➡️ overflow ✅2u8.pow(9)
➡️ overflow ✅Oddly enough, this one breaks the pattern:
2u8.pow(10)
➡️ overflow ✅Haven't bothered with further cases; at this point it's probably best to just look at the implementation and see what's going on.
The text was updated successfully, but these errors were encountered: