Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Math::Base - arithmetics with baseX integers

by shmem (Chancellor)
on Aug 22, 2017 at 16:02 UTC ( #1197814=note: print w/replies, xml ) Need Help??

in reply to Re: Math::Base - arithmetics with baseX integers
in thread Math::Base - arithmetics with baseX integers (updated)

This is one of the reasons why I wrote Far from complete (besides missing pod, tests, you name it.)

The perl builtins suffer from negative integer flaws also. The format %x of sprintf expects a signed an unsigned integer, but nonetheless

say $f = sprintf "%x", -15; say hex $f; __END__ fffffffffffffff1 18446744073709551601

on a 64bit system. The object could get a sign flag set by the constructor which is honored by arithmetic operations, but the string representation would be ambiguous anyways if the string has a leading dash.

I'm not sure what to do about that. Perhaps limiting to unsigned integers is the way to go, and encode should croak if the number is negative; don't know yet.

update: unsigned, yes, that's the point; common typo. It is coerced into an unsigned. Thanks Anonymous Monk fo pointing out the glitch.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^3: Math::Base - arithmetics with baseX integers
by no_slogan (Deacon) on Aug 22, 2017 at 16:15 UTC
    %x is clearly documented as taking an unsigned int in the page you link to.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1197814]
[marto]: I really should have stayed in bed today
[choroba]: exceptions to this rule are rare

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-03-20 10:44 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (250 votes). Check out past polls.