Revision: 41118
http://brlcad.svn.sourceforge.net/brlcad/?rev=41118&view=rev
Author: brlcad
Date: 2010-10-21 05:49:51 +0000 (Thu, 21 Oct 2010)
Log Message:
-----------
add an initial ulp.c implementation to provide a variety of routines useful for
comparing numbers. this is completely preliminary and needs a variety of
changes so don't even enable the file for compilation. for now, it implements
ulp() and a variety of run-time variants of the float.h constants
([flt|dbl]_[min|max] and [epsilon|epsilonf]).
Modified Paths:
--------------
brlcad/trunk/src/libbn/Makefile.am
Added Paths:
-----------
brlcad/trunk/src/libbn/ulp.c
Modified: brlcad/trunk/src/libbn/Makefile.am
===================================================================
--- brlcad/trunk/src/libbn/Makefile.am 2010-10-21 05:12:36 UTC (rev 41117)
+++ brlcad/trunk/src/libbn/Makefile.am 2010-10-21 05:49:51 UTC (rev 41118)
@@ -47,6 +47,7 @@
EXTRA_DIST = \
$(man_MANS) \
+ ulp.c \
CMakeLists.txt
DEPENDS = src/libbu
Added: brlcad/trunk/src/libbn/ulp.c
===================================================================
--- brlcad/trunk/src/libbn/ulp.c (rev 0)
+++ brlcad/trunk/src/libbn/ulp.c 2010-10-21 05:49:51 UTC (rev 41118)
@@ -0,0 +1,114 @@
+/* U L P . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2010 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file ulp.c
+ *
+ * Routines useful for performing comparisons and dynamically
+ * calculating floating point limits including the Unit in the Last
+ * Place (ULP).
+ *
+ * In this context, ULP is the distance to the next normalized
+ * floating point value larger that a given input value.
+ *
+ * TODO: handle NaN, +-Inf, underflow, overflow, non-IEEE, float.h
+ *
+ * This file is completely in flux, incomplete, limited, and subject
+ * to drastic changes. Do NOT use it for anything.
+ */
+
+
+double
+bn_epsilon()
+{
+ static const double val = 1.0;
+ register long long next = *(long long*)&val + 1;
+ return val - *(double *)&next;
+}
+
+
+double
+bn_epsilonf()
+{
+ static const float val = 1.0;
+ register long next = *(long*)&val + 1;
+ return val - *(float *)&next;
+}
+
+
+double
+bn_dbl_min()
+{
+ register long long val = (1LL<<52);
+ return *(double *)&val;
+}
+
+
+double
+bn_dbl_max()
+{
+ static const double val = INFINITY;
+ register long long next = *(long long*)&val - 1;
+ return *(double *)&next;
+}
+
+
+double
+bn_flt_min()
+{
+ register long val = (1LL<<23);
+ return *(float *)&val;
+}
+
+
+double
+bn_flt_max()
+{
+ static const float val = INFINITY;
+ register long next = *(long*)&val - 1;
+ return *(float *)&next;
+}
+
+
+double
+bn_ulp(double val)
+{
+ double next;
+ register long long up, dn, idx;
+
+ if (isnan(val) || !isfinite(val))
+ return val;
+
+ if (val >=0) {
+ up = *(long long*)&val + 1;
+ return *(double *)&up - val;
+ }
+ dn = *(long long*)&val - 1;
+ return *(double *)&dn - val;
+}
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbn/ulp.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits