[Algorithms] Fast Floating-Point compares?
Brought to you by:
vexxed72
From: Stuart H. <stu...@ku...> - 2003-08-15 17:02:04
|
This may be slightly off-topic, if so, I apologise in advance. Floating point compares, that is, doing something like: float x, y; x =3D some_value; y =3D different_value; if (x > y) do_something(); else do_something_else(); .seem to be particularly slow on most architectures. Short of avoiding the problem entirely (i.e. not using floats) - are there any tricks for improving the performance of floating point compares? I know of the trick of testing the "sign" bit (assuming IEEE compliance) to do: if (x > 0.0f) ... .tests, and by rearranging terms slightly you can generalise this to any constant: if (x > 12.3f) ... becomes: if ((x - 12.3f) > 0.0f) ... . meaning you can then test the sign of (x - 12.3f). However, there don't appear to be similar tricks for two variables, unless: if (x > y) ... . can be sped up by simply testing the sign of (x - y). But that sounds too simple to be true... -Dino. Information contained in this e-mail is intended for the use of the = addressee only, and is confidential and may be the subject of Legal = Professional Privilege. Any dissemination, distribution, copying or use = of this communication without prior permission of the addressee is = strictly prohibited.The views of the author may not necessarily = constitute the views of Kuju Entertainment Ltd. Nothing in this email = shall bind Kuju Entertainment Ltd in any contract or obligation. The contents of an attachment to this e-mail may contain software = viruses which could damage your own computer system. While Kuju = Entertainment has taken every reasonable precaution to minimise this = risk, we cannot accept liability for any damage which you sustain as a = result of software viruses. You should carry out your own virus checks = before opening the attachment. |