[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Math::BigFloat Question



MacPerl'ers,

I'm having some problems using Math::BigFloat.  I was using it for a research project, but I had to come up with another quick fix.  In any event, my problem is that the following subroutine returns 0 and position blank.  For each comparison that's made, 0 continues to be the largest, which shouldn't be the case.

Now, I'm sure that the problem lies w/ myself, however, I don't know that it is.  If anyone has any suggestions, please let me know.


sincerely, na'im


#!/usr/local/bin/perl
# activ2vector.pl --> takes out activation patterns and returns them to
# their binary vector representations

use Math::BigFloat;

@target_output = ('0.0009', '0.5000', '0.2298', '0.7541', '0.7599');

largest_float(*target_output);
# make_pattern(*target_vect);


### finds largest number in array ###

sub largest_float {

          $lar_float = Math::BigFloat->new("0.0000");
        # $lar_float = 0;



        local *target_output = shift @_;

        for ($eout = 0; $eout < @target_output; $eout++) {
        #       if ($lar_float < $target_output[$eout]) {
        #               $lar_float  = $target_output[$eout];
        #               $pos = $eout;
        #       }

                           $out=Math::BigFloat->new("$target_output[$eout]");

                $big = $out->fcmp("$lar_float");

                print 'This is $big: ', "$big\n";

        if ($big == 1) {  # i.e. if this float is larger
                          # than the largest float value
                $lar_float = Math::BigFloat->new("$out");                   $pos = $eout
        }

        }

        print "The largest number is: ", "$lar_float", " at position $pos.\n";

        # $target_vect[$pos] = 1;

        # return @target_vect;

}

### end largest_float ###


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org