Math::NumberCruncher changing scalar into... something else

U

usenet

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 seeking
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
 
U

usenet

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() );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top