1arryb
User
Mar 20, 2009, 12:22 PM
Post #15 of 17
(5173 views)

mickey, Look for a bug in your latest program, not Math::BigFloat (hint: what is the value of $1 at '$temp = "1$1";')? This is getting tiresome. I have tested the following program and it works. Please study it before replying.
#!/usr/bin/perl use strict; use warnings; use Math::BigFloat; open (IN, "< exponents.txt") or die "can't open exponents.txt for reading."; while(my $line = <IN>) { # Trim line termination. $line =~ tr/\r\n//d; # Get a number in exponential notation from line. $line =~ m/value = (\S+)/; my $v = $1; # Handle parse errors. die "can't parse \"$line\"" unless $v; # Normalize bogus data to a value Math::BigFloat can handle # AND that works for our application. $v = "1$v" if $v =~ /^e*\d+/; # Get the value in numeric form. my $d = Math::BigFloat>new($v); # Test numeric value and do something. if ( $d < 1) { print ( "$v < 1, d=$d \n" ); } else { print ( "$v >= 1, d=$d \n" ); } } close (IN); exponents.txt contains:
otherString value = e30 otherString otherString value = 4e30 otherString otherString value = 1e20 otherString otherString value = e200 otherString otherString value = 3.2e23 otherString If you run the program, you get:
1e30 < 1, d=0.000000000000000000000000000001 4e30 < 1, d=0.000000000000000000000000000004 1e20 < 1, d=0.00000000000000000001 1e200 < 1, d=0.000000000000000000000000000000000 00000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000 00000000000000000000000001 3.2e23 >= 1, d=320000000000000000000000 Larry
(This post was edited by 1arryb on Mar 20, 2009, 12:30 PM)
