Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perl 5.005_02 math bug #1019

Closed
p5pRT opened this issue Jan 10, 2000 · 2 comments
Closed

Perl 5.005_02 math bug #1019

p5pRT opened this issue Jan 10, 2000 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 10, 2000

Migrated from rt.perl.org#1970 (status was 'resolved')

Searchable as RT1970$

@p5pRT
Copy link
Author

p5pRT commented Jan 10, 2000

From thj@hpesthj.fc.hp.com

#!/usr/local/bin/perl5 -w

  $x = 22818.875 - 22765.65;
  print("$x\n");

outputs​:

53.2249999999985

The equiv C code

#include <stdio.h>

void main(void)
{
  double x;
  x = 22818.875 - 22765.65;
  printf("%lf\n", x);
}

correctly outputs​:

53.225

@p5pRT
Copy link
Author

p5pRT commented Jan 10, 2000

From @tamias

On Mon, Jan 10, 2000 at 01​:03​:01PM -0700, Tim Jackson wrote​:

On HP PA-RISC systems (perl version 5.005_02 built for PA-RISC1.1), the
following code

#!/usr/local/bin/perl5 -w

$x = 22818.875 - 22765.65;
print("$x\n");

outputs​:

53.2249999999985

The equiv C code

#include <stdio.h>

void main(void)
{
double x;
x = 22818.875 - 22765.65;
printf("%lf\n", x);
}

correctly outputs​:

53.225

Those two code samples are not equivalent. Try this instead​:

  #!/usr/local/bin/perl5 -w

  $x = 22818.875 - 22765.65;
  printf "%lf\n", $x;

Also, refer to the first entry in perlfaq4.

Ronald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant