Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What is the best signed integer representation?

Name: Anonymous 2015-01-20 23:15

Sure, Two's Complement is nice and all because it increments easily, but that isn't enough to make it the definite best. For example, One's Complement and Sign and Magnitude both allow negative zero, so that's pretty neat. That would be great for error checking with sentinels. A function can return 0 or -0 for failure, both of which will evaluate to false in a logical statement, but -0 can be indicative of not just false, but failure. They both have the advantage of simplicity as well. Sign and Magnitude makes it very easy to see at a glance what the number is and is the closest to negative decimal values. One's Complement is also very easy because to negate the number, just NOT the number. Subtraction is thus reduced to a - b = a + ~b. The advantages of Excess-k are harder to see. So hard to see that I can't think of any. It just offsets. Seems useless and annoying. A less direct method could be using the unused values in a binary coded decimal to signify the sign, but you would still be using binary coded decimal. Gross.

Which do you prefer /prog/?

Name: Anonymous 2015-01-20 23:28

The returning -0 argument is pretty convincing.
That would certainly come in handy.

Name: Anonymous 2015-01-21 0:12

2 * N + sign

Name: Anonymous 2015-01-21 0:24

-0 does sound useful at first glance. However, 0 is the false value because all of its bits are set to zero; this cannot be the case with two distinct false values, making comparisons more expensive. Also, while subtraction is simplified, addition becomes more complex, which incurs further performance penalties because it is more common than negation.

I'm not sold yet.

Name: Anonymous 2015-01-21 2:54

I don't see why anyone would ever need negative numbers.

Name: Anonymous 2015-01-21 3:01

I don't see why anybody would ever need doubles (dubs) and floats.

Name: Anonymous 2015-01-21 7:48

sign bit | natural number

Name: Anonymous 2015-01-21 8:13

sentinel values? not unless the hardware traps on them like snan &c.

Name: Anonymous 2015-01-21 13:50

UTF-32 strings containing 32-bit characters of '0' and '1'

Name: Anonymous 2015-01-21 16:03

>>7
So sign and magnitude?

Name: Anonymous 2015-01-22 9:14

check em

Don't change these.
Name: Email:
Entire Thread Thread List