@@ -451,11 +451,12 @@ template <typename T, typename U>
451
451
PLAYRHO_CONSTEXPR inline auto Solve (const Matrix22<U> mat, const Vector2<T> b) noexcept
452
452
{
453
453
const auto cp = Cross (get<0 >(mat), get<1 >(mat));
454
+ const auto inverseCp = Real{1 } / cp;
454
455
using OutType = decltype ((U{} * T{}) / cp);
455
456
return (!AlmostZero (StripUnit (cp)))?
456
457
Vector2<OutType>{
457
- (get<1 >(mat)[1 ] * b[0 ] - get<1 >(mat)[0 ] * b[1 ]) / cp ,
458
- (get<0 >(mat)[0 ] * b[1 ] - get<0 >(mat)[1 ] * b[0 ]) / cp
458
+ (get<1 >(mat)[1 ] * b[0 ] - get<1 >(mat)[0 ] * b[1 ]) * inverseCp ,
459
+ (get<0 >(mat)[0 ] * b[1 ] - get<0 >(mat)[1 ] * b[0 ]) * inverseCp
459
460
}: Vector2<OutType>{};
460
461
}
461
462
@@ -465,10 +466,11 @@ PLAYRHO_CONSTEXPR inline auto Invert(const Matrix22<IN_TYPE> value) noexcept
465
466
{
466
467
const auto cp = Cross (get<0 >(value), get<1 >(value));
467
468
using OutType = decltype (get<0 >(value)[0 ] / cp);
469
+ const auto inverseCp = Real{1 } / cp;
468
470
return (!AlmostZero (StripUnit (cp)))?
469
471
Matrix22<OutType>{
470
- Vector2<OutType>{ get<1 >(get<1 >(value)) / cp , -get<1 >(get<0 >(value)) / cp },
471
- Vector2<OutType>{-get<0 >(get<1 >(value)) / cp , get<0 >(get<0 >(value)) / cp }
472
+ Vector2<OutType>{ get<1 >(get<1 >(value)) * inverseCp , -get<1 >(get<0 >(value)) * inverseCp },
473
+ Vector2<OutType>{-get<0 >(get<1 >(value)) * inverseCp , get<0 >(get<0 >(value)) * inverseCp }
472
474
}:
473
475
Matrix22<OutType>{};
474
476
}
@@ -478,7 +480,7 @@ PLAYRHO_CONSTEXPR inline auto Invert(const Matrix22<IN_TYPE> value) noexcept
478
480
PLAYRHO_CONSTEXPR inline Vec3 Solve33 (const Mat33& mat, const Vec3 b) noexcept
479
481
{
480
482
const auto dp = Dot (GetX (mat), Cross (GetY (mat), GetZ (mat)));
481
- const auto det = (dp != 0 )? 1 / dp: dp;
483
+ const auto det = (dp != 0 )? Real{ 1 } / dp: dp;
482
484
const auto x = det * Dot (b, Cross (GetY (mat), GetZ (mat)));
483
485
const auto y = det * Dot (GetX (mat), Cross (b, GetZ (mat)));
484
486
const auto z = det * Dot (GetX (mat), Cross (GetY (mat), b));
@@ -492,7 +494,7 @@ template <typename T>
492
494
PLAYRHO_CONSTEXPR inline T Solve22 (const Mat33& mat, const T b) noexcept
493
495
{
494
496
const auto cp = GetX (GetX (mat)) * GetY (GetY (mat)) - GetX (GetY (mat)) * GetY (GetX (mat));
495
- const auto det = (cp != 0 )? 1 / cp: cp;
497
+ const auto det = (cp != 0 )? Real{ 1 } / cp: cp;
496
498
const auto x = det * (GetY (GetY (mat)) * GetX (b) - GetX (GetY (mat)) * GetY (b));
497
499
const auto y = det * (GetX (GetX (mat)) * GetY (b) - GetY (GetX (mat)) * GetX (b));
498
500
return T{x, y};
@@ -623,7 +625,7 @@ inline Real Normalize(Vec2& vector)
623
625
const auto length = GetMagnitude (vector);
624
626
if (!AlmostZero (length))
625
627
{
626
- const auto invLength = 1 / length;
628
+ const auto invLength = Real{ 1 } / length;
627
629
vector[0 ] *= invLength;
628
630
vector[1 ] *= invLength;
629
631
return length;
@@ -734,7 +736,8 @@ PLAYRHO_CONSTEXPR inline Vector2<T> operator* (const UnitVec u, const T s) noexc
734
736
// / @brief Division operator.
735
737
PLAYRHO_CONSTEXPR inline Vec2 operator / (const UnitVec u, const UnitVec::value_type s) noexcept
736
738
{
737
- return Vec2{GetX (u) / s, GetY (u) / s};
739
+ const auto inverseS = Real{1 } / s;
740
+ return Vec2{GetX (u) * inverseS, GetY (u) * inverseS};
738
741
}
739
742
740
743
// / @brief Rotates a vector by a given angle.
0 commit comments