The BigInt->new function takes decimal, hex, and binary in the usual Perl literal number syntax. But it doesn't take Octal—it treats a leading zero as nothing special and parses a decimal number.
Even the documentation for autocreating Big constants doesn't mention octal, so presumably those are left as normal scalars. But trying it, I find that
perl -MMath::BigInt=:constant -e"print 077"
and
perl -e"print 077"
produce different results! So that leads to a silent change in the program, which is not good.
The affect of autocreate-constant might be considered a bug at least in the docs, but that's not why I'm writing.
I'm pondering how to parse octal values, changing a program that just reads text from the user and converts to a number using $val = oct($val) if $val =~ /^0/;. Writing $val= new BigInt:: ($val); will handle decimal, binary, hex, but not octal.
My first idea is to detect the leading zero first and convert the octal string into a binary string using only string-based operations, one character at a time. Anybody got a better way?
—John
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.