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

Add unsigned(T) in addition to existing unsigned(x::XBS). #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

NHDaly
Copy link
Contributor

@NHDaly NHDaly commented Dec 12, 2018

:) I noticed that these methods were missing.

Thanks for the really handy package!! :)


Adds methods to unsigned and signed that take types instead of values. Also extends both to work over all XBI, not just XBS/XBU, so that you can call unsigned(UInt256) without an error.

This is in addition to the existing `unsigned(x)`, `signed(x)`.
Also extends `unsigned` and `signed` so you can call them on already
unsigned/signed types (keeping with the Base integers)
@rfourquet
Copy link
Owner

Thanks for your PR!

I'm in favor of such functionality, but remember having a hard time choosing a name. When looking at the documentation of unsigned / signed, there is no mention that it works on types; moreover, it seems that the tendency in Base is to give different names for functions which work on values or types. But it's true that unsigned for integer types is already defined in Base.MultiplicativeInverses, but this seems like an internal detail.

There is also the function Base.uinttype, defined for floating point types, which reflects in its name the fact that it operate on the type level. I chose this name in this package, but this is not really satisfying as this function is not documented (it seems to mean, according to how it is used: "give me the bit pattern of this value, as an unsigned integer"), and there is no obvious good corresponding name for getting the "signed" type: inttype? sinttype ? (sounds terrible!) I don't remember if this functionality is in Base for Base integer types, is it?

What do you think?

@NHDaly
Copy link
Contributor Author

NHDaly commented Dec 16, 2018

Oh, huh, you're totally right! I hadn't even noticed that there wasn't a corresponding signed(UInt64); i just assumed there was!!

hmm those are all good points. Thanks for pointing out Base.uinttype in this package -- i hadn't even noticed it. :)That will probably do for now.

I think we should ask around a bit about why julia doesn't have a way to convert between the signed/unsigned types easily, and then follow whatever consensus arises there. Thanks for pointing me in that direction! :)

@ghost
Copy link

ghost commented Dec 18, 2018

:) I opened JuliaLang/julia#30444 to discuss it! :)

@NHDaly
Copy link
Contributor Author

NHDaly commented Feb 17, 2022

I think JuliaLang/julia#34864 eventually did add support for this in Base, so this PR might actually be good to go now? Sorry i let it languish for so long!!

@omus
Copy link
Contributor

omus commented Jun 13, 2024

@NHDaly looks like you need to resolve the conflicts on this PR

@NHDaly
Copy link
Contributor Author

NHDaly commented Aug 16, 2024

Thanks Curtis. Finally done so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants