01777777777777777777777 [std.conv.octal]
Steven Schveighoffer
schveiguy at gmail.com
Thu Apr 7 19:59:24 UTC 2022
On 4/7/22 3:18 PM, kdevel wrote:
> On Thursday, 7 April 2022 at 16:38:58 UTC, Adam Ruppe wrote:
>> On Thursday, 7 April 2022 at 16:28:39 UTC, kdevel wrote:
>>> That was not my objection. My point is that it won't compile for
>>> certain valid octal literals.
>>
>> They're not actually octal literals.
>
> You certainly don't want to dispute that
>
> 01777777777777777777777
>
> is actually an octal literal whose value fits in a ulong?
but that's not what you gave to the compiler. for
`octal!1777777777777777777777`, the number part of that expression isn't
a valid literal that fits in a ulong.
>
> The method does not work for most of the possible octal literals whose
> values fit in a ulong. I would call it an inconvenience method.
It works for all numbers below 288,230,376,151,711,744 (i.e. up to 58 bits).
So, yeah, not all of them. But many of them.
But I kind of agree with you that the integer one is full of problems.
Another problem I just realized:
```d
auto x1 = octal!17777777777;
auto x2 = octal!"17777777777";
pragma(msg, typeof(x1)); // long
pragma(msg, typeof(x2)); // int
```
Why? because `octal(T)` takes the type of `T`
And there's no way to fix it. Because you'd want `octal!1L` to be long,
so you can't just look at the value.
We might want to just undocument the integer version.
-Steve
More information about the Digitalmars-d
mailing list