From 7fb36849c7a1a6384de13206b9096945ce02bec9 Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 3 Feb 2022 14:47:41 +0000 Subject: [PATCH] vector3d scalar operator/ and operator/= no longer multiply by the inverse but use the expected division. That was a bad case of premature optimization. Multiplication is indeed faster, but when working with floats this can introduce some rather unexpected inaccuracies. Like x/x suddenly no longer being 1.0 (something guaranteed by division). If someone really needs this back, then please add some new function which makes it clear we don't just have a typical division here. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6298 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 2 ++ include/vector3d.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changes.txt b/changes.txt index 6ee71071..7da17ee7 100644 --- a/changes.txt +++ b/changes.txt @@ -9,6 +9,8 @@ Changes in ogl-es (not yet released - will be merged with trunk at some point) -------------------------- Changes in 1.9 (not yet released) +- vector3d scalar operator/ and operator/= no longer multiply by the inverse but use the expected division. + Costs some speed, but fixes floating point troubles caused by this optimization (like x/x no longer being 1.0). - Add equals and set_data functions to core::array for easier working with blocks of data. - SIrrlichtCreationParameters::IgnoreInput set to false works again on X11. Thanks @ Victor Gaydov for report + patch + very good test cases! (bug #401) diff --git a/include/vector3d.h b/include/vector3d.h index 95325ef6..4dbc53b8 100644 --- a/include/vector3d.h +++ b/include/vector3d.h @@ -50,8 +50,8 @@ namespace core vector3d operator/(const vector3d& other) const { return vector3d(X / other.X, Y / other.Y, Z / other.Z); } vector3d& operator/=(const vector3d& other) { X/=other.X; Y/=other.Y; Z/=other.Z; return *this; } - vector3d operator/(const T v) const { T i=(T)1.0/v; return vector3d(X * i, Y * i, Z * i); } - vector3d& operator/=(const T v) { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; } + vector3d operator/(const T v) const { return vector3d(X/v, Y/v, Z/v); } + vector3d& operator/=(const T v) { X/=v; Y/=v; Z/=v; return *this; } T& operator [](u32 index) {