http://qs321.pair.com?node_id=534734

fizbin has asked for the wisdom of the Perl Monks concerning the following question:

The following code (when run without any arguments, so that the default @ARGV is picked up below) triggers some kind of strange bizarre bug in Math::BigFloat. It appears that I'm creating a value that is both 1 and 0 at the same time. Can someone help make it shorter into a test case I can submit?
#!perl use bignum; # This is Stirling's approximation for log(n!), but # without the "-n" piece that cancels out below in any # case. sub xe{ $_[0]*log($_[0])+log(atan2(1,1)*8*$_[0])/2 + 1/(12*$_[0]) - 1/(360*($_[0]**3)) + 1/(1260*($_[0]**5)); } if (!@ARGV) { @ARGV = qw{ 2**96 3*(10**6) 1*(10**6) }; } my($m,$n,$r)=map {eval "use bignum;$_"}@ARGV; my $e=exp(xe($m-$n)+xe($m-$r)-xe($m)-xe($m-$n-$r)); printf "%3.5g %3.5g %3.5g\n",$e,1-$e,(1-"$e");

The bug is that the numbers printed in the last line don't make sense. Somehow, both $e and 1-$e print as "1", though 1-"$e" properly prints as "0". (The true value of $e should in fact be somewhere between 1-2**(-54) and 1)

When I use Data::Dumper, then $e is shown as '1' (note the quotes). However, that doesn't really help isolate the bug, as this also creates something that dumps as '1', but doesn't show the "both $e and 1-$e are 1" anomaly:

use bignum; $e = exp(2 ** (-128)); use Data::Dumper; print Dumper($e); print $e,"\n",1-$e,"\n";

My perl environment is perl 5.8.7 on cygwin.

--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/