RE: Range of 32 bit values
RE: Range of 32 bit values
- Subject: RE: Range of 32 bit values
- From: "MacArthur, Ian (SELEX) (UK)" <email@hidden>
- Date: Fri, 6 Apr 2007 11:51:52 +0100
- Thread-topic: Range of 32 bit values
> I just so happens that when the result of the multiplication
> exceed the
> size of the value that a 32 bit int type variable is able to represent
> the value is clipped to -2147483648.
This sort of behaviour is hardware specific... It is rarely safe to
depend on it happening in a particular way, as different architectures
*will* do different things...
I can't find where I hid my Intel manuals right now, but certainly for
the PPC, the behaviour is specified as being that the returned value
will be 0x8000000 if the input float value was large negative or NaN,
and 0x7FFFFFFF if the input float value was large positive.
(This assuming that FPSCR(VE) is not enabled - now I think of it I'm not
sure what OSX does with VE...)
In any case, there is no way to make the hardware wrap your float for
you.
I'm not sure, but I think the Intel implementation is *similar* - but
don't count on it being the same. (I'm fairly sure it is NOT exactly the
same...)
> In any case for the algorithm I am developing I would like the int
> value to be wrapped, not clipped. I would like after reaching the
> value's maximum limit to go back and start again from its minimum.
>
> Is there any flag I need to set in Xcode to achieve that or am I just
> unaware of programming rules ? I remember in Codewarrior values were
> always wrapped by default.
Really? I wonder how they achieved that? Perhaps the compiler intervened
on your behalf whenever you cast a float to an int and bound checked it
for you?
I suppose you could handle the VX exception case and implement an
exception handler that trapped the out-of-range cast and did the wrap
for you... Perhaps that is what Codewarrior did? I don't think the
Xcode/gcc code does that for you, however...
> Thanks for any help or suggestion.
Might I suggest you call fmod() before your cast?
--
Ian
SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden