Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On Tue, Dec 13, 2011 at 12:50:57AM -0500, Kohei Yoshida wrote:
On Tue, 2011-12-13 at 00:15 +0100, Markus Mohrhard wrote:

Any objections against this patch? I think that this fix should be
correct for all cases but it would be good if someone could have a
look at it.

Well, I'm not necessarily objecting, but I'm a bit puzzled.  I
would've thought that, if nExp < 0 is true, -nExp > 0 is
automatically true.

For a signed integer in twos complement, that is true, except for the
smallest representable (negative) number; it stems from the asymmetry
of the range.

In n bits, you can represent from -2^(n-1) to 2^(n-1)-1. Note how
-2^(n-1) is an outlier in the symmetry with respect to 0; (lambda
x.-x) (the function that takes x as an argument and returns -x, the
opposite of x) is effectively the symmetry with centre point 0. But
-(-2^(n-1)), that is 2^(n-1) is not representable. So it wraps around
back to -2^(n-1), like if you would add 1 to 2^(n-1)-1. And that's
actually exactly what happens.

See http://en.wikipedia.org/wiki/Two%27s_complement#The_most_negative_number

-- 
Lionel

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.