Skip to content

Commit

Permalink
Moved math functions to be constexpr.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Nov 28, 2024
1 parent c8ff296 commit 7eace05
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 318 deletions.
3 changes: 3 additions & 0 deletions include/bx/bx.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ namespace bx
template<typename Ty>
constexpr bool isPowerOf2(Ty _a);

/// Returns true if it's evaluated as constexpr.
constexpr bool isConstantEvaluated();

/// Returns a value of type `Ty` by reinterpreting the object representation of `FromT`.
template <typename Ty, typename FromT>
constexpr Ty bitCast(const FromT& _from);
Expand Down
9 changes: 3 additions & 6 deletions include/bx/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ namespace bx
constexpr float kInvLogNat2 = 1.4426950408889634073599246810019f;

/// The natural logarithm of the 2. ln(2)
constexpr float kLogNat2Hi = 0.6931471805599453094172321214582f;

///
constexpr float kLogNat2Lo = 1.90821492927058770002e-10f;
constexpr float kLogNat2 = 0.6931471805599453094172321214582f;

/// The base of natural logarithms. e(1)
constexpr float kE = 2.7182818284590452353602874713527f;
Expand Down Expand Up @@ -83,7 +80,7 @@ namespace bx
/// Maximum representable floating-point number.
constexpr float kFloatLargest = 3.402823466e+38f;

///
/// Floating-point infinity.
// constexpr float kFloatInfinity;

///
Expand All @@ -104,7 +101,7 @@ namespace bx
/// Largest representable double-precision floating-point number.
constexpr double kDoubleLargest = 1.7976931348623158e+308;

//
// Double-precision floating-point infinity.
// constexpr double kDoubleInfinity;

} // namespace bx
Expand Down
5 changes: 5 additions & 0 deletions include/bx/inline/bx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ namespace bx
return _a && !(_a & (_a - 1) );
}

constexpr bool isConstantEvaluated()
{
return __builtin_is_constant_evaluated();
}

template <typename Ty, typename FromT>
inline constexpr Ty bitCast(const FromT& _from)
{
Expand Down
Loading

0 comments on commit 7eace05

Please sign in to comment.