40#ifndef GEOGRAM_BASIC_NUMERIC
41#define GEOGRAM_BASIC_NUMERIC
45#include <geogram/basic/i387.h>
60#define M_PI 3.14159265358979323846
94 return Sign((a > b) - (a < b));
161 return std::numeric_limits<float32>::max();
178 return std::numeric_limits<float64>::max();
242 template <
class T,
bool is_numeric>
256 static const size_t size =
sizeof(T);
272 LimitsHelper<T, std::numeric_limits<T>::is_specialized> {
291 const T& a_num,
const T& a_denom,
const T& b_num,
const T& b_denom
293 if(a_denom == b_denom) {
297 geo_cmp(a_num*b_denom, b_num*a_denom) *
347 return std::numeric_limits<index_t>::max();
361 return std::numeric_limits<signed_index_t>::max();
368 return std::numeric_limits<signed_index_t>::min();
381 return ((x - floor(x)) > 0.5 ? ceil(x) : floor(x));
391 static constexpr index_t NO_INDEX =
index_t(-1);
402 typedef typename std::is_arithmetic<T>::type type;
403 static constexpr bool value = std::is_arithmetic<T>::value;
420# define GEO_FP_CONTRACT_OFF(x)
421#elif defined(__clang__)
422# define GEO_FP_CONTRACT_OFF _Pragma("clang fp contract(off)")
423#elif defined(_MSC_VER)
424# define GEO_FP_CONTRACT_OFF _Pragma("fp_contract(off)")
425#elif defined(__GNUC__)
434 struct GeoAssertStrictIEEE754 {
435 GeoAssertStrictIEEE754() {
437 geo_disable_387_extended_precision();
440 if(fp_contraction_enabled()) {
441 std::cerr <<
"Needs to be compiled with -ffp-contract-off "
442 <<
"(or no x87 extended precision)"
450 static bool fp_contraction_enabled() {
451 return (a2plusb(0x1.0000002p0, -0x1.0000004p0) != 0.0);
453 __attribute__((noipa))
static double a2plusb(
double a,
double b) {
459# define GEO_FP_CONTRACT_OFF \
460 static GeoAssertStrictIEEE754 CPP_CONCAT(assert_strict_ieee_754_,__LINE__);
462# define GEO_FP_CONTRACT_OFF _Pragma("STDC FP_CONTRACT OFF")
Assertion checking mechanism.
#define geo_assert(x)
Verifies that a condition is met.
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.
Common include file, providing basic definitions. Should be included before anything else by all head...
Defines numeric types used in Vorpaline.
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.
static const size_t numbits
Limits helper class that extends std::numeric_limits.
Extends std::numeric_limits with additional information.