YARP
Yet Another Robot Platform
numeric.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_CONFIG_NUMERIC_H
10 #define YARP_CONFIG_NUMERIC_H
11 
12 #define YARP_HAS_SYS_TYPES_H
13 
14 #if defined(YARP_HAS_SYS_TYPES_H)
15 # include <sys/types.h>
16 #endif
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <cfloat>
21 #include <cinttypes>
22 #if defined (_MSC_VER)
23 # include <BaseTsd.h>
24 #endif
25 
26 /* #undef YARP_BIG_ENDIAN */
27 #define YARP_LITTLE_ENDIAN
28 
29 #define YARP_HAS_FLOAT128_T
30 #define YARP_FLOAT32_IS_IEC559 1
31 #define YARP_FLOAT64_IS_IEC559 1
32 #define YARP_FLOAT128_IS_IEC559 1
33 
34 // Ensure that float32_t, float64_t, and float128_t are not defined by some
35 // other header, included before this one.
36 #if defined(float32_t)
37 # undef float32_t
38 #endif
39 #if defined(float64_t)
40 # undef float64_t
41 #endif
42 #if defined(float128_t)
43 # undef float128_t
44 #endif
45 
46 
47 namespace yarp {
48 namespace conf {
49 
50 typedef float float32_t;
51 typedef double float64_t;
52 typedef std::int32_t vocab32_t;
53 #if defined(YARP_HAS_FLOAT128_T)
54 typedef long double float128_t;
55 #endif
56 
57 #if defined (_MSC_VER)
58 typedef ::SSIZE_T ssize_t;
59 #else
61 #endif
62 
63 // Define `clamp` algorithm, available in c++17
64 template<class T>
65 constexpr const T& clamp( const T& v, const T& lo, const T& hi )
66 {
67  // assert( !(hi < lo) );
68  return (v < lo) ? lo : (hi < v) ? hi : v;
69 }
70 
71 template<class T, class Compare>
72 constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp )
73 {
74  // assert( !comp(hi, lo) );
75  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
76 }
77 
78 } // namespace conf
79 } // namespace yarp
80 
81 
82 #define YARP_FLT_EXP_DIG 3
83 #define YARP_DBL_EXP_DIG 4
84 #define YARP_LDBL_EXP_DIG 5
85 
86 
87 #ifndef YARP_NO_DEPRECATED // since YARP 3.0.0
88 #include <yarp/conf/api.h> // For YARP_DEPRECATED_TYPEDEF_MSG
89 YARP_DEPRECATED_TYPEDEF_MSG("Use std::int8_t instead") std::int8_t YARP_INT8;
90 YARP_DEPRECATED_TYPEDEF_MSG("Use std::int16_t instead") std::int16_t YARP_INT16;
91 YARP_DEPRECATED_TYPEDEF_MSG("Use std::int32_t instead") std::int32_t YARP_INT32;
92 YARP_DEPRECATED_TYPEDEF_MSG("Use std::int64_t instead") std::int64_t YARP_INT64;
96 #define YARP_INT32_FMT PRId32
97 #define YARP_INT64_FMT PRId64
98 #endif // YARP_NO_DEPRECATED
99 
100 
101 #endif
YARP_FLOAT64
yarp::conf::float64_t YARP_FLOAT64
Definition: numeric.h:94
yarp::conf::clamp
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition: numeric.h:65
yarp::conf::float128_t
long double float128_t
Definition: numeric.h:54
YARP_SSIZE_T
yarp::conf::ssize_t YARP_SSIZE_T
Definition: numeric.h:95
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
YARP_INT8
std::int8_t YARP_INT8
Definition: numeric.h:89
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
YARP_DEPRECATED_TYPEDEF_MSG
#define YARP_DEPRECATED_TYPEDEF_MSG(x)
Definition: api.h:102
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::conf::vocab32_t
std::int32_t vocab32_t
Definition: numeric.h:52
YARP_INT32
std::int32_t YARP_INT32
Definition: numeric.h:91
YARP_FLOAT32
yarp::conf::float32_t YARP_FLOAT32
Definition: numeric.h:93
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
YARP_INT64
std::int64_t YARP_INT64
Definition: numeric.h:92
api.h
YARP_INT16
std::int16_t YARP_INT16
Definition: numeric.h:90