tag:blogger.com,1999:blog-8722048993094113071.post6327351939729038946..comments2023-09-11T06:34:38.721-07:00Comments on The world is amazing: Perl: Big number addition with a simple integer numberUnknownnoreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8722048993094113071.post-17809602762957520402009-05-08T12:49:00.000-07:002009-05-08T12:49:00.000-07:00Instead of using Math::BigInt directly you can als...Instead of using Math::BigInt directly you can also using it indirectly.<br /><br />perl -Mbigint -le 'print 999999999999999 + 10000000'Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8722048993094113071.post-18109031470107949452009-04-17T10:20:00.000-07:002009-04-17T10:20:00.000-07:00I could not stop myself from fiddling with this co...I could not stop myself from fiddling with this code:<br /><br /><A HREF="http://kill.devc.at/node/254" REL="nofollow">UnPerlish UnLaziness</A>rhohttps://www.blogger.com/profile/09307769622732055649noreply@blogger.comtag:blogger.com,1999:blog-8722048993094113071.post-5429933466148331442009-04-16T10:24:00.000-07:002009-04-16T10:24:00.000-07:00Ok, apart from the obvious Math::BigInt tangent:
...Ok, apart from the obvious Math::BigInt tangent:<br /><br /><br /> ## putting rest of the number from hand<br /> while($to_add){<br /> $big_num[ $i++ ] = $to_add % 10;<br /> $to_add = int( $to_add / 10 );<br /> }<br /><br /><br />This is just insane. Why not prepend the $to_add<br />to the result?rhohttps://www.blogger.com/profile/09307769622732055649noreply@blogger.comtag:blogger.com,1999:blog-8722048993094113071.post-48340896306188943862009-04-15T12:33:00.000-07:002009-04-15T12:33:00.000-07:00Or you could install Math::BigInt from CPAN, and d...Or you could install <A HREF="http://search.cpan.org/dist/Math-BigInt" REL="nofollow">Math::BigInt</A> from CPAN, and do:<br /><br />perl -MMath::BigInt -le'my $m = Math::BigInt->new("999999999999999"); $m->badd(10000000); print $m'<br /><br />JessAnonymousnoreply@blogger.com