]> git.lizzy.rs Git - irrlicht.git/commitdiff
vector3d scalar operator/ and operator/= no longer multiply by the inverse but use...
authorcutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>
Thu, 3 Feb 2022 14:47:41 +0000 (14:47 +0000)
committersfan5 <sfan5@live.de>
Wed, 9 Feb 2022 18:07:05 +0000 (19:07 +0100)
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
include/vector3d.h

index 6ee71071b1ccaee3597997f620073639f82378cc..7da17ee7fcc45eae1435d35e509c895259d12566 100644 (file)
@@ -9,6 +9,8 @@ Changes in ogl-es (not yet released - will be merged with trunk at some point)
 \r
 --------------------------\r
 Changes in 1.9 (not yet released)\r
+- vector3d scalar operator/ and operator/= no longer multiply by the inverse but use the expected division. \r
+  Costs some speed, but fixes floating point troubles caused by this optimization (like x/x no longer being 1.0).\r
 - Add equals and set_data functions to core::array for easier working with blocks of data.\r
 - SIrrlichtCreationParameters::IgnoreInput set to false works again on X11. \r
   Thanks @ Victor Gaydov for report + patch + very good test cases! (bug #401)\r
index 95325ef6722da3830cbb248dab2d21b47983bf6d..4dbc53b844df2249f96e482e442fe91a7843b451 100644 (file)
@@ -50,8 +50,8 @@ namespace core
 \r
                vector3d<T> operator/(const vector3d<T>& other) const { return vector3d<T>(X / other.X, Y / other.Y, Z / other.Z); }\r
                vector3d<T>& operator/=(const vector3d<T>& other) { X/=other.X; Y/=other.Y; Z/=other.Z; return *this; }\r
-               vector3d<T> operator/(const T v) const { T i=(T)1.0/v; return vector3d<T>(X * i, Y * i, Z * i); }\r
-               vector3d<T>& operator/=(const T v) { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; }\r
+               vector3d<T> operator/(const T v) const { return vector3d<T>(X/v, Y/v, Z/v); }\r
+               vector3d<T>& operator/=(const T v) { X/=v; Y/=v; Z/=v; return *this; }\r
 \r
                T& operator [](u32 index)\r
                {\r