Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/X-ARTEMIS/ASTD/llms.txt

Use this file to discover all available pages before exploring further.

The astd/math/cppmath.hpp header provides three lightweight, template-based free functions for common mathematical operations. Because every function accepts const auto parameters, they work with any numeric type that supports the required operators — no explicit template instantiation is needed.
#include "astd/math/math.hpp"
// or via the umbrella header:
#include "astd/astd.hpp"

power

Raises a base value to a non-negative integer exponent using iterative multiplication.
auto power(const auto base, const auto exponent);
When exponent is zero or negative, power short-circuits and returns 1 immediately, regardless of the value of base. This matches the mathematical convention that any number raised to the power of zero equals one.

Parameters

base
auto
required
The base value to be raised. Accepts any numeric type that supports *=.
exponent
auto
required
The exponent to raise base to. Values less than or equal to 0 cause the function to return 1 immediately.

Return value

result
int
The value of base raised to exponent. Returns 1 when exponent <= 0.

Example

#include "astd/math/math.hpp"
#include <iostream>

int main() {
    std::cout << power(2, 10)  << '\n'; // 1024
    std::cout << power(3, 4)   << '\n'; // 81
    std::cout << power(5, 0)   << '\n'; // 1  (exponent <= 0 guard)
    std::cout << power(7, -2)  << '\n'; // 1  (exponent <= 0 guard)
}

square

Returns the square of a value by multiplying it by itself.
auto square(const auto base);
Prefer square over power(x, 2) for squaring — it avoids the loop overhead entirely and lets the compiler inline a single multiplication.

Parameters

base
auto
required
The value to square. Accepts any type that supports the binary * operator.

Return value

result
auto
The product of base * base, preserving the operand’s type.

Example

#include "astd/math/math.hpp"
#include <iostream>

int main() {
    std::cout << square(4)    << '\n'; // 16
    std::cout << square(3.5)  << '\n'; // 12.25
    std::cout << square(-7)   << '\n'; // 49
}

getNumType

Determines whether a number is even or odd.
bool getNumType(const auto num);
The function returns true for even numbers and false for odd numbers. This convention might feel counter-intuitive — consider wrapping the result in a named boolean if call-site clarity matters.

Parameters

num
auto
required
The integer value to inspect. Accepts any integral type that supports the % (modulo) operator.

Return value

isEven
bool
true if num is even (num % 2 == 0), false if num is odd.

Example

#include "astd/math/math.hpp"
#include <iostream>

int main() {
    bool fourIsEven = getNumType(4);   // true
    bool nineIsEven = getNumType(9);   // false

    std::cout << std::boolalpha;
    std::cout << "4 is even: " << fourIsEven << '\n'; // true
    std::cout << "9 is even: " << nineIsEven << '\n'; // false

    // Useful in a condition:
    int value{ 42 };
    if (getNumType(value)) {
        std::cout << value << " is even\n";
    }
}

Build docs developers (and LLMs) love