cgv
Loading...
Searching...
No Matches
max.h
1#pragma once
2
3#include <cgv/type/standard_types.h>
4#include <climits>
5#include <float.h>
6
7// FIXME: We should really take the standards compilant way which is
8// to use INT8_MAX,... instead of _I8_MAX and add compatibility definitions
9// for MSVC instead the other way around...
10// FIXME: Can't we just use std::numeric_limits?
11#ifndef _MSC_VER
12// FIXME: better use stdint.h
13
14// Explicit redefinition to avoid compiler warnings.
15#undef __INT64_C
16#undef __UINT64_C
17
18# if __WORDSIZE == 64
19# define __INT64_C(c) c ## L
20# define __UINT64_C(c) c ## UL
21# else
22# define __INT64_C(c) c ## LL
23# define __UINT64_C(c) c ## ULL
24# endif
25
26#define _I8_MAX (127)
27#define _I16_MAX (32767)
28#define _I32_MAX (2147483647)
29#define _I64_MAX (__INT64_C(9223372036854775807))
30#define _UI8_MAX (255)
31#define _UI16_MAX (65535)
32#define _UI32_MAX (4294967295U)
33#define _UI64_MAX (__UINT64_C(18446744073709551615))
34#endif
35
36
37namespace cgv {
38 namespace type {
39 namespace traits {
42 template <typename T> struct max {};
43 template <> struct max<int8_type> { static const int8_type value = _I8_MAX; };
44 template <> struct max<int16_type> { static const int16_type value = _I16_MAX; };
45 template <> struct max<int32_type> { static const int32_type value = _I32_MAX; };
46 template <> struct max<int64_type> { static const int64_type value = _I64_MAX; };
47 template <> struct max<uint8_type> { static const uint8_type value = _UI8_MAX; };
48 template <> struct max<uint16_type> { static const uint16_type value = _UI16_MAX; };
49 template <> struct max<uint32_type> { static const uint32_type value = _UI32_MAX; };
50 template <> struct max<uint64_type> { static const uint64_type value = _UI64_MAX; };
51
54 template <typename T> struct max_fct { static T get_value() { return max<T>::value; } };
55 template <> struct max_fct<float> { static float get_value() { return FLT_MAX; } };
56 template <> struct max_fct<double> { static double get_value() { return DBL_MAX; } };
57 }
58 }
59}
signed char int8_type
this type provides an 8 bit signed integer type
int int32_type
this type provides an 32 bit signed integer type
short int16_type
this type provides an 16 bit signed integer type
unsigned short uint16_type
this type provides an 16 bit unsigned integer type
unsigned long long uint64_type
this type provides an 64 bit unsigned integer type
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
long long int64_type
this type provides an 64 bit signed integer type
unsigned char uint8_type
this type provides an 8 bit unsigned integer type
this header is dependency free
Definition print.h:11
the max_fct traits provides a static function returning the maximal value of a type.
Definition max.h:54
the max traits defines for each type in the static const member value, what the maximum value is.
Definition max.h:42