[Issue 12974] Integer constant exponentiation gives wrong value
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jun 24 01:41:58 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12974
--- Comment #4 from safety0ff.bugz <safety0ff.bugz at gmail.com> ---
(In reply to bearophile_hugs from comment #1)
> This seems to pass on my 32 bit system:
>
> assert((3uL)^^40uL == 12157665459056928801uL); // error
A quick check on dpaste suggests that it passes in 2.065 and fails in git.
I suspect it's just a const-folding change that enables that line to get
CT-evaluated in git versus 2.065 because the other expression fails in both.
(In reply to bearophile_hugs from comment #2)
> ulong(uint.max) ^^ 40UL is something like:
>
> 208158641954659548848625708480171133381207412524816152551724014122904182251
> 307912571997657650065254566688428866939275444029732004368372970852338827367
> 264791762120127429330987166710374655101628820795072338450535380344923607954
> 436493529260566657177085349603902288285849258947350283095860468263104249444
> 251291644696840982120081667552033239985460311393336090041066199773922562599
> 18212890625
Typo, the exponent was supposed to be 2uL.
Corrected:
//CODE: http://dpaste.dzfl.pl/ef7cd3cfd32d
import std.math;
void main()
{
ulong uimax = uint.max;
assert(uimax^^2uL == 18446744065119617025uL); //passes
ulong three = 3uL;
assert(three^^40uL == 12157665459056928801uL); // passes
assert((cast(ulong)uint.max)^^2uL == 12157665459056928801uL); // error
assert((3uL)^^40uL == 12157665459056928801uL); // error
}
--
More information about the Digitalmars-d-bugs
mailing list