Revision: 41402
http://brlcad.svn.sourceforge.net/brlcad/?rev=41402&view=rev
Author: brlcad
Date: 2010-11-18 15:17:43 +0000 (Thu, 18 Nov 2010)
Log Message:
-----------
check for c89 float.h constants and use those instead of calculating epsilon if
the constants are available. also added method that does not assume ieee754
but it may find a smaller epsilon than ieee specifies.
Modified Paths:
--------------
brlcad/trunk/src/libbn/ulp.c
Modified: brlcad/trunk/src/libbn/ulp.c
===================================================================
--- brlcad/trunk/src/libbn/ulp.c 2010-11-17 23:10:22 UTC (rev 41401)
+++ brlcad/trunk/src/libbn/ulp.c 2010-11-18 15:17:43 UTC (rev 41402)
@@ -35,22 +35,46 @@
* representation.
*/
+#include "common.h"
+#include <float.h>
+
+
double
bn_epsilon()
{
+#if defined(DBL_EPSILON)
+ return DBL_EPSILON;
+#elif defined(HAVE_IEEE754)
static const double val = 1.0;
register long long next = *(long long*)&val + 1;
return val - *(double *)&next;
+#else
+ /* must be volatile to avoid long registers */
+ volatile double tol = 1.0;
+ while (1.0 + (tol * 0.5) != 1.0) {
+ tol *= 0.5;
+ }
+#endif
}
-double
+float
bn_epsilonf()
{
+#if defined(FLT_EPSILON)
+ return FLT_EPSILON;
+#elif defined(HAVE_IEEE754)
static const float val = 1.0;
register long next = *(long*)&val + 1;
return val - *(float *)&next;
+#else
+ /* must be volatile to avoid long registers */
+ volatile float tol = 1.0f;
+ while (1.0f + (tol * 0.5f) != 1.0f) {
+ tol *= 0.5f;
+ }
+#endif
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits