John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
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
andperl -MMath::BigInt=:constant -e"print 077"
produce different results! So that leads to a silent change in the program, which is not good.perl -e"print 077"
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BigInt and octal input
by ysth (Canon) on Feb 04, 2004 at 19:22 UTC | |
|
Re: BigInt and octal input
by hardburn (Abbot) on Feb 04, 2004 at 17:59 UTC |