Dear Monks,
I'm not sure how I can understand the output I'm getting from the sample program below. Maybe (probably) something quite simple that I'm missing..
I need to calculate square roots with more than the standard precision so I'm using
use bignum. This works fine unless it is in a loop. Anybody care to explain?
use strict;
use warnings;
use Data::Dumper;
use bignum(a=>200);
my $s = sqrt(2);;
print Dumper(\$s);
for my $num (2..2) {
$s = sqrt($num);
print Dumper(\$s);
}
The output is:
$VAR1 = \bless( {
'_es' => '-',
'_m' => [
605715,
1152782,
9995050,
5927557,
5927505,
1322266,
9358314,
1497099,
1264412,
8507372,
4836055,
9702492,
2309122,
5013846,
4157273,
5343276,
8850387,
6210703,
7324784,
9737990,
7317667,
3769480,
9671875,
9807856,
7242096,
8801688,
7309504,
2135623,
1414
],
'_a' => 200,
'_e' => [
199
],
'sign' => '+'
}, 'Math::BigFloat' );
$VAR1 = \'1.4142135623731';
It looks as if the blessing of
$s is lost in the loop, but I don't understand why.
si_lence (confused)
Update: Thanks everybody for pointing out the reason and the suggestions. I did read the documentation, but obviously glossed over the important part.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.