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

sprintf() float precision cannot go beyond 15[efg] #5013

Open
p6rt opened this issue Jan 7, 2016 · 1 comment
Open

sprintf() float precision cannot go beyond 15[efg] #5013

p6rt opened this issue Jan 7, 2016 · 1 comment

Comments

@p6rt
Copy link

p6rt commented Jan 7, 2016

Migrated from rt.perl.org#127201 (status was 'new')

Searchable as RT127201$

@p6rt
Copy link
Author

p6rt commented Jan 7, 2016

From dankogai@dan.co.jp

This is possibly related to https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127184 .
Run the code below​:

  #!/usr/bin/env perl6
  use v6;
  my $log2 = log(2);
  for 0..20 {
  say sprintf "%%.%dg​:\t%.{$_}g", $_, $log2;
  }

and you get​:

  %.0g​: 1
  %.1g​: 0.7
  %.2g​: 0.69
  %.3g​: 0.693
  %.4g​: 0.6931
  %.5g​: 0.69315
  %.6g​: 0.693147
  %.7g​: 0.6931472
  %.8g​: 0.69314718
  %.9g​: 0.693147181
  %.10g​: 0.6931471806
  %.11g​: 0.69314718056
  %.12g​: 0.69314718056
  %.13g​: 0.6931471805599
  %.14g​: 0.69314718055995
  %.15g​: 0.693147180559945
  %.16g​: 0.693147180559945
  %.17g​: 0.693147180559945
  %.18g​: 0.693147180559945
  %.19g​: 0.693147180559945
  %.20g​: 0.693147180559945

With perl5 version​:

  #!/usr/bin/env perl
  use v5.22;
  use warnings;
  my $log2 = log(2);
  for (0..20) {
  say sprintf "%%.%dg​:\t%.${_}g", $_, $log2;
  }

  %.0g​: 0.7
  %.1g​: 0.7
  %.2g​: 0.69
  %.3g​: 0.693
  %.4g​: 0.6931
  %.5g​: 0.69315
  %.6g​: 0.693147
  %.7g​: 0.6931472
  %.8g​: 0.69314718
  %.9g​: 0.693147181
  %.10g​: 0.6931471806
  %.11g​: 0.69314718056
  %.12g​: 0.69314718056
  %.13g​: 0.6931471805599
  %.14g​: 0.69314718055995
  %.15g​: 0.693147180559945
  %.16g​: 0.6931471805599453
  %.17g​: 0.69314718055994529
  %.18g​: 0.693147180559945286
  %.19g​: 0.6931471805599452862
  %.20g​: 0.69314718055994528623

Dan the Inaccurate Perl Monger

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

No branches or pull requests

1 participant