Skip to content

Commit

Permalink
karm-math: Added floori, ceili, and roundi.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed May 6, 2024
1 parent eee3115 commit befdede
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/libs/karm-math/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ static constexpr bool isNegInf(f64 x) {

// MARK: Rounding + Remainder --------------------------------------------------

template <typename T>
constexpr isize floori(T x) {
if (x < 0)
return (long)(x - 1);

return (long)x;
}

template <typename T>
constexpr isize ceili(T x) {
if (x < 0)
return (long)x;

return (long)(x + 1);
}

template <typename T>
constexpr isize roundi(T x) {
return (long)(x + 0.5);
}

template <typename T>
constexpr T floor(T x) {
if (x < 0)
Expand All @@ -54,8 +75,9 @@ constexpr T ceil(T x) {
return (T)(long)(x + 1);
}

constexpr isize round(f64 x) {
return (isize)(x + 0.5);
template <typename T>
constexpr T round(T x) {
return (T)(long)(x + 0.5);
}

// MARK: Trigonometry ----------------------------------------------------------
Expand Down

0 comments on commit befdede

Please sign in to comment.