-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
re-enable BigInt hexadecimal literals #23546
Conversation
I agree. It's not a law of the universe that hexadecimal must give |
I re-added the tests and updated the docs which where modified in #12760. |
@@ -235,16 +235,18 @@ For users coming to Julia from R, these are some noteworthy differences: | |||
a larger size type, such as `Int64` (if `Int` is `Int32`), `Int128`, or the arbitrarily large | |||
`BigInt` type. There are no numeric literal suffixes, such as `L`, `LL`, `U`, `UL`, `ULL` to indicate | |||
unsigned and/or signed vs. unsigned. Decimal literals are always signed, and hexadecimal literals | |||
(which start with `0x` like C/C++), are unsigned. Hexadecimal literals also, unlike C/C++/Java | |||
(which start with `0x` like C/C++), are unsigned, unless when they encode more than 128 bits, | |||
in which case they are of type ``BigInt``. Hexadecimal literals also, unlike C/C++/Java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``BigInt``
-> `BigInt`
Ok to merge? |
6b2fcb8
to
de9d36d
Compare
Jeff was supporting the idea, but without explicit approval, I'm not sure to dare to merge it mysef. So gentle bump! |
This can be re-enabled at any point since it's an error now. I think the weird thing about these is that they use an input syntax that is supposed to produce unsigned integers but produces a signed integer type. Let's let this wait – we can always have the debate later and enable this in 1.x. |
Oh, I see the connection to the MT printing, just read that. |
I'm very fine to wait, it was just convenient to flesh out a nicer print for |
Given that this provides a motivation for the hex syntax for |
aa8655d
to
713c714
Compare
Besides #25129 (the seed of a
Given that support was expressed, I will merge soon barring objections. |
713c714
to
426adaa
Compare
Yet another argument for this change: Julia itself uses long hexadecimal digits to represent primitive types: julia> primitive type UInt200 200 end
julia> reinterpret(UU, rand(UInt8, 25))[]
UU(0x616395f3cd92da91f682131e0a681693b380f61127cb303bc7)
julia> 0x616395f3cd92da91f682131e0a681693b380f61127cb303bc7
ERROR: syntax: Hex or binary literal too large for UInt128
[...] That would be cool to be able to manipulate |
As this reverts a change which apparently was uncontroversial (but not supported by solid arguments IMO, see below), I apologize in advance to re-open the discussion, and to try to have this decision reconsidered.
This tries to fix what appears to me as a useless and frustrating limitation: the impossibility to input arbitrary-precision numbers as hexadecimal literals. My first attempt (which proves my willingness to try to respect the earlier decision) at fixing this was to create a
BigUInt <: Unsigned
type to hold arbitrary-precision unsigned numbers (a thin wrapper overBigInt
). After a couple hours of coding, it became clear that, even if the code complexity overhead was not big, no-one would want to maintain this new type, at least not in Base (BigInt
alone is complex enough). But after all,BigInt
is enough for most purposes where one needs a bigUnsigned
(e.g. as bit fields), which is helped by the fact that theBigInt
uses "two-complement" semantics. Except that they can encode negative values. Having specific printing routines to represent them in hexadecimal would help using them asUnsigned
: e.g.For this last number, "...1110" is the mathematical representation of
-2
using 2-adic numbers, i.e. there is some soundness to it.So I claim that representing and inputing
BigInt
with hexadecimal/octal/binary literals has nothing wrong in itself. IMHO, enabling the literal0x100000000000000000000000000000000
to parse requires only to document that hex-literals don't necessarily produceUnsigned
numbers, so I updated the docs here.The arguments for disabling parsing
BigInt
hex literals that I can recollect (from #11105 and #11130):I'm not conviced honestly; sure, more complexity brings more possibilities for bugs; but Julia didn't use this argument to have only one integer type in Base...
Well, as long as we parse decimal
BigInt
literals, this will remain the case.it may appear so, until one needs them.
So my argument is that it is useful to have hex-literals for
BigInt
, and that it's surprising only if one believes that hex-literals must produceUnsigned
numbers.