Branimir Karadžić 7 年之前
父节点
当前提交
257316ab01
共有 3 个文件被更改,包括 22 次插入24 次删除
  1. 19 3
      include/bx/inline/math.inl
  2. 3 5
      include/bx/math.h
  3. 0 16
      src/math.cpp

+ 19 - 3
include/bx/inline/math.inl

@@ -95,16 +95,32 @@ namespace bx
 		return tmp == UINT64_C(0x7ff0000000000000);
 	}
 
-	inline BX_CONST_FUNC float round(float _f)
+	inline BX_CONSTEXPR_FUNC float floor(float _a)
 	{
-		return floor(_f + 0.5f);
+		if (_a < 0.0f)
+		{
+			const float fr = fract(-_a);
+			const float result = -_a - fr;
+
+			return -(0.0f != fr
+				? result + 1.0f
+				: result)
+				;
+		}
+
+		return _a - fract(_a);
 	}
 
-	inline BX_CONST_FUNC float ceil(float _a)
+	inline BX_CONSTEXPR_FUNC float ceil(float _a)
 	{
 		return -floor(-_a);
 	}
 
+	inline BX_CONSTEXPR_FUNC float round(float _f)
+	{
+		return floor(_f + 0.5f);
+	}
+
 	inline BX_CONSTEXPR_FUNC float lerp(float _a, float _b, float _t)
 	{
 		return _a + (_b - _a) * _t;

+ 3 - 5
include/bx/math.h

@@ -3,8 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-// FPU math lib
-
 #ifndef BX_MATH_H_HEADER_GUARD
 #define BX_MATH_H_HEADER_GUARD
 
@@ -112,15 +110,15 @@ namespace bx
 
 	/// Returns the largest integer value not greater than _f.
 	///
-	BX_CONST_FUNC float floor(float _f);
+	BX_CONSTEXPR_FUNC float floor(float _f);
 
 	/// Returns the smallest integer value not less than _f.
 	///
-	BX_CONST_FUNC float ceil(float _f);
+	BX_CONSTEXPR_FUNC float ceil(float _f);
 
 	/// Returns the nearest integer value to _f, rounding halfway cases away from zero,
 	///
-	BX_CONST_FUNC float round(float _f);
+	BX_CONSTEXPR_FUNC float round(float _f);
 
 	/// Returns linear interpolation between two values _a and _b.
 	///

+ 0 - 16
src/math.cpp

@@ -239,22 +239,6 @@ namespace bx
 		return result;
 	}
 
-	BX_CONST_FUNC float floor(float _a)
-	{
-		if (_a < 0.0f)
-		{
-			const float fr = fract(-_a);
-			const float result = -_a - fr;
-
-			return -(0.0f != fr
-				? result + 1.0f
-				: result)
-				;
-		}
-
-		return _a - fract(_a);
-	}
-
 	static void mtxLookAtImpl(float* _result, const Vec3& _eye, const Vec3& _view, const Vec3& _up)
 	{
 		const Vec3 uxv   = cross(_up, _view);