Thread overview
[Issue 8164] New: BigInt from char[] too
May 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8164

           Summary: BigInt from char[] too
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2012-05-30 04:57:00 PDT ---
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);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8164



--- Comment #1 from github-bugzilla@puremagic.com 2012-07-01 19:53:10 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/15c655f1b54ef6e2d29b9b91401f1699c98c0d2e Fix issue 8164 BigInt from char[] too

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8164


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from bearophile_hugs@eml.cc 2012-07-01 22:03:16 PDT ---
Thank you. Fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------