mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Better handling of nan/infinity. Previously, these weren't working on Windows in config strings.
This commit is contained in:
parent
cd79de19b2
commit
515f93a0b8
@ -365,12 +365,25 @@ cpow(int x, int y) {
|
|||||||
INLINE bool
|
INLINE bool
|
||||||
cnan(double v) {
|
cnan(double v) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
return (std::isnan(v) != 0);
|
return std::isnan(v);
|
||||||
#else
|
#else
|
||||||
return (_isnan(v) != 0);
|
return (_isnan(v) != 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: cinf
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE bool
|
||||||
|
cinf(double v) {
|
||||||
|
#ifndef _WIN32
|
||||||
|
return std::isinf(v);
|
||||||
|
#else
|
||||||
|
return (_isnan(v) == 0 && _finite(v) == 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: make_nan
|
// Function: make_nan
|
||||||
// Description:
|
// Description:
|
||||||
@ -380,7 +393,7 @@ make_nan(float) {
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
return nanf("");
|
return nanf("");
|
||||||
#else
|
#else
|
||||||
return numeric_limits<float>::quiet_NaN();
|
return std::numeric_limits<float>::quiet_NaN();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,10 +406,27 @@ make_nan(double) {
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
return nan("");
|
return nan("");
|
||||||
#else
|
#else
|
||||||
return numeric_limits<double>::quiet_NaN();
|
return std::numeric_limits<double>::quiet_NaN();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: make_inf
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE float
|
||||||
|
make_inf(float) {
|
||||||
|
return std::numeric_limits<float>::infinity();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: make_inf
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE double
|
||||||
|
make_inf(double) {
|
||||||
|
return std::numeric_limits<double>::infinity();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: cmod
|
// Function: cmod
|
||||||
|
@ -68,13 +68,17 @@ INLINE int cpow(int x, int y);
|
|||||||
// or infinity.
|
// or infinity.
|
||||||
INLINE bool cnan(double v);
|
INLINE bool cnan(double v);
|
||||||
|
|
||||||
// Returns NaN.
|
// Returns true if the number is infinity.
|
||||||
|
INLINE bool cinf(double v);
|
||||||
|
|
||||||
|
// Return NaN and infinity, respectively.
|
||||||
INLINE float make_nan(float);
|
INLINE float make_nan(float);
|
||||||
INLINE double make_nan(double);
|
INLINE double make_nan(double);
|
||||||
|
INLINE float make_inf(float);
|
||||||
|
INLINE double make_inf(double);
|
||||||
|
|
||||||
INLINE int cmod(int x, int y);
|
INLINE int cmod(int x, int y);
|
||||||
|
|
||||||
#include "cmath.I"
|
#include "cmath.I"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define strncasecmp _strnicmp
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: pstrtod
|
// Function: pstrtod
|
||||||
@ -45,11 +48,43 @@ pstrtod(const char *nptr, char **endptr) {
|
|||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
|
|
||||||
if (isalpha(*p)) {
|
if (isalpha(*p)) {
|
||||||
// For special cases like "inf" and "nan", pass these up to the
|
// Windows' implementation of strtod doesn't support "inf" or
|
||||||
// system implementation of strtod.
|
// "nan", so check for those here.
|
||||||
|
if (strncasecmp(p, "inf", 3) == 0) {
|
||||||
|
p += 3;
|
||||||
|
if (strncasecmp(p, "inity", 5) == 0) {
|
||||||
|
p += 5;
|
||||||
|
}
|
||||||
|
value = std::numeric_limits<double>::infinity();
|
||||||
|
|
||||||
|
} else if (strncasecmp(p, "nan", 3) == 0) {
|
||||||
|
p += 3;
|
||||||
|
|
||||||
|
if (*p == 's' || *p == 'S') {
|
||||||
|
value = std::numeric_limits<double>::signaling_NaN();
|
||||||
|
++p;
|
||||||
|
} else {
|
||||||
|
if (*p == 'q' || *p == 'Q') {
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
value = std::numeric_limits<double>::quiet_NaN();
|
||||||
|
}
|
||||||
|
|
||||||
|
// It is optionally possible to include a character sequence
|
||||||
|
// between parentheses after "nan", to be passed to the new
|
||||||
|
// nan() function. Since it isn't supported universally, we
|
||||||
|
// will only accept a pair of empty parentheses.
|
||||||
|
if (strncmp(p, "()", 2) == 0) {
|
||||||
|
p += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Pass it up to the system implementation of strtod;
|
||||||
|
// perhaps it knows how to deal with this string.
|
||||||
return strtod(nptr, endptr);
|
return strtod(nptr, endptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
// Start reading decimal digits to the left of the decimal point.
|
// Start reading decimal digits to the left of the decimal point.
|
||||||
bool found_digits = false;
|
bool found_digits = false;
|
||||||
while (isdigit(*p)) {
|
while (isdigit(*p)) {
|
||||||
@ -101,6 +136,7 @@ pstrtod(const char *nptr, char **endptr) {
|
|||||||
value *= pow(evalue, 10.0);
|
value *= pow(evalue, 10.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sign == '-') {
|
if (sign == '-') {
|
||||||
value = -value;
|
value = -value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user