D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8164 - BigInt from char[] too
Summary: BigInt from char[] too
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-30 04:57 UTC by bearophile_hugs
Modified: 2012-07-01 22:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-05-30 04:57:00 UTC
I have code that generates arrays of mutable chars, and I have to convert them to BigInts. I'd like this to be allowed:

import std.bigint: BigInt;
void main() {
    char[] s1 = "123".dup;
    assert(BigInt(s1) == 123);
    char[] s2 = "0xABC".dup;
    assert(BigInt(s2) == 2748);
}


DMD 2.060alpha gives:

...\dmd2\src\phobos\std\bigint.d(97): Error: function std.internal.math.biguintcore.BigUint.fromHexString (string s) is not callable using argument types (char[])
...\dmd2\src\phobos\std\bigint.d(97): Error: cannot implicitly convert expression (s[2u..__dollar]) of type char[] to string
...\dmd2\src\phobos\std\bigint.d(99): Error: function std.internal.math.biguintcore.BigUint.fromDecimalString (string s) is not callable using argument types (char[])
...\dmd2\src\phobos\std\bigint.d(99): Error: cannot implicitly convert expression (s) of type char[] to string
test.d(4): Error: template instance std.bigint.BigInt.__ctor!(char[]) error instantiating


Current workaround: I use a cast:

char[] s1 = "123".dup;
assert(BigInt(cast(string)s1) == 123);
Comment 2 bearophile_hugs 2012-07-01 22:03:16 UTC
Thank you. Fixed.