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: Wed, 11 Apr 2007 09:26:27 +0100
- Thread-topic: Range of 32 bit values
(various posts merged - sorry if that confuses...!)
> >These are the restriction that I have to deal with.
>
> Then I think your optimization trick just failed.
I'd tend to side with Greg G.
I don't think you can rely on float-wrapping to make this optimisation
work. AFAIK, neither the x86 or PPC hardware do this "naturally" - what
toolchain/compiler *did* this work with?
> >So my question remains as if there is a way to make the range of an
> >integer wrap after casting or if it's an operation entirely dependant
> >on hardware and the programmer has no control over it.
I'm fairly sure this is architecture specific - the only way out I know
of is to add a floating point excpetion handler to your code, that will
be triggered by any attempt to assign an out-of-range float value to an
integer.
Most of the time, this should not trigger, and you get the "ideal"
behaviour. When it does trigger, you can recover the failing value and
wrap it "by hand".
But this can be slow.
May still be faster than fmod() in most cases though. Fmod() can be
quite slow, since it is being careful and takes longer than it might
really need.
A simplified fmod-like function might be credibly fast, though?
> You could try dicing up the floating-point format by hand using
> integer instructions. The float format is 1:8:23, with a bias
> of 127,
> so you'd have something like this (which should handle denormal/
> infinity values as well, since you want them all to produce 0 output):
Although, if the OP is actually using doubles, that would need to be
reworked - and if it's lobg doubles, I think the PPC implementation and
the x86 implementation are really quite different...
Interesting idea though. I have a similar bit of code for generating
fast-logs based on the exponent and the first few bits of mantissa and
it is adequately accurate and much faster than the built-in log
functions...
--
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