mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-12-28 07:34:32 +00:00
Merge pull request #40 from miblodelcarpio/master
Introduce HMM_PowerF()
This commit is contained in:
@@ -77,19 +77,23 @@
|
||||
#define HMM_SINF MySinF
|
||||
#define HMM_COSF MyCosF
|
||||
#define HMM_TANF MyTanF
|
||||
#define HMM_EXPF MyExpF
|
||||
#define HMM_LOGF MyLogF
|
||||
|
||||
Provide your own implementations of SinF, CosF, and TanF
|
||||
Provide your own implementations of SinF, CosF, TanF, ExpF and LogF
|
||||
in EXACTLY one C or C++ file that includes this header, BEFORE the
|
||||
include, like this:
|
||||
|
||||
#define HMM_SINF MySinF
|
||||
#define HMM_COSF MyCosF
|
||||
#define HMM_TANF MyTanF
|
||||
#define HMM_EXPF MyExpF
|
||||
#define HMM_LOGF MyLogF
|
||||
#define HANDMADE_MATH_IMPLEMENTATION
|
||||
#define HANDMADE_MATH_CPP_MODE
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
If you do not define all three of these, HandmadeMath.h will use the
|
||||
If you do not define all five of these, HandmadeMath.h will use the
|
||||
versions of these functions that are provided by the CRT.
|
||||
|
||||
==========================================================================
|
||||
@@ -183,7 +187,8 @@ extern "C"
|
||||
#define HINLINE inline
|
||||
#endif
|
||||
|
||||
#if !defined(HMM_SINF) || !defined(HMM_COSF) || !defined(HMM_TANF)
|
||||
#if !defined(HMM_SINF) || !defined(HMM_COSF) || !defined(HMM_TANF) || \
|
||||
!defined(HMM_EXPF) || !defined(HMM_LOGF)
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
@@ -199,6 +204,14 @@ extern "C"
|
||||
#define HMM_TANF tanf
|
||||
#endif
|
||||
|
||||
#ifndef HMM_EXPF
|
||||
#define HMM_EXPF expf
|
||||
#endif
|
||||
|
||||
#ifndef HMM_LOGF
|
||||
#define HMM_LOGF logf
|
||||
#endif
|
||||
|
||||
#define HMM_PI32 3.14159265359f
|
||||
#define HMM_PI 3.14159265358979323846
|
||||
|
||||
@@ -338,6 +351,8 @@ typedef hmm_mat4 hmm_m4;
|
||||
HMMDEF float HMM_SinF(float Angle);
|
||||
HMMDEF float HMM_TanF(float Angle);
|
||||
HMMDEF float HMM_CosF(float Angle);
|
||||
HMMDEF float HMM_ExpF(float Float);
|
||||
HMMDEF float HMM_LogF(float Float);
|
||||
|
||||
HMMDEF float HMM_ToRadians(float Degrees);
|
||||
HMMDEF float HMM_SquareRootF(float Float);
|
||||
@@ -345,6 +360,7 @@ HMMDEF float HMM_RSquareRootF(float Float);
|
||||
HMMDEF float HMM_LengthSquared(hmm_vec3 A);
|
||||
HMMDEF float HMM_Length(hmm_vec3 A);
|
||||
HMMDEF float HMM_Power(float Base, int Exponent);
|
||||
HMMDEF float HMM_PowerF(float Base, float Exponent);
|
||||
HMMDEF float HMM_Lerp(float A, float Time, float B);
|
||||
HMMDEF float HMM_Clamp(float Min, float Value, float Max);
|
||||
|
||||
@@ -512,7 +528,7 @@ HMMDEF hmm_mat4 & operator/=(hmm_mat4 &Left, float Right);
|
||||
|
||||
#ifdef HANDMADE_MATH_IMPLEMENTATION
|
||||
|
||||
HINLINE float
|
||||
HINLINE float
|
||||
HMM_SinF(float Angle)
|
||||
{
|
||||
float Result = 0;
|
||||
@@ -521,7 +537,7 @@ HMM_SinF(float Angle)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HINLINE float
|
||||
HMM_CosF(float Angle)
|
||||
{
|
||||
float Result = 0;
|
||||
@@ -530,7 +546,7 @@ HMM_CosF(float Angle)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HINLINE float
|
||||
HMM_TanF(float Radians)
|
||||
{
|
||||
float Result = 0;
|
||||
@@ -539,7 +555,25 @@ HMM_TanF(float Radians)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HINLINE float
|
||||
HMM_ExpF(float Float)
|
||||
{
|
||||
float Result = 0;
|
||||
|
||||
Result = HMM_EXPF(Float);
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HMM_LogF(float Float)
|
||||
{
|
||||
float Result = 0;
|
||||
|
||||
Result = HMM_LOGF(Float);
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HMM_SquareRootF(float Value)
|
||||
{
|
||||
float Result = 0;
|
||||
@@ -643,6 +677,12 @@ HMM_Power(float Base, int Exponent)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HMM_PowerF(float Base, float Exponent)
|
||||
{
|
||||
return expf(Exponent * logf(Base));
|
||||
}
|
||||
|
||||
HINLINE float
|
||||
HMM_Lerp(float A, float Time, float B)
|
||||
{
|
||||
|
||||
@@ -57,6 +57,13 @@ TEST(ScalarMath, Power)
|
||||
EXPECT_FLOAT_EQ(HMM_Power(2.0f, -2), 0.25f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, PowerF)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, 0), 1.0f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, 4.1), 17.148376f, 0.0001f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, -2.5), 0.176777f, 0.0001f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Lerp)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.0f, 2.0f), -2.0f);
|
||||
|
||||
Reference in New Issue
Block a user