Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Math::BigInt Newbee question.

by Paladin (Priest)
on Jan 27, 2005 at 16:57 UTC ( #425624=note: print w/replies, xml ) Need Help??


in reply to Math::BigInt Newbee question.

When I run that code, I get
$ perl whomany.pl 2 675 Global symbol "$arg2" requires explicit package name at test.pl line 2 +0. Execution of test.pl aborted due to compilation errors.

So I am guessing that the code you pasted is not the code that's actually running. You don't declare $arg2 and are missing ->new in a few places.

Also, bdiv and bmul modify inplace. I believe what you were trying to write is:

#!/usr/bin/perl -w use strict; use Math::BigInt; #BigInt KiloByte Unit my $KB = Math::BigInt->new( "1024" ); #BigInt MegaByte Unit my $MB = $KB->copy()->bmul( $KB ); #BigInt GigaByte Unit my $GB = $MB->copy()->bmul( $KB ); print "$KB, $MB, $GB\n"; my $arg1 = Math::BigInt->new( shift ); my $arg2 = Math::BigInt->new( shift ); # arg1 is in GBs my $GBarg1 = $arg1->copy()->bmul( $GB ); # arg2 is in MBs my $MBarg2 = $arg2->copy()->bmul( $MB ); print $GBarg1, " ", $MBarg2, "\n"; # why rc is 0? my ($rc, $rem) = $GBarg1->copy()->bdiv( $MBarg2 ); print "rc is [$rc]\n";
Note: Also, to be really correct, you will need to add 1 more CD to the final result to take up the remainder of the data.

Update: Clean up code a bit

Replies are listed 'Best First'.
Re^2: Math::BigInt Newbee question.
by ikegami (Pope) on Jan 27, 2005 at 17:20 UTC

    I think you can also do my $MB = $KB * $KB; instead of my $MB = $KB->copy()->bmul( $KB ); thanks to overloaded operators.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://425624]
help
Chatterbox?
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already
[perldigious]: Snowshoeing time stevieb? I need to buy a pair so I can walk my German Shepherd properly through the country.
[stevieb]: yeah, I snowshoe a fair amount in the mountains. I also use spikes similar to these very often as well
[perldigious]: Discipulus: alternate link
[stevieb]: LOL you can easily replace "Helsinki" with "Alberta"
[perldigious]: I used to live at the top of a very steep hill stevieb, I can relate to the video. Literally used to have to build up momentum and try to force my vehicle to make it up the hill to park in my driveway properly... didn't always make it.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-12-06 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.