Bug 7078 – BigInt.toInt returns a long

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-12-07T17:38:00Z
Last change time
2012-02-23T14:30:23Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-12-07T17:38:20Z
Despite what the ddoc of BigInt.toInt() says, it returns a long. I suggest to change toInt() to really return an int: /// Returns the value of this BigInt as a long, /// or +- long.max if outside the representable range. long toLong() pure const { return (sign ? -1 : 1) * (data.ulongLength() == 1 && (data.peekUlong(0) <= cast(ulong)(long.max)) ? cast(long)(data.peekUlong(0)) : long.max); } /// Returns the value of this BigInt as an int, /// or +- int.max if outside the representable range. long toInt() pure const { return (sign ? -1 : 1) * (data.uintLength() == 1 && (data.peekUint(0) <= cast(uint)(int.max)) ? cast(int)(data.peekUint(0)) : int.max); }
Comment #1 by clugdbug — 2011-12-08T00:26:45Z
Comment #2 by clugdbug — 2012-02-23T14:30:23Z