Switch to unordered floating point compares.
In particular, this gives us desired behavior for NaNs (all compares involving a NaN evaluate to true). This in turn allows writing the canonical isnan() function as "v != v". Added isnan() to the standard library as well.
This commit is contained in:
20
stdlib.ispc
20
stdlib.ispc
@@ -1120,6 +1120,26 @@ static inline uniform int64 clock() {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Floating-Point Math
|
||||
|
||||
__declspec(safe,cost1)
|
||||
static inline uniform bool isnan(uniform float v) {
|
||||
return v != v;
|
||||
}
|
||||
|
||||
__declspec(safe,cost1)
|
||||
static inline bool isnan(float v) {
|
||||
return v != v;
|
||||
}
|
||||
|
||||
__declspec(safe,cost1)
|
||||
static inline uniform bool isnan(uniform double v) {
|
||||
return v != v;
|
||||
}
|
||||
|
||||
__declspec(safe,cost1)
|
||||
static inline bool isnan(double v) {
|
||||
return v != v;
|
||||
}
|
||||
|
||||
__declspec(safe,cost1)
|
||||
static inline float abs(float a) {
|
||||
// Floating-point hack: zeroing the high bit clears the sign
|
||||
|
||||
Reference in New Issue
Block a user