Started work on database handling.

This commit is contained in:
2024-04-08 03:10:24 -07:00
parent 405acb026f
commit beba947c69
22 changed files with 918 additions and 44 deletions

View File

@@ -101,29 +101,73 @@ namespace ehs
return from * 57.295779513082320876798154814105;
}
template <typename T = float>
static T Exp(const T x)
{
T sum = 1;
T term = 1;
for (int n = 1; n <= 20; ++n)
{
term *= x / n;
sum += term;
}
return sum;
}
template <typename T = float>
static T Ln(T x)
{
if (x <= 0)
return -1;
T result = 0;
x = (x - 1) / (x + 1);
for (int i = 1; i <= 19; i += 2)
result += (1 / i) * Exp<T>(x * i);
return 2 * result;
}
/// A method for use of exponents.
/// @tparam T The data type to return;
/// @tparam I The data type to use as the exponent.
/// @param [in] from The value to use the exponent on.
/// @param [in] of The exponent.
/// @returns The result.
template<typename T = float, typename I = UInt_64>
static T Pow(const T from, const I of)
template<typename T = float, typename I = float>
static T Pow(const T base, const I exponent)
{
if (of < 0)
{
if (from == 0)
return -0;
if (base == 0)
return 0;
return 1 / (from * Pow<T>(from, (-of) - 1));
}
if (exponent == 0)
return 1;
if (of == 0)
return 1;
else if (of == 1)
return from;
UInt_32 exponentIsInteger = exponent == (UInt_32)exponent;
UInt_32 baseIsNegative = base < 0;
return from * Pow<T>(from, of - 1);
if (baseIsNegative && exponentIsInteger)
{
T result = Exp<T>(exponent * Ln<T>(-base));
if (Mod((float)exponent, 2.0f) != 0)
result = -result;
return result;
}
else if (!baseIsNegative)
return Exp<T>(exponent * Ln<T>(base));
return 0;
}
template <typename T = float>
static T Log10(const T x)
{
return Ln<T>(x) / Ln<T>(10);
}
static float Near(const float from);