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
This commit is contained in:
Hein-Pieter van Braam
2017-02-14 04:10:02 +01:00
parent 81edda18f3
commit adcc211feb
9 changed files with 99 additions and 26 deletions

View File

@@ -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) );