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 doesn't format %floats with many significant digits properly #3248

Closed
p6rt opened this issue Oct 14, 2013 · 6 comments
Closed

sprintf doesn't format %floats with many significant digits properly #3248

p6rt opened this issue Oct 14, 2013 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Oct 14, 2013

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

Searchable as RT120232$

@p6rt
Copy link
Author

p6rt commented Oct 14, 2013

From @Mouq

10​:48 < Mouq> p5eval​: printf("%.50f", 1.115)
10​:48 < p5eval> Mouq​: 1.114999999999999991118215802998747676610946655273441
10​:48 < Mouq> r​: printf("%.50f", 1.115)
10​:48 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
10​:48 < diakopter> p5eval​: printf("%.500f", 1.115)
10​:48 < p5eval> diakopter​:
1.11499999999999999111821580299874767661094665527343750000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
10​:48 * Mouq likes p5's approximation better than rakudo's fail
10​:49 < timotimo> ... what the hell is that 1.00000...0001.15 thing? :D
10​:49 < Mouq> n​: printf("%.50f", 1.115)
10​:49 <+camelia> niecza v24-98-g473bd20​:
OUTPUT«1.11500000000000000000000000000000000000000000000000»
10​:49 < diakopter> megafail
10​:49 < Mouq> niecza++
10​:50 < timotimo> well, you *did* ask for a float to be output
10​:50 < timotimo> and niecza just goes ahead and says "haha, that's totally
a rat!"
10​:54 < FROGGS> Mouq​: please send a rakudobug
10​:55 < Mouq> FROGGS​: Roger
10​:57 < Mouq> r​: printf("%.50f", '1.115')
10​:57 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
10​:58 < moritz> r-j​: printf("%.50f", '1.115')
10​:58 <+camelia> rakudo-jvm e22ac2​:
OUTPUT«1.000000000000000000000000000001.1499999999999994E49»
10​:58 < moritz> r​: printf("%.10f", '1.115')
10​:58 <+camelia> rakudo e22ac2​: OUTPUT«1.1150000000»
11​:02 < diakopter> nqp-m​: printf("%.10f", '1.115')
11​:02 <+camelia> nqp-moarvm​: OUTPUT«Bytecode validation error at offset 22,
instruction 4​:␤register operand index 50
  out of range 0..9␤»
11​:03 < FROGGS> r​: printf("%.50f", 1.115)
11​:03 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
11​:03 < FROGGS> nqp​: say(nqp​::sprintf("%.50f", 1.115))
11​:03 <+camelia> nqp​: OUTPUT«get_pmc_keyed() not implemented in class
'Float'␤current instr.​: 'next_argument' pc
  50548 (src/stage2/gen/NQPHLL.pir​:19479)
(src/stage2/gen/NQPHLL.nqp​:2137)␤»
11​:04 < FROGGS> nqp​: say(nqp​::sprintf("%.50f", [1.115])) # better
11​:04 <+camelia> nqp​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49␤»
11​:04 < jnthn> nqp-jvm​: nqp​: say(nqp​::sprintf("%.50f", [1.115])) # curious
11​:04 <+camelia> nqp-jvm​: OUTPUT«Confused at line 2, near "nqp​: say(n"␤ in
panic (src/stage2/gen/NQPHLL.nqp​:279)␤
  in comp_unit (src/stage2/gen/NQP.nqp​:772)␤ in TOP
(src/stage2/gen/NQP.nqp​:669)␤ in parse
  (src/stage2/gen/QRegex.nqp​:1247)␤ in parse
(src/stage2/gen/NQPHLL.nqp​:1376)␤ in…»
11​:04 < FROGGS> why does that take so long to compute?
11​:04 < jnthn> nqp-jvm​: say(nqp​::sprintf("%.50f", [1.115])) # curious
11​:04 <+camelia> nqp-jvm​:
OUTPUT«1.000000000000000000000000000001.1499999999999994E49␤»
11​:05 < jnthn> Portably buggy :P

@p6rt
Copy link
Author

p6rt commented Aug 19, 2014

From @perlpilot

On Mon Oct 14 08​:12​:47 2013, Mouq wrote​:

