Boost logo

Boost :

Subject: Re: [boost] New Boost.XInt Library, request preliminary review
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2010-04-06 16:11:02


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>> To me, the key question is whether the signed 0 shows through the
>> interface. I would consider it a mistake if it did so. Besides any
>> "purity" arguments, doing so would eliminate the option of using some
>> otherwise plausible internal representation, such as 2s-complement [...]
>
> Good point. Do you have any references to such packages? I'm curious
> about the implementation advantages and disadvantages of using
> 2s-complement vs sign+magnitude.

I tried it with the first large-integer library I developed, many years
ago. As I recall, it made addition and subtraction slightly easier to
implement, but multiplication and division were slightly harder, as were
any more-advanced functions that needed to access the internals of the
number (like exponentiation).

It was slightly more efficient storage-wise to use 2s-complement, you
could just allocate an array instead of having to have a struct *and* an
array. (Though if that's all you're after, you could do the same thing
with sign+magnitude, if you're willing to engage in some pointer
trickery.) It was slightly less efficient for processing, because for
anything other than addition and subtraction, you had to remove the sign
bit, then calculate, then re-add the sign bit.

Overall there wasn't much difference. I prefer sign+magnitude because
it's easier to write readable code that way.
- --
Chad Nelson
Oak Circle Software, Inc.
*
*
*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAku7lVYACgkQp9x9jeZ9/wRq9QCeNLESN3qXOlHgEhKVFLdhnSn4
Pw4An3SxilFV4IPNaskDGz7HHNZW48P9
=60mH
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk