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

Discussion in 'Perl Misc' started by usenet@DavidFilmer.com, Nov 15, 2005.

  1. Guest

    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
    , Nov 15, 2005
    #1
    1. Advertising

  2. Guest

    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() );
    , Nov 15, 2005
    #2
    1. Advertising

  3. Guest

    wrote:
    > ... a Math::BigInt object ...


    Err, I mean, Math::BigFloat, of course...
    , Nov 15, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    471
    Guest
    Oct 13, 2004
  2. Clint Olsen
    Replies:
    6
    Views:
    340
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  3. Replies:
    0
    Views:
    83
  4. Replies:
    4
    Views:
    203
    Tad McClellan
    Jun 1, 2007
  5. VK
    Replies:
    15
    Views:
    1,117
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page