You are here: really big integer « PHP Programming Language « IT news, forums, messages
really big integer

Posted by julian_m on 03/17/06 22:02

I need to calculate the sum of the following numbers

1+ 11 + 111 + 1111 + ......+ 1111.....11111 (the last one is a number
made by 2002 1's )

so, I wrote


$res =0;
for ($i = 1; $i<2003; $i++){
echo str_repeat("1", $i).'<br>';
$res += str_repeat("1", $i);
}

echo 'El resultado total es:<br>';
echo $res;

All works pretty well, and after a really small piece of time, I get:

1.2345679012346E+308

but the result seems to be wrong, beacause I do know (given that I have
a math proof), that it should have 224 1's inside, and as fas as I
know,

1.2345679012346E+308 means 1.2345679012346 * 10^308

which obviously doesn't have such amount of 1's (in fact only has 2 )

Can anyone point me where is the mistake?

sdos - jm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация