Skip to content

Commit

Permalink
Move math stuff into /Math
Browse files Browse the repository at this point in the history
  • Loading branch information
a740g committed Sep 11, 2024
1 parent f21661f commit 6add142
Show file tree
Hide file tree
Showing 15 changed files with 629 additions and 330 deletions.
2 changes: 1 addition & 1 deletion AudioAnalyzer.bi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $INCLUDEONCE
'$INCLUDE:'Types.bi'
'$INCLUDE:'PointerOps.bi'
'$INCLUDE:'BitwiseOps.bi'
'$INCLUDE:'MathOps.bi'
'$INCLUDE:'Math/Math.bi'
'$INCLUDE:'StringOps.bi'
'$INCLUDE:'GraphicOps.bi'
'$INCLUDE:'AudioAnalyzerFFT.bi'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Circle2D.h → Math/Circle2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
struct Circle2D
{
Vector2D position;
int32_t radius;
float radius;
};
4 changes: 1 addition & 3 deletions Easings.bi → Math/Easings.bi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

$INCLUDEONCE

'$INCLUDE:'Common.bi'

DECLARE LIBRARY "external/reasings"
DECLARE LIBRARY "reasings"
FUNCTION EaseBackIn! (BYVAL t AS SINGLE, BYVAL b AS SINGLE, BYVAL c AS SINGLE, BYVAL d AS SINGLE)
FUNCTION EaseBackInOut! (BYVAL t AS SINGLE, BYVAL b AS SINGLE, BYVAL c AS SINGLE, BYVAL d AS SINGLE)
FUNCTION EaseBackOut! (BYVAL t AS SINGLE, BYVAL b AS SINGLE, BYVAL c AS SINGLE, BYVAL d AS SINGLE)
Expand Down
File renamed without changes.
34 changes: 17 additions & 17 deletions MathOps.bi → Math/Math.bi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$INCLUDEONCE

'$INCLUDE:'Common.bi'
'$INCLUDE:'../Common.bi'

'-----------------------------------------------------------------------------------------------------------------------
' TEST CODE
Expand All @@ -28,10 +28,10 @@ $INCLUDEONCE
'END
'-----------------------------------------------------------------------------------------------------------------------

DECLARE LIBRARY "MathOps"
DECLARE LIBRARY "Math"
SUB Math_SetRandomSeed (BYVAL seed AS _UNSIGNED LONG)
FUNCTION Math_GetRandomMax~&
FUNCTION Math_GetRandomValue& ALIAS "rand"
FUNCTION Math_GetRandomValue& ALIAS "std::rand"
FUNCTION Math_GetRandomBetween& (BYVAL lo AS LONG, BYVAL hi AS LONG)
FUNCTION Math_IsSingleNaN! (BYVAL n AS SINGLE)
FUNCTION Math_IsDoubleNaN# (BYVAL n AS DOUBLE)
Expand All @@ -55,10 +55,10 @@ DECLARE LIBRARY "MathOps"
FUNCTION Math_RemapInteger64&& (BYVAL value AS _INTEGER64, BYVAL oldMin AS _INTEGER64, BYVAL oldMax AS _INTEGER64, BYVAL newMin AS _INTEGER64, BYVAL newMax AS _INTEGER64)
FUNCTION Math_RemapSingle! (BYVAL value AS SINGLE, BYVAL oldMin AS SINGLE, BYVAL oldMax AS SINGLE, BYVAL newMin AS SINGLE, BYVAL newMax AS SINGLE)
FUNCTION Math_RemapDouble# (BYVAL value AS DOUBLE, BYVAL oldMin AS DOUBLE, BYVAL oldMax AS DOUBLE, BYVAL newMin AS DOUBLE, BYVAL newMax AS DOUBLE)
FUNCTION Math_GetMaxSingle! ALIAS "fmaxf" (BYVAL a AS SINGLE, BYVAL b AS SINGLE)
FUNCTION Math_GetMinSingle! ALIAS "fminf" (BYVAL a AS SINGLE, BYVAL b AS SINGLE)
FUNCTION Math_GetMaxDouble# ALIAS "fmax" (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE)
FUNCTION Math_GetMinDouble# ALIAS "fmin" (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE)
FUNCTION Math_GetMaxSingle! ALIAS "std::fmax" (BYVAL a AS SINGLE, BYVAL b AS SINGLE)
FUNCTION Math_GetMinSingle! ALIAS "std::fmin" (BYVAL a AS SINGLE, BYVAL b AS SINGLE)
FUNCTION Math_GetMaxDouble# ALIAS "std::fmax" (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE)
FUNCTION Math_GetMinDouble# ALIAS "std::fmin" (BYVAL a AS DOUBLE, BYVAL b AS DOUBLE)
FUNCTION Math_GetMaxLong& (BYVAL a AS LONG, BYVAL b AS LONG)
FUNCTION Math_GetMinLong& (BYVAL a AS LONG, BYVAL b AS LONG)
FUNCTION Math_GetMaxInteger64&& (BYVAL a AS _INTEGER64, BYVAL b AS _INTEGER64)
Expand All @@ -71,19 +71,19 @@ DECLARE LIBRARY "MathOps"
FUNCTION Math_WrapDouble# (BYVAL value AS DOUBLE, BYVAL startValue AS DOUBLE, BYVAL endValue AS DOUBLE)
FUNCTION Math_IsSingleEqual%% (BYVAL x AS SINGLE, BYVAL y AS SINGLE)
FUNCTION Math_IsDoubleEqual%% (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE)
FUNCTION Math_FMASingle! ALIAS "fmaf" (BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE)
FUNCTION Math_FMADouble# ALIAS "fma" (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE, BYVAL z AS DOUBLE)
FUNCTION Math_PowerSingle! ALIAS "powf" (BYVAL b AS SINGLE, BYVAL e AS SINGLE)
FUNCTION Math_PowerDouble# ALIAS "pow" (BYVAL b AS DOUBLE, BYVAL e AS DOUBLE)
FUNCTION Math_FMASingle! ALIAS "std::fma" (BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE)
FUNCTION Math_FMADouble# ALIAS "std::fma" (BYVAL x AS DOUBLE, BYVAL y AS DOUBLE, BYVAL z AS DOUBLE)
FUNCTION Math_PowerSingle! ALIAS "std::pow" (BYVAL b AS SINGLE, BYVAL e AS SINGLE)
FUNCTION Math_PowerDouble# ALIAS "std::pow" (BYVAL b AS DOUBLE, BYVAL e AS DOUBLE)
FUNCTION Math_FastPowerSingle! ALIAS "__builtin_powif" (BYVAL b AS SINGLE, BYVAL e AS LONG)
FUNCTION Math_FastPowerDouble# ALIAS "__builtin_powi" (BYVAL b AS DOUBLE, BYVAL e AS LONG)
FUNCTION Math_FastSquareRoot! (BYVAL n AS SINGLE)
FUNCTION Math_FastInverseSquareRoot! (BYVAL n AS SINGLE)
FUNCTION Math_Log10Single! ALIAS "log10f" (BYVAL n AS SINGLE)
FUNCTION Math_Log10Double# ALIAS "log10" (BYVAL n AS DOUBLE)
FUNCTION Math_Log2Single! ALIAS "log2f" (BYVAL n AS SINGLE)
FUNCTION Math_Log2Double# ALIAS "log2" (BYVAL n AS DOUBLE)
FUNCTION Math_CubeRootSingle! ALIAS "cbrtf" (BYVAL n AS SINGLE)
FUNCTION Math_CubeRootDouble# ALIAS "cbrt" (BYVAL n AS DOUBLE)
FUNCTION Math_Log10Single! ALIAS "std::log10" (BYVAL n AS SINGLE)
FUNCTION Math_Log10Double# ALIAS "std::log10" (BYVAL n AS DOUBLE)
FUNCTION Math_Log2Single! ALIAS "std::log2" (BYVAL n AS SINGLE)
FUNCTION Math_Log2Double# ALIAS "std::log2" (BYVAL n AS DOUBLE)
FUNCTION Math_CubeRootSingle! ALIAS "std::cbrt" (BYVAL n AS SINGLE)
FUNCTION Math_CubeRootDouble# ALIAS "std::cbrt" (BYVAL n AS DOUBLE)
FUNCTION Math_MulDiv (BYVAL v AS LONG, BYVAL m AS LONG, BYVAL d AS LONG)
END DECLARE
14 changes: 7 additions & 7 deletions MathOps.h → Math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include "Types.h"
#include "../Types.h"
#include <cstdint>
#include <cfloat>
#include <cstdlib>
Expand Down Expand Up @@ -35,7 +35,7 @@ extern void sub_randomize(double seed, int32_t passed); // QB64's random seed fu
/// @param seed Any number
inline void Math_SetRandomSeed(uint32_t seed)
{
srand(seed);
std::srand(seed);
sub_randomize(seed, 1);
}

