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# if __WORDSIZE == 64
14# define __INT64_C(c) c ## L
15# define __UINT64_C(c) c ## UL
16# else
17# define __INT64_C(c) c ## LL
18# define __UINT64_C(c) c ## ULL
19# endif
20
21#define _I8_MAX (127)
22#define _I16_MAX (32767)
23#define _I32_MAX (2147483647)
24#define _I64_MAX (__INT64_C(9223372036854775807))
25#define _UI8_MAX (255)
26#define _UI16_MAX (65535)
27#define _UI32_MAX (4294967295U)
28#define _UI64_MAX (__UINT64_C(18446744073709551615))
29#endif
30
31
32namespace cgv {
33 namespace type {
34 namespace traits {
37 template <typename T> struct max {};
38 template <> struct max<int8_type> { static const int8_type value = _I8_MAX; };
39 template <> struct max<int16_type> { static const int16_type value = _I16_MAX; };
40 template <> struct max<int32_type> { static const int32_type value = _I32_MAX; };
41 template <> struct max<int64_type> { static const int64_type value = _I64_MAX; };
42 template <> struct max<uint8_type> { static const uint8_type value = _UI8_MAX; };
43 template <> struct max<uint16_type> { static const uint16_type value = _UI16_MAX; };
44 template <> struct max<uint32_type> { static const uint32_type value = _UI32_MAX; };
45 template <> struct max<uint64_type> { static const uint64_type value = _UI64_MAX; };
46
49 template <typename T> struct max_fct { static T get_value() { return max<T>::value; } };
50 template <> struct max_fct<float> { static float get_value() { return FLT_MAX; } };
51 template <> struct max_fct<double> { static double get_value() { return DBL_MAX; } };
52 }
53 }
54}
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
the cgv namespace
Definition print.h:11
the max_fct traits provides a static function returning the maximal value of a type.
Definition max.h:49
the max traits defines for each type in the static const member value, what the maximum value is.
Definition max.h:37