You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input. The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
This commit is contained in:
@@ -74,11 +74,13 @@ public:
|
||||
static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); }
|
||||
static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); }
|
||||
|
||||
static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); }
|
||||
static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); }
|
||||
// Always does clamping so always safe to use.
|
||||
static _ALWAYS_INLINE_ double asin(double p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asin(p_x)); }
|
||||
static _ALWAYS_INLINE_ float asin(float p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asinf(p_x)); }
|
||||
|
||||
static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); }
|
||||
static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); }
|
||||
// Always does clamping so always safe to use.
|
||||
static _ALWAYS_INLINE_ double acos(double p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acos(p_x)); }
|
||||
static _ALWAYS_INLINE_ float acos(float p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acosf(p_x)); }
|
||||
|
||||
static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); }
|
||||
static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); }
|
||||
|
||||
Reference in New Issue
Block a user