D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7078 - BigInt.toInt returns a long
Summary: BigInt.toInt returns a long
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-07 17:38 UTC by bearophile_hugs
Modified: 2012-02-23 14:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-12-07 17:38:20 UTC
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);
}