10​:48 < Mouq> p5eval​: printf("%.50f", 1.115)
10​:48 < p5eval> Mouq​:
1.114999999999999991118215802998747676610946655273441
10​:48 < Mouq> r​: printf("%.50f", 1.115)
10​:48 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
10​:48 < diakopter> p5eval​: printf("%.500f", 1.115)
10​:48 < p5eval> diakopter​:
1.11499999999999999111821580299874767661094665527343750000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
10​:48 * Mouq likes p5's approximation better than rakudo's fail
10​:49 < timotimo> ... what the hell is that 1.00000...0001.15 thing?
:D
10​:49 < Mouq> n​: printf("%.50f", 1.115)
10​:49 <+camelia> niecza v24-98-g473bd20​:
OUTPUT«1.11500000000000000000000000000000000000000000000000»
10​:49 < diakopter> megafail
10​:49 < Mouq> niecza++
10​:50 < timotimo> well, you *did* ask for a float to be output
10​:50 < timotimo> and niecza just goes ahead and says "haha, that's
totally
a rat!"
10​:54 < FROGGS> Mouq​: please send a rakudobug
10​:55 < Mouq> FROGGS​: Roger
10​:57 < Mouq> r​: printf("%.50f", '1.115')
10​:57 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
10​:58 < moritz> r-j​: printf("%.50f", '1.115')
10​:58 <+camelia> rakudo-jvm e22ac2​:
OUTPUT«1.000000000000000000000000000001.1499999999999994E49»
10​:58 < moritz> r​: printf("%.10f", '1.115')
10​:58 <+camelia> rakudo e22ac2​: OUTPUT«1.1150000000»
11​:02 < diakopter> nqp-m​: printf("%.10f", '1.115')
11​:02 <+camelia> nqp-moarvm​: OUTPUT«Bytecode validation error at
offset 22,
instruction 4​:␤register operand index 50
out of range 0..9␤»
11​:03 < FROGGS> r​: printf("%.50f", 1.115)
11​:03 <+camelia> rakudo e22ac2​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49»
11​:03 < FROGGS> nqp​: say(nqp​::sprintf("%.50f", 1.115))
11​:03 <+camelia> nqp​: OUTPUT«get_pmc_keyed() not implemented in class
'Float'␤current instr.​: 'next_argument' pc
50548 (src/stage2/gen/NQPHLL.pir​:19479)
(src/stage2/gen/NQPHLL.nqp​:2137)␤»
11​:04 < FROGGS> nqp​: say(nqp​::sprintf("%.50f", [1.115])) # better
11​:04 <+camelia> nqp​:
OUTPUT«1.0000000000000000000000000000000000000000001.15e+49␤»
11​:04 < jnthn> nqp-jvm​: nqp​: say(nqp​::sprintf("%.50f", [1.115])) #
curious
11​:04 <+camelia> nqp-jvm​: OUTPUT«Confused at line 2, near "nqp​:
say(n"␤ in
panic (src/stage2/gen/NQPHLL.nqp​:279)␤
in comp_unit (src/stage2/gen/NQP.nqp​:772)␤ in TOP
(src/stage2/gen/NQP.nqp​:669)␤ in parse
(src/stage2/gen/QRegex.nqp​:1247)␤ in parse
(src/stage2/gen/NQPHLL.nqp​:1376)␤ in…»
11​:04 < FROGGS> why does that take so long to compute?
11​:04 < jnthn> nqp-jvm​: say(nqp​::sprintf("%.50f", [1.115])) # curious
11​:04 <+camelia> nqp-jvm​:
OUTPUT«1.000000000000000000000000000001.1499999999999994E49␤»
11​:05 < jnthn> Portably buggy :P

Fixed for Moar/Parrot​:

00​:04 <PerlJam> r​: printf("%.50f", 1.115)
00​:04 <+camelia> rakudo-jvm 9a2f3e​: OUTPUT«(timeout)»
00​:04 <+camelia> ..rakudo-{parrot,moar} 9a2f3e​: OUTPUT«1.11500000000000000000000000000000000000000000000000»

Not sure what's going on with the JVM​:

00​:05 <PerlJam> nqp-jvm​: say(nqp​::sprintf("%.50f",[1.115]))
00​:05 <+camelia> nqp-jvm​: OUTPUT«#␤# There is insufficient memory for the Java Runtime Environment to continue.␤#
  pthread_getattr_np␤# An error report file with more information is saved as​:␤#
  /home/p6eval/hs_err_pid5092.log␤»

@p6rt
Copy link
Author

p6rt commented Aug 19, 2014

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @usev6

This works for Moar, Parrot and JVM​:

$ perl6 -e 'printf("%.50f", 1.115)'
1.11500000000000000000000000000000000000000000000000

I added a test to S32-str/sprintf.t with the following commit​: Raku/roast@46ef5bf0e9. I'm closing the ticket.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @usev6

This works for Moar, Parrot and JVM​:

$ perl6 -e 'printf("%.50f", 1.115)'
1.11500000000000000000000000000000000000000000000000

I added a test to S32-str/sprintf.t with the following commit​: Raku/roast@46ef5bf0e9. I'm closing the ticket.

@p6rt p6rt closed this as completed Oct 17, 2014
@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

@usev6 - Status changed from 'open' to 'resolved'

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