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
This commit is contained in:
cutealien 2022-02-03 14:47:41 +00:00
parent 42c0b17435
commit 57f518737d
3 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,7 @@
--------------------------
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).
- Bugfix: XML reader dropped last character in strings if there was a special character replacement for the second-last character.
- Avoid allocating more than 16k on stack in OCT loader. Also avoid potential heap overwrites in there.
- obj file loader now allows using mtl files with spaces in the filename.

View File

@ -54,8 +54,8 @@ namespace core
vector3d<T> operator/(const vector3d<T>& other) const { return vector3d<T>(X / other.X, Y / other.Y, Z / other.Z); }
vector3d<T>& operator/=(const vector3d<T>& other) { X/=other.X; Y/=other.Y; Z/=other.Z; return *this; }
vector3d<T> operator/(const T v) const { T i=(T)1.0/v; return vector3d<T>(X * i, Y * i, Z * i); }
vector3d<T>& operator/=(const T v) { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; }
vector3d<T> operator/(const T v) const { return vector3d<T>(X/v, Y/v, Z/v); }
vector3d<T>& operator/=(const T v) { X/=v; Y/=v; Z/=v; return *this; }
T& operator [](u32 index)
{

View File

@ -1,4 +1,4 @@
Tests finished. 72 tests of 72 passed.
Compiled as DEBUG
Test suite pass at GMT Sat Jan 22 16:40:25 2022
Test suite pass at GMT Thu Feb 03 14:40:09 2022