Expand All @@ -45,7 +45,7 @@ inline void Math_SetRandomSeed(uint32_t seed)
/// @return A number between lo and hi
inline int32_t Math_GetRandomBetween(int32_t lo, int32_t hi)
{
return lo + rand() % (hi - lo + 1);
return lo + std::rand() % (hi - lo + 1);
}

/// @brief Determines if the given floating point number arg is a not-a-number (NaN) value
Expand Down Expand Up @@ -316,7 +316,7 @@ inline constexpr double Math_NormalizeDouble(double value, double start, double
/// @return The wrapped value
inline float Math_WrapSingle(float value, float min, float max)
{
return value - (max - min) * floorf((value - min) / (max - min));
return value - (max - min) * std::floor((value - min) / (max - min));
}

/// @brief Wrap input value from min to max
Expand All @@ -326,7 +326,7 @@ inline float Math_WrapSingle(float value, float min, float max)
/// @return The wrapped value
inline double Math_WrapDouble(double value, double min, double max)
{
return value - (max - min) * floor((value - min) / (max - min));
return value - (max - min) * std::floor((value - min) / (max - min));
}

/// @brief Check whether two given floats are almost equal
Expand All @@ -335,7 +335,7 @@ inline double Math_WrapDouble(double value, double min, double max)
/// @return True if both are almost equal
inline qb_bool Math_IsSingleEqual(float x, float y)
{
return TO_QB_BOOL(fabsf(x - y) <= FLT_EPSILON * fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y))));
return TO_QB_BOOL(std::fabs(x - y) <= FLT_EPSILON * std::fmax(1.0f, std::fmax(std::fabs(x), std::fabs(y))));
}

/// @brief Check whether two given floats are almost equal
Expand All @@ -344,7 +344,7 @@ inline qb_bool Math_IsSingleEqual(float x, float y)
/// @return True if both are almost equal
inline qb_bool Math_IsDoubleEqual(double x, double y)
{
return TO_QB_BOOL(fabs(x - y) <= DBL_EPSILON * fmax(1.0, fmax(fabs(x), fabs(y))));
return TO_QB_BOOL(std::fabs(x - y) <= DBL_EPSILON * std::fmax(1.0, std::fmax(std::fabs(x), std::fabs(y))));
}

/// @brief This one comes from https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Approximations_that_depend_on_the_floating_point_representation
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6add142

Please sign in to comment.