Re: My Bits are Flipping (or, "Why Can't I Be Negative?")

new topic     » goto parent     » topic index » view thread      » older message » newer message

Travis Beaty wrote:

> Well, actually, that's the problem.  The value will be positive if the mouse
> is *in* the widget, but will become negative if it crosses past the left or
> top edge.

And what is the problem? Andy wrote about signed values. "signed" does
not mean, that the concerning values only can be negative. "signed"
values can be negative or positive.

<snip>

> Mr. Craig, any possibility of putting the ability to detect signed values from
> external libraries on the last-minute 2.5 wishlist?  Or the first minute 2.6
> one?

There is no possibility to "detect" signed values from external
libraries at all. Only some bits are passed from external libraries to
Euphoria. Human beings (or software written by them) have to _decide_,
what a certain "collection of bits" should _mean_. By their "nature",
those values are neither signed nor unsigned.

Obviously in the past Rob had decided to _treat_ those values as
unsigned. When future versions of Euphoria would treat those values as
signed, this would not be backward compatible, so this is not
recommendable.
Converting unsigned values to signed values, or vice versa, using
functions like those that were posted here, is quite normal in
programming. Besides, the suggested functions are small and fast.

Since after my experience there are often problems in understanding
this point, I'll explain it more in detail. Because it's simpler, just
let's look at 8 bit rather than 32 bit.

One byte (= 8 bit) can hold 2^8 = 256 differnt values, that's a
technical fact. If we _interpret_ the bits in a byte in a way, that the
most significant bit acts as the "sign" bit, then a byte can hold any
value in the closed interval [-128, 127].
The reason why negative values for a byte might look somewhat unfamiliar
simply is, that the most widespread _convention_ concerning bytes is,
not to interpret the most significant bit as the "sign" bit. So a byte
normally is treated as an unsigned value in the closed interval [0, 255].

> Thanks everyone for your help!!
>
> Travis.
>
>
> On Friday 27 August 2004 07:04 pm, Andy Serpa wrote:
>> It is not the difference between negative & positive per se -- it is the
>> difference between signed & unsigned values.  The library either returns
>> signed or unsigned values.  If it returns signed values, then you convert
>> them.  There is no danger to it, and no guessing, unless you don't know
>> what the library is supposed to be giving you.

[snipped garbage]

Hope this helps.

Regards,
   Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu