gmp problem

From: Date: Fri, 20 Jul 2001 17:43:07 +0000
Subject: gmp problem
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-58947@lists.php.net to get a copy of this message
For some odd reason, I'd like to be able to take a number like 534 and make a larger number by repeating it 5 times, to get 534534534534534. This is part of a parser, so the two integers are passed as gmp numbers. gmp_init(str_repeat(gmp_strval($a),gmp_intval($b))) sometimes works and sometimes fails. To illustrate this consider: for ($i = 1; $i < 10; $i++) {
    $temp = str_repeat(gmp_strval(gmp_init($i)),8);
    echo "$temp is ",gmp_strval(gmp_init($temp)),"<br>";
} Yields 11111111 is 11111111 22222222 is 22222222 33333333 is 33333333 44444444 is 44444444 55555555 is 55555555 66666666 is 66666666 77777777 is 77777777 88888888 is 8 99999999 is 9 Why do the last two fail? How can I fix this? Note that the following works for ($i = 1; $i < 10; $i++) {
    $temp = str_repeat("$i",8);  # or     $temp = str_repeat($i,8);
    echo "$temp is ",gmp_strval(gmp_init($temp)),"<br>";
} but again I have a parser, so my input is a gmp number.

« previous php.general (#58947) next »