Beloved Brethren and Sistren:

I am having a difficulty that is sorely trying me. I am trying to use the BigFloat module for various calculations. My code is thus:

#!/usr/bin/perl -w use warnings; use strict; use diagnostics; use Math::BigFloat; my $float=Math::BigFloat->new(2.0); $float->bsqrt(); print "\$float is a:\t" . ref($float) . "\n"; my $int = $float->as_int(); print "\$int is a:\t" .ref($int) . "\n"; print "\$float\t$float\n\$int:\t$int\n";

According to the documents, the as_int() method should return an BigInt value. However, as you can see from this output, it does not:

$float is a: Math::BigFloat $int is a: Math::BigFloat $float 1.41421356237309504880168872420969807857 $int: 1.41421356237309504880168872420969807857

The documentation for this module says:

$x->as_int(); # return $x as BigInt
What am I doing wrong? I assume I've made some assumption that isn't true, but I haven't been able to find anything in the documentation that explains this mysterious behavior. I cannot believe that this is a bug... any help would be appreciated. Thank you.

Update: Thanks, Zaxo. That worked beautifully...


In reply to Unexpected behavior of a method in BigFloat by spiritway

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.