BitIntegers.jl icon indicating copy to clipboard operation
BitIntegers.jl copied to clipboard

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

Open NHDaly opened this issue 7 years ago • 6 comments

:) 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.

NHDaly avatar Dec 12 '18 05:12 NHDaly

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?

rfourquet avatar Dec 16 '18 14:12 rfourquet

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! :)

NHDaly avatar Dec 16 '18 19:12 NHDaly

:) I opened https://github.com/JuliaLang/julia/issues/30444 to discuss it! :)

ghost avatar Dec 18 '18 23:12 ghost

I think https://github.com/JuliaLang/julia/pull/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!!

NHDaly avatar Feb 17 '22 05:02 NHDaly