فهرست منبع

Added signum convenience function.

Daniel Buckmaster 12 سال پیش
والد
کامیت
ce24c28b8f
2فایلهای تغییر یافته به همراه12 افزوده شده و 0 حذف شده
  1. 7 0
      engine/source/math/mConsoleFunctions.cc
  2. 5 0
      engine/source/math/mMathFn.h

+ 7 - 0
engine/source/math/mConsoleFunctions.cc

@@ -115,6 +115,13 @@ ConsoleFunction( mAbs, F32, 2, 2, "( val ) Use the mAbs function to get the magn
    return(mFabs(dAtof(argv[1])));
 }
 
+ConsoleFunction( mSign, F32, 2, 2, "( val ) Use the mSign function to get the signum of a number.\n"
+                                                                "@param val An integer or a floating-point value.\n"
+                                                                "@return Returns +1 if the number is >= 0, or -1 if it's < 0")
+{
+   return(mFsign(dAtof(argv[1])));
+}
+
 ConsoleFunction( mSqrt, F32, 2, 2, "( val ) Use the mSqrt function to calculated the square root of val.\n"
                                                                 "@param val A numeric value.\n"
                                                                 "@return Returns the the squareroot of val")

+ 5 - 0
engine/source/math/mMathFn.h

@@ -325,6 +325,11 @@ inline F32 mFabs(const F32 val)
    return (F32) fabs(val);
 }
 
+inline F32 mFsign(const F32 val)
+{
+   return (F32) (val >= 0 ? 1 : -1);
+}
+
 inline F32 mFmod(const F32 val, const F32 mod)
 {
    return (F32) fmod(val, mod);