• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible Correction in Cup Size?

 
Pete Johnston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new here and I am a new programmer, just learning, so please forgive my insolence. Unless I am mistaken (entirely possible), there seems to be a smidgen of an error in wording in the cup story, I quote:

"This gives you a range, for bytes, of :
(-2 to the 7th) through (2 to the 7th) -1. Why that little -1 on the end? Because zero is in there, and zero counts as negative. Works the same way with the others."

The range is correct however zero is non-negative thus the positive numbers of type byte go to the value (2 to the 7th) - 1. If zero counted as a negative then the minus one would be on that side, only you would add one instead of subtracting to reduce the range in that direction.

Well if I am confused let me know.

Thanks,

Pete
 
Campbell Ritchie
Sheriff
Posts: 48364
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Careful: "cup size" means something different in England. More suitable for Meaningless Drivel!!

I think you are correct, in which case two's complement numbers have exactly half their range negative and half their range non-negative.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Careful: "cup size" means something different in England. More suitable for Meaningless Drivel!!



I am glad I am not the only one who got confused with the terminology!
But to be honest I still cant figure out what this is about, the thread I mean.
 
Campbell Ritchie
Sheriff
Posts: 48364
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says it's for "very beginners" but with the title I think "adults only" would be better. Here.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I agree with you. they are talking about the range of the values - the max and min you can store - not the number of negative or positive values. Say you could only store 2^2 total values (per Polya, use a simpler case). One of them has to be 0. so, we'll go -2, -1, 0, and 1.

I have (2^1) - 1 as the max positive value, or 1.

I have 2^1 as the minimum negative value, -2.

As to HOW MANY positive and negative values I can store, THAT is a different question. if zero counts as negative, then indeed i see where your +1 comes from. we have 2^1 ACTUAL negative values, and then would need to add one more for zero. But that is not what they're talking about.
 
Pete Johnston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-2, -1, 0, and 1.


Yes, exactly. zero is counted with the non-negative numbers. That is precisely
my point
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess i don't understand what you mean by
If zero counted as a negative then the minus one would be on that side, only you would add one instead of subtracting to reduce the range in that direction.
 
Pete Johnston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, that wasn't very clear at all, sorry.
I meant if zero is counted as negative the range on that side would be shortened by one as opposed to shortening the positive side. (reminds me of a lullaby I heard as a little child)
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete,

I totally agree with you; I think the word "negative" should be "positive." If you look at Fred's example (-2, -1, 0, 1), it's very clear that there is one more negative value than there are truly positive values, and the reason for this is because one of the nominally positive values is taken up by zero.

In case it's not clear to everyone, we're talking about this JavaRanch Campfile Story.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having re-read this thread 20 or so times... i THINK i get what you're saying. But I think i'd probably phrase it like this:

"This gives you a range, for bytes, of :
(-2 to the 7th) through (2 to the 7th) -1. Why that little -1 on the end? Because zero is in there, and zero uses one spot that would otherwise be used for a positive. Works the same way with the others."

actually, i wouldn't phrase it that way... this is hard... no wonder i don't write books. how about this:

"This gives you a range, for bytes, of :
(-2 to the 7th) through (2 to the 7th) -1. Why that little -1 on the end? Because if exactly half are used for positive, and exactly half used for negative, there's no room for Zero!!! Someone decided that the positive side would make the sacrifice, so there is one less positive value available. I'm sure zero is very grateful (as are millions of coders all over the world"


that's not much better... But i need to get back to work.
 
Campbell Ritchie
Sheriff
Posts: 48364
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think my (non-joky) explanation is simpler: exactly half the values are negative (less than 0) and half are not negative (0 or more). I don't think 0 counts as negative or positive; it's just 0.
 
Campbell Ritchie
Sheriff
Posts: 48364
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pete Johnston:
(reminds me of a lullaby I heard as a little child)


They used to sing you lullabies about two's complement arithmetic?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
I still think my (non-joky) explanation is simpler: exactly half the values are negative (less than 0) and half are not negative (0 or more). I don't think 0 counts as negative or positive; it's just 0.


The term "non-negative" is often used to describe the range of numbers starting at zero.
 
Campbell Ritchie
Sheriff
Posts: 48364
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree, Ernest that non-negative would be better.
 
Pete Johnston
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:


They used to sing you lullabies about two's complement arithmetic?


Yes, it went like this:
"Mama's little baby likes shortnin' shortnin'..."

on another note, I am not receiving notice of updates to topics I am watching.
I have checked and I am correctly signed up to watch. I received the first couple on this thread then nothing more. I also don't think my emails are getting through to my nitpicker, oh well

Thanks to everyone for some stimulating thought.
zero is non-negative all agreed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic