IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8113


Ignore:
Timestamp:
Aug 3, 2006, 4:16:58 PM (20 years ago)
Author:
jhoblitt
Message:

add basically floating point epsilon support for psF32 & psF64s

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/db/psDB.c

    r8112 r8113  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-08-04 02:01:56 $
     14 *  @version $Revision: 1.75 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-08-04 02:16:58 $
    1616 *
    1717 *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
     
    2323#include <stdarg.h>
    2424#include <string.h>
     25#include <float.h>
    2526#undef __STRICT_ANSI__
    2627#include <stdlib.h>
     
    15811582
    15821583    // stringify the psMetadataItem into a SQL search specification
     1584    // XXX we're making a big assumption here that the MySQL server handles
     1585    // floating point in the exact same way as the client.  This is a bit scary
     1586    // as MySQL uses native types on the server end.  In theory all IEEE754
     1587    // math is the same but know that isn't always the case.  At least forcing
     1588    // the comparison to be done on the server provides some consistency
     1589    // between clients on different archs.
    15831590    if ((item->type == PS_DATA_S32) || (item->type == PS_TYPE_S32)) {
    15841591        psStringAppend(&query, "%s=%d", item->name, (int)(item->data.S32));
    15851592    } else if ((item->type == PS_DATA_F32) || (item->type == PS_TYPE_F32)) {
    1586         psStringAppend(&query, "%s=%g", item->name, (double)(item->data.F32));
     1593        psStringAppend(&query, "ABS(%s - %d) < %f.6", item->name, (int)(item->data.S32), FLT_EPSILON);
    15871594    } else if ((item->type == PS_DATA_F64) || (item->type == PS_TYPE_F64)) {
    1588         psStringAppend(&query, "%s=%g", item->name, (double)(item->data.F64));
     1595        psStringAppend(&query, "ABS(%s - %d) < %f.10", item->name, (int)(item->data.S32), DBL_EPSILON);
    15891596    } else if ((item->type == PS_DATA_BOOL) || (item->type == PS_TYPE_BOOL)) {
    15901597        psStringAppend(&query, "%s=%d", item->name, (int)(item->data.B));
Note: See TracChangeset for help on using the changeset viewer.