From 0de0fa8ab8aaf08d1b39048504778eefea2a1e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Fri, 15 May 2020 08:50:10 -0700 Subject: [PATCH] Cleanup. --- include/bx/inline/math.inl | 19 +++++++------------ include/bx/math.h | 5 ++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index 5677e59..9afacc0 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -291,6 +291,11 @@ namespace bx return _a * _b + _c; } + inline BX_CONSTEXPR_FUNC float rcp(float _a) + { + return 1.0f / _a; + } + inline BX_CONST_FUNC float mod(float _a, float _b) { return _a - _b * floor(_a / _b); @@ -494,22 +499,12 @@ namespace bx inline BX_CONSTEXPR_FUNC Vec3 div(const Vec3 _a, const Vec3 _b) { - return - { - _a.x / _b.x, - _a.y / _b.y, - _a.z / _b.z, - }; + return mul(_a, rcp(_b) ); } inline BX_CONSTEXPR_FUNC Vec3 div(const Vec3 _a, float _b) { - return - { - _a.x / _b, - _a.y / _b, - _a.z / _b, - }; + return mul(_a, rcp(_b) ); } inline BX_CONSTEXPR_FUNC Vec3 mad(const Vec3 _a, const float _b, const Vec3 _c) diff --git a/include/bx/math.h b/include/bx/math.h index 4f3b7bb..4e39ad3 100644 --- a/include/bx/math.h +++ b/include/bx/math.h @@ -257,6 +257,9 @@ namespace bx /// BX_CONSTEXPR_FUNC float mad(float _a, float _b, float _c); + /// Returns reciprocal of _a. + BX_CONSTEXPR_FUNC float rcp(float _a); + /// Returns the floating-point remainder of the division operation _a/_b. /// BX_CONST_FUNC float mod(float _a, float _b); @@ -369,7 +372,7 @@ namespace bx /// BX_CONSTEXPR_FUNC Vec3 max(const Vec3 _a, const Vec3 _b); - /// + /// Returns component wise reciprocal of _a. BX_CONSTEXPR_FUNC Vec3 rcp(const Vec3 _a); ///