Closed p5pRT closed 12 years ago
perl -wle 'print 2 ** 3333' inf perl -wle 'print 2 ** 3333 == 2 ** 3333' 1 perl -wle 'print oct(2 ** 3333)' 0 perl -wle 'print hex(2 ** 3333)' Illegal hexadecimal digit 'i' ignored at -e line 1. 0
This effects BigInt and friends\, since oct() and hex() seem not to be overloadable:
perl -Mbignum -wle 'print oct(inf)' 0 perl -Mbignum -wle 'print hex(inf)' Illegal hexadecimal digit 'i' ignored at -e line 1. 0
Compare to:
perl -Mbignum -wle 'print inf->as_hex()' inf perl -Mbignum -wle 'print inf->as_bin()' inf
In addition\, oct() and hex() seem not to be able to handle negative numbers at all. That should either be documented or fixed (preferable to me):
perl -wle 'print hex("-12")'
Illegal hexadecimal digit '-' ignored at -e line 1.
0
perl -wle 'print oct("-12")'
0
perl -wle 'print oct(-12)'
0
perl -wle 'print oct(-02)'
0
perl -wle 'print -2 ** 3333'
-inf
perl -wle 'print oct(-2 ** 3333)'
0
perl -wle 'print hex(-2 ** 3333)'
Illegal hexadecimal digit '-' ignored at -e line 1.
0
Note: rand() gets it right:
perl -wle 'print rand(2 ** 3333)' inf perl -wle 'print rand(-2 ** 3333)' -inf perl -wle 'print rand(-1)' -0.174723732358874
Reed Wilson says: "A number\, chosen uniformly between 0 and inf\, has no chance of being finite".
Best wishes\,
Tels
On Sun\, Dec 12\, 2004 at 02:23:23PM -0000\, Tels wrote:
perl \-wle 'print 2 \*\* 3333' inf perl \-wle 'print 2 \*\* 3333 == 2 \*\* 3333' 1 perl \-wle 'print oct\(2 \*\* 3333\)' 0 perl \-wle 'print hex\(2 \*\* 3333\)' Illegal hexadecimal digit 'i' ignored at \-e line 1\. 0
I'm a little confused as to what you want; oct and hex take octal and hex *strings* and return the equivalent number. There shouldn't be any need to accept an Inf *number* and return Inf.
The RT System itself - Status changed from 'new' to 'open'
-----BEGIN PGP SIGNED MESSAGE-----
Moin\,
Yitzchak wrote:
On Sun\, Dec 12\, 2004 at 02:23:23PM -0000\, Tels wrote:
perl \-wle 'print 2 \*\* 3333' inf perl \-wle 'print 2 \*\* 3333 == 2 \*\* 3333' 1 perl \-wle 'print oct\(2 \*\* 3333\)' 0 perl \-wle 'print hex\(2 \*\* 3333\)' Illegal hexadecimal digit 'i' ignored at \-e line 1\. 0
I'm a little confused as to what you want; oct and hex take octal and hex *strings* and return the equivalent number. There shouldn't be any need to accept an Inf *number* and return Inf.
You are of course right about the strings. However\, hex() and oct() take happily *numbers*\, too\, but they convert them first to their string form:
perl -wle 'print hex(123)' 291 perl -wle 'print oct(123)' 83
Plus and minus infinity are just a numbers. Granted\, they are special numbers\, but numbers still. And their *string form* is 'inf'\, '+inf' or '-inf'\, respectively. And since it is the same form in all bases\, their *hexadecimal string form* is 'inf'\, '-inf'\, and '+inf' respectively. (One could argue that '0xinf' should also be valid\, but I think that is a bit silly. Hm\, maybe not.)
So\, IMHO hex() and oct() should deal with the strings 'inf'\, '+inf' and 'inf'.
Likewise\, minus 0x123 should be "-0x123" and therefore "-0x123" should be a valid hex string\, and therefore IMHO hex() should be able to deal with it.
One might argue that Perl's hex()/oct() should not be changed. However\, at least under bignum they _should_ be able to deal with these kinds of inputs. (bignum is all about enhancing the math support for long numbers\, inf\, NaN etc).
AFAIK hex()/oct() are _not_ overloadable\, though\, so BigInt can't fix these things easily. That might be worth a second bug report. If people think I should file one\, just says so :) Just watch:
perl -Mbignum -le 'print hex( 123456789012345678->as_hex() )' Integer overflow in hexadecimal number at -e line 1. 1.23456789012346e+17
Best wishes\,
Tels
- -- Signed on Sun Dec 19 13:33:39 2004 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email.
"Where shall I put you? Under H\, like Hot\, Sexy Mama?"
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux)
iQEVAwUBQcV19HcLPEOTuEwVAQFGKwf/S68gVUNxTm29ZaYHzWmNtPEq6iB9o0Mf hwMy2m51yjf+TsLPiALAmicYpElCsZQkjU3TXbCBjVuQZfiQzWxWJzuiKdrInVA/ rMlP013ZQHrEyaTHjm7wZ96L/hFtN5vw7E7UuAxO7XqDhVOxSekYzeoqH6Ns4Yul my04CfiSMYdMfsh7SyDTHGDrKC7GpiXaWopGOqvCNn4rhbvIvrt5337hCjH/33pP y9ys4EZvKBGxjmk4m0QxA3chkzqQb1YbQULr2jCwjIkLHJVXlhgugOO3kryXpMtO 0/hWFWIFgyaQKJP5gpunUWO39Vtqfpx6GjIX/Wlw4jwp6pAz9x7NVA== =Q9ot -----END PGP SIGNATURE-----
On Sun\, Dec 19\, 2004 at 01:37:00PM +0100\, Tels wrote:
You are of course right about the strings. However\, hex() and oct() take happily *numbers*\, too\, but they convert them first to their string form:
perl \-wle 'print hex\(123\)' 291 perl \-wle 'print oct\(123\)' 83
Plus and minus infinity are just a numbers. Granted\, they are special numbers\, but numbers still. And their *string form* is 'inf'\, '+inf' or '-inf'\, respectively. And since it is the same form in all bases\, their *hexadecimal string form* is 'inf'\, '-inf'\, and '+inf' respectively. (One could argue that '0xinf' should also be valid\, but I think that is a bit silly. Hm\, maybe not.)
So\, IMHO hex() and oct() should deal with the strings 'inf'\, '+inf' and 'inf'.
What about:
$ perl -wle '$a=1e70; $b = "$a"; $c = hex $a; print $b; print $c' Illegal hexadecimal digit '+' ignored at -e line 1. 1e+70 30
hex() doesn't handle arbitrary stringifications of numbers\, it just handles strings containing 0-9\,a-f or thereabouts. I don't see why inf should be special-cased.
-- Wesley Crusher gets beaten up by his classmates for being a smarmy git\, and consequently has a go at making some friends of his own age for a change. -- Things That Never Happen in "Star Trek" #18
@cpansprout - Status changed from 'open' to 'rejected'
Migrated from rt.perl.org#33013 (status was 'rejected')
Searchable as RT33013$