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@/

In reply to Help me make a test case for Math::BigFloat by fizbin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.