Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Inexact floating-point compare



[EMAIL PROTECTED] wrote:
Terje Mathisen <[EMAIL PROTECTED]> wrote:
: : The easiest method would seem to be a subtract, scale, add and compare:
: : double inexact_compare(double a, double b, int bits_to_skip)
: {
: // First the the regular difference:
: double diff = b - a;
: : // Shift this difference down by the number of bits to ignore:
: double scaled_diff = diff / ((double) (2 << bits_to_skip));
:


This does not work for floating point..... or am I missing something obvious?

Well, it does work (modulo having a shift which is smaller than the bitsoze of an integer), but the casting to double of the integer shift result is pretty non-optimal, as is the fp division that follows.


As I wrote in my post, this was only for illustration, a useful implementation would either use a fp scale operation or a lookup table to generate a suitable shifting multiplier.

Terje

--
- <[EMAIL PROTECTED]>
"almost all programming can be viewed as an exercise in caching"




<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.