Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Math::NumberCruncher changing scalar into... something else

Reply
Thread Tools

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

 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      11-15-2005
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:umper;

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

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      11-15-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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() );

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      11-15-2005
(E-Mail Removed) wrote:
> ... a Math::BigInt object ...


Err, I mean, Math::BigFloat, of course...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find and replace something that is nested inside something else? alainfri@gmail.com Perl Misc 4 05-31-2007 11:50 PM
for: else: - any practical uses for the else clause? metaperl.etc@gmail.com Python 25 09-30-2006 11:01 PM
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
umm... something... template(s)... something else... pointer(s)... and such... 0.o yah, I'm hopeless and clueless o.0 C++ 4 10-13-2004 10:34 PM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM



Advertisments