Question about floating point math w/perl 
Author Message
 Question about floating point math w/perl

I am trying to use perl for numerical data reduction. I have three output
files which are of the same lenght, are composed of two rows of numbers,
and each have time as the first field. I open them, then do the following:

(open lines are of the form:
  open( BRAD,"< BRAD.1" ) || die "can't open BRAD.1: $!\n";

while ( <PDEC> ) {
  ($time,$dec) = $_ =~ /^\s+(\.\w+E[+-]\w+)\s+(\w*\.\w+)/;
  $tmp = <BRVL>;
  ($vel) = $tmp =~ /^\s+\.\w+E[+-]\w+\s+([-]*\w*\.\w+[-]*\w*)/;
  $tmp = <BRAD>;
  ($rad) = $tmp =~ /^\s+\.\w+E[+-]\w+\s+(\w*\.\w+)/;

  $integ = $dec*$vel/$rad^(3.*1.27-2.);

  printf "%.3f %.3f\n",$time,$integ;


I use PDEC to find the time, then ignore it in the next two matches; I then
need to calculate $integ, a quantity I will numerically integrate using a
fortran routine.

My problem:
$integ is an integer. In addition, when $vel is negative, $integ = 4294967292.

Is there a fix?

Thanks - feel free to reply to this group or to me via email.

Mon, 23 Aug 1999 03:00:00 GMT  
 Question about floating point math w/perl

This may not be a complete answer to your question, but I
wonder if you might have really wanted exponentiation in the

$integ = $dec*$vel/$rad**(3.*1.27-2.);

It would be unusual to want to XOR these floating point values.


P.S.  This is a mistake I have made more than once...


>   $integ = $dec*$vel/$rad^(3.*1.27-2.);


| Michael Sadd                          | Cornell Univerisity        |
| Department of Physics and             | Ithaca, NY 14850           |
| Lab of Atomic and Solid State Physics | |

Mon, 23 Aug 1999 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Question concerning Math::MatrixReal / Floating Point

2. Perl's brain-dead floating point math

3. Floating Point Issues with Math::BigFloat

4. Floating point math errors

5. Floating point question

6. simple floating point question

7. Math::BigInt/Float version question?

8. Perl floating point okay to represent $ amounts?

9. Handling floating point number input in Perl CGI scripts

10. Perl 5.001e *** Floating point exception

11. Problem compiling perl with software floating point emulation

12. Perl floating point problem


Powered by phpBB® Forum Software