瀏覽代碼

make_nan()

David Rose 12 年之前
父節點
當前提交
e0238675f3
共有 2 個文件被更改,包括 32 次插入1 次删除
  1. 26 0
      dtool/src/dtoolbase/cmath.I
  2. 6 1
      dtool/src/dtoolbase/cmath.h

+ 26 - 0
dtool/src/dtoolbase/cmath.I

@@ -349,6 +349,32 @@ cnan(double v) {
 #endif
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: make_nan
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE float
+make_nan(float) {
+#ifndef _WIN32
+  return nanf();
+#else
+  return numeric_limits<float>::quiet_NaN();
+#endif
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: make_nan
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE double 
+make_nan(double) {
+#ifndef _WIN32
+  return nan();
+#else
+  return numeric_limits<double>::quiet_NaN();
+#endif
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: cmod

+ 6 - 1
dtool/src/dtoolbase/cmath.h

@@ -29,6 +29,7 @@
 // name than everyone else.  Sheesh.
 #ifdef _WIN32
 #include <float.h>
+#include <limits>
 #endif
 
 INLINE float csqrt(float v);
@@ -61,10 +62,14 @@ INLINE double cacos(double v);
 INLINE double cmod(double x, double y);
 INLINE double cpow(double x, double y);
 
-// Returns true if the number is nan, false if it's a genuine number
+// Returns true if the number is NaN, false if it's a genuine number
 // or infinity.
 INLINE bool cnan(double v);
 
+// Returns NaN.
+INLINE float make_nan(float);
+INLINE double make_nan(double);
+
 INLINE int cmod(int x, int y);
 
 #include "cmath.I"