From adcc211feb7827127b2548c791f2de0b6efda3d3 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Tue, 14 Feb 2017 04:10:02 +0100 Subject: Make nan==nan true for GDScript After discussing this with Reduz this seemed like the best way to fix #7354. This will make composite values that contain NaN in the same places as well as the same other values compare as the same. Additionally non-composite values now also compare equal if they are both NaN. This breaks IEEE specifications but this is probably what most users expect. There is a GDScript function check for NaN if the user needs this information. This fixes #7354 and probably also fixes #6947 --- core/math/math_2d.cpp | 7 +++++++ core/math/math_2d.h | 3 +++ core/math/plane.cpp | 5 +++++ core/math/plane.h | 1 + core/math/quat.cpp | 19 +++++++++++++++++++ core/math/quat.h | 2 +- core/math/vector3.cpp | 11 +++++++++++ core/math/vector3.h | 1 + 8 files changed, 48 insertions(+), 1 deletion(-) (limited to 'core/math') diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 76eeece688..995cb0834a 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -157,6 +157,13 @@ bool Vector2::operator!=(const Vector2& p_vec2) const { return x!=p_vec2.x || y!=p_vec2.y; } +bool Vector2::nan_equals(const Vector2& p_vec2) const { + + return (x==p_vec2.x && y==p_vec2.y) || + (x==p_vec2.x && isnan(y) && isnan(p_vec2.y)) || + (isnan(x) && isnan(p_vec2.x) && y == p_vec2.y); +} + Vector2 Vector2::floor() const { return Vector2( Math::floor(x), Math::floor(y) ); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index a24c4266ee..6dd8799ba2 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -133,6 +133,7 @@ struct Vector2 { bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y