off-by-one error
It seems you've hit some precision limit - which is avoided if you use bigint.
Try placing an extra number at the beginning of $x, and you'll soon see what I mean.
For every extra number you prepend to the start of $x, you get an extra "0" at the end of $y:
use strict;
use warnings;
use feature 'say';
use bignum;#num;
# (1) #use bignum downgrade => "Math::BigInt", upgrade => "Math::BigI
+nt";
## (2) #use bigint;
say $^V;
my $x = 999999999921778071482940061661655974875633165533182;
say $x;
my $y = $x / 2;
say $y;
__END__
For me, outputs:
D:\pscrpt>perl try.pl
v5.39.5
999999999921778071482940061661655974875633165533182
499999999960889035741470030830827987437800000000000
Cheers, Rob
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.
|
|