[brlcad-commits] SF.net SVN: brlcad:[36402] brlcad/trunk/src/libbu/units.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2009-11-04 04:40:32
|
Revision: 36402 http://brlcad.svn.sourceforge.net/brlcad/?rev=36402&view=rev Author: brlcad Date: 2009-11-04 04:40:25 +0000 (Wed, 04 Nov 2009) Log Message: ----------- convert to near-zero testing instead of relying on == testing of potentially non-ieee floating point types. quell verbose compilation warnings. Modified Paths: -------------- brlcad/trunk/src/libbu/units.c Modified: brlcad/trunk/src/libbu/units.c =================================================================== --- brlcad/trunk/src/libbu/units.c 2009-11-04 04:32:29 UTC (rev 36401) +++ brlcad/trunk/src/libbu/units.c 2009-11-04 04:40:25 UTC (rev 36402) @@ -24,10 +24,15 @@ #include <stdio.h> #include <ctype.h> #include <string.h> +#include <float.h> #include "bu.h" +/* done specifically to avoid a libbn dependency */ +#define NEAR_ZERO(val, epsilon) (((val) > -epsilon) && ((val) < epsilon)) + + struct cvt_tab { double val; char name[32]; @@ -160,7 +165,7 @@ }; static const struct conv_table unit_lists[3] = { - bu_units_length_tab, bu_units_volume_tab, bu_units_mass_tab + {bu_units_length_tab}, {bu_units_volume_tab}, {bu_units_mass_tab} }; @@ -215,7 +220,7 @@ for (tp=bu_units_length_tab; tp->name[0]; tp++) { fastf_t diff, bigger; - if (mm == tp->val) + if (NEAR_ZERO(mm - tp->val, SMALL_FASTF)) return tp->name; /* Check for near-miss */ @@ -245,7 +250,7 @@ register const struct cvt_tab *tp; const char *nearest = NULL; - double nearer = 99.0e+99; + double nearer = DBL_MAX; if (mm <= 0) return (char *)NULL; @@ -255,11 +260,11 @@ double nearness; /* skip zero so we don't return 'none' */ - if (tp->val == 0.0) + if (NEAR_ZERO(tp->val, SMALL_FASTF)) continue; /* break early on perfect match */ - if (mm == tp->val) + if (NEAR_ZERO(mm - tp->val, SMALL_FASTF)) return tp->name; /* Check for nearness */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |