Am I allowed to subtract a rational from a float if I explicitly convert it to a float first? Pretty please?
> 3e-1 - Num(.3)
5.55111512312578e-17
Oh look, I got the same answer. Also, Perl6's
printf lies.
> printf "%.100f\n", .3
0.30000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000
> printf "%.100f\n", 3e-1
0.30000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000
> printf "%.100f\n", Num(.3)
0.30000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000
But you can still get an honest
printf with
Inline::Perl5.
use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.run('sub p { printf "%.100f\n", shift }');
$p5.call('p', .3);
$p5.call('p', Num(.3));
$p5.call('p', 3e-1);
=finish
0.29999999999999998889776975374843459576368331909179687500000000000000
+00000000000000000000000000000000
0.29999999999999998889776975374843459576368331909179687500000000000000
+00000000000000000000000000000000
0.30000000000000004440892098500626161694526672363281250000000000000000
+00000000000000000000000000000000