Although that seems to be completely untrendy for this thread, I'll try to stay on topic... ;)
>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...
Why not? Testing a float by an integer cast (the sign bit trick) works for testing against zero.
Since x>y <=> x-y>0, you can substract x-y and test against zero. Works ok, as long as you stay away
from NANs, denormals etc. Also, if you care what happens in the == case, you might need to perform
some more complicated test, because of the possibility of negative zero.
HTH,
Alen
----- Original Message -----
From: "Stuart Harrison" <stu...@ku...>
To: <gda...@li...>
Sent: Friday, August 15, 2003 4:14 PM
Subject: [Algorithms] Fast Floating-Point compares?
This may be slightly off-topic, if so, I apologise in advance.
Floating point compares, that is, doing something like:
float x, y;
x = some_value;
y = 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.
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
GDAlgorithms-list mailing list
GDA...@li...
https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_ida88
|