40#ifndef GEOGRAM_BASIC_NUMERIC
41#define GEOGRAM_BASIC_NUMERIC
59#define M_PI 3.14159265358979323846
93 return Sign((a > b) - (a < b));
160 return std::numeric_limits<float32>::max();
177 return std::numeric_limits<float64>::max();
241 template <
class T,
bool is_numeric>
255 static const size_t size =
sizeof(T);
257 static const size_t numbits = 8 *
sizeof(T);
271 LimitsHelper<T, std::numeric_limits<T>::is_specialized> {
290 const T& a_num,
const T& a_denom,
const T& b_num,
const T& b_denom
292 if(a_denom == b_denom) {
296 geo_cmp(a_num*b_denom, b_num*a_denom) *
346 return std::numeric_limits<index_t>::max();
360 return std::numeric_limits<signed_index_t>::max();
367 return std::numeric_limits<signed_index_t>::min();
380 return ((x - floor(x)) > 0.5 ? ceil(x) : floor(x));
401 typedef typename std::is_arithmetic<T>::type type;
402 static constexpr bool value = std::is_arithmetic<T>::value;
419# define GEO_FP_CONTRACT_OFF(x)
420#elif defined(__clang__)
421# define GEO_FP_CONTRACT_OFF _Pragma("clang fp contract(off)")
422#elif defined(_MSC_VER)
423# define GEO_FP_CONTRACT_OFF _Pragma("fp_contract(off)")
424#elif defined(__GNUC__)
430struct GeoAssertNoFpContract {
431 GeoAssertNoFpContract() {
433 if(fp_contraction_enabled()) {
434 std::cerr <<
"Needs to be compiled with -ffp-contract-off"
442 static bool fp_contraction_enabled() {
443 return (a2plusb(0x1.0000002p0, -0x1.0000004p0) != 0.0);
445 __attribute__((noipa))
static double a2plusb(
double a,
double b) {
449# define GEO_FP_CONTRACT_OFF \
450 static GeoAssertNoFpContract CPP_CONCAT(assert_no_fp_contract_,__LINE__);
452# define GEO_FP_CONTRACT_OFF _Pragma("STDC FP_CONTRACT OFF")
unsigned char geo_coord_index_t
Represents dimension (e.g. 3 for 3d, 4 for 4d ...).
unsigned int geo_index_t
Represents indices.
int geo_signed_index_t
Represents possibly negative indices.
Assertion checking mechanism.
#define geo_assert(x)
Verifies that a condition is met.
Common include file, providing basic definitions. Should be included before anything else by all head...
constexpr float32 max_float32()
Gets 32 bits float maximum positive value.
constexpr float64 min_float64()
Gets 64 bits float minimum negative value.
float32 random_float32()
Returns a 32 bits float between 0 and 1.
Sign ratio_compare(const T &a_num, const T &a_denom, const T &b_num, const T &b_denom)
Compares two rational numbers given as separate numerators and denominators.
float64 random_float64()
Returns a 64 bits float between 0 and 1.
void optimize_number_representation(T &x)
place holder for optimizing internal number representation
constexpr float64 max_float64()
Gets 64 bits float maximum positive value.
void random_reset()
Resets the random number generator.
int32 random_int32()
Returns a 32 bits integer between 0 and RAND_MAX.
constexpr float32 min_float32()
Gets 32 bits float minimum negative value.
bool is_nan(float32 x)
Checks whether a 32 bits float is "not a number".
Global Vorpaline namespace.
signed_index_t min_signed_index_t()
Gets the minimum negative value of type signed_index_t.
T geo_sqr(T x)
Gets the square value of a value.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
geo_signed_index_t signed_index_t
The type for storing and manipulating indices differences.
constexpr signed_index_t max_signed_index_t()
Gets the maximum positive value of type signed_index_t.
void geo_clamp(T &x, T min, T max)
Clamps a value to a range.
Sign geo_sgn(const T &x)
Gets the sign of a value.
geo_index_t index_t
The type for storing and manipulating indices.
Sign
Integer constants that represent the sign of a value.
Sign geo_cmp(const T &a, const T &b)
Compares two values.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
constexpr index_t max_index_t()
Gets the maximum positive value of type index_t.
Limits helper class that extends std::numeric_limits.
Extends std::numeric_limits with additional information.