-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BinaryInteger/power(_:) #53
Comments
|
Hm. I'm reluctant to allow signed exponents because I don't want to think about 0-x and the like. But, it turns out that infinite values just work. Most inputs with infinite exponents cannot be allocated, but that's equally true for big-but-finite exponents. So perhaps T.Magnitude is preferred over Natural<T>. I also don't need unsigned systems integer convenience methods if the exponent type is T.Magnitude. |
The exponent can be clamped to UX because the allocation limit is IX.max bits. Note that the clamped value must preserve the least significant bit of the original exponent in order to correctly toggle ~0. Also note that only 0, 1, and ~0 can be allocated when the exponent is greater than IX.max. This approach replaces arbitrary integer shifts with systems integer shifts.
We only need to combine the multiplier's error indicator once at the end.
I'll add an exponentiation extension to BinaryInteger. It should wrap around and return an error indicator, making the result equivalent to repeated BinaryInteger/times(_:) calls. Negative and infinite exponents will be banned using Natural<T>.
The text was updated successfully, but these errors were encountered: