Home > Archive > PERL Miscellaneous > November 2005 > Math::NumberCruncher changing scalar into... something else
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Math::NumberCruncher changing scalar into... something else
|
|
| usenet@DavidFilmer.com 2005-11-15, 7:00 pm |
| I'm playing around with the unit conversion methods of
Math::NumberCruncher. It seems to be changing an ordinary scalar
into... something else... that I don't really understand. I am s ing
advice on what is happening to my scalar and which perldoc or other
resource I can use to understand it.
Kindly consider this sample code, which simply attempts to convert a
value from feet->meters and back again:
#!/usr/bin/perl
use strict; use warnings;
use Math::NumberCruncher;
use Data::Dumper;
my $crunch = Math::NumberCruncher->new();
my $length = 5; #feet
print Dumper $length; #an ordinary scalar
$length = $crunch -> ft2m($length); #convert to meters
print Dumper $length; #not an ordinary scalar
print "$length meters\n"; #...but it looks like one
$length = $crunch -> m2ft($length); #convert back to feet (?)
print "$length feet\n"; #NaN???
__END__
########## OUTPUT ############
$VAR1 = 5;
$VAR1 = bless( {
'_m' => [
1524
],
'_es' => '-',
'_p' => -20,
'_e' => [
3
],
'sign' => '+'
}, 'Math::BigFloat' );
1.52400000000000000000 meters
NaN feet
| |
| usenet@DavidFilmer.com 2005-11-15, 7:00 pm |
| usenet@DavidFilmer.com wrote:
> I'm playing around with the unit conversion methods of
> Math::NumberCruncher. It seems to be changing an ordinary scalar
> into... something else... that I don't really understand.
OK, I figured out that it is converting it to a Math::BigInt object
(or, really, it's not "converting" anything - it's "returning" a M:BI
object with which I'm stomping over the original scalar).
> $length = $crunch -> m2ft($length); #convert back to feet (?)
It seems I need to do something like this:
$length = $crunch -> m2ft( $length -> bstr() );
| |
| usenet@DavidFilmer.com 2005-11-15, 7:00 pm |
| use...@DavidFilmer.com wrote:
> ... a Math::BigInt object ...
Err, I mean, Math::BigFloat, of course...
|
|
|
|
|