Skip to content
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

Generic exponent in BinaryInteger/power(_:) #72

Closed
oscbyspro opened this issue Aug 22, 2024 · 4 comments
Closed

Generic exponent in BinaryInteger/power(_:) #72

oscbyspro opened this issue Aug 22, 2024 · 4 comments
Labels
addition oh, so shiny! brrr such code, much wow

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 22, 2024

(#67) made me wonder whether the exponent (#53) type should be UX or Magnitude. But, making it fully generic would be even better. It is important that each specialization uses the same underlying implementation and there are multiple ways of ensuring that. I believe, but I'll have to double-check, that the truncated value repeats itself after some power-of-two exponent less than or equal to pow(2, size). If that's the case, then I could simply load the bit pattern that fits in the greater of UX and Magnitude and perform some minor error handling if it doesn't. Otherwise, maybe I'll use a bit-view thingy.

@oscbyspro oscbyspro added addition oh, so shiny! brrr such code, much wow labels Aug 22, 2024
@oscbyspro oscbyspro added this to the Ultimathnum 0.9.0 milestone Aug 22, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 22, 2024

Seems like odd exponents repeat whereas even exponents produce zeros.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 22, 2024

I wonder if I should use UX when the Magnitude is small to maximize the chance that the generic exponent fits, or if it is better to use a smaller type and take the does-not-fit path.

@oscbyspro
Copy link
Owner Author

I8(123).power(U8 .max) // Fallible<I8>(value: -77, error: true)
I8(123).power(U16.max) // Fallible<I8>(value: -77, error: true)
I8(123).power(U32.max) // Fallible<I8>(value: -77, error: true)
I8(123).power(U64.max) // Fallible<I8>(value: -77, error: true)
I8(123).power(UXL.max) // Fallible<I8>(value: -77, error: true)

@oscbyspro
Copy link
Owner Author

I wish it were possible to annotate a generic type parameter with a preferred concrete type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant