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

@ -284,3 +284,22 @@ Quat::Quat(const Vector3& axis, const real_t& angle) {
cos_angle);
}
}
bool Quat::nan_equals(const Quat& q2) const {
return (x == q2.x && y == q2.y && z == q2.z && w == q2.w) ||
(x == q2.x && y == q2.y && z == q2.z && isnan(w) && isnan(q2.w)) ||
(x == q2.x && y == q2.y && isnan(z) && isnan(q2.z) && w == q2.w) ||
(x == q2.x && y == q2.y && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) ||
(x == q2.x && isnan(y) && isnan(q2.y) && z == q2.z && w == q2.w) ||
(x == q2.x && isnan(y) && isnan(q2.y) && z == q2.z && isnan(w) && isnan(q2.w)) ||
(x == q2.x && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && w == q2.w) ||
(x == q2.x && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) ||
(isnan(x) && isnan(q2.x) && y == q2.y && z == q2.z && w == q2.w) ||
(isnan(x) && isnan(q2.x) && y == q2.y && z == q2.z && isnan(w) && isnan(q2.w)) ||
(isnan(x) && isnan(q2.x) && y == q2.y && isnan(z) && isnan(q2.z) && w == q2.w) ||
(isnan(x) && isnan(q2.x) && y == q2.y && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) ||
(isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && z == q2.z && w == q2.w) ||
(isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && z == q2.z && isnan(w) && isnan(q2.w)) ||
(isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && w == q2.w) ||
(isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w));
}