summaryrefslogtreecommitdiff
path: root/src/libnml/posemath/gotypes.h
blob: c94df69e2d9a44e7de3375fd8883a6b5cb4e14fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/********************************************************************
* Description: gotypes.h
*   Library file with various functions for working with matrices
*
*   Derived from a work by Fred Proctor,
*   changed to work with emc2 and HAL
*
* Adapting Author: Alex Joni
* License: LGPL Version 2
* System: Linux
*    
*******************************************************************
    Similar to posemath, but using different functions.
    
    TODO: 
	* find the new functions, add them to posemath, convert the rest
*/


#ifndef GO_TYPES_H
#define GO_TYPES_H

#include <float.h>		/* DBL_MAX, FLOAT_MAX */

/*!
  GO_RESULT symbols run through a small range of values, on the
  order of tens, suitable for a byte.  GO_RESULT_OK is zero for easy
  detection of error conditions, e.g., if (result) { handle error }
*/
enum {
  GO_RESULT_OK = 0,
  GO_RESULT_IGNORED,		/* action can't be done, ignored */
  GO_RESULT_BAD_ARGS,		/* arguments bad, e.g., null pointer */
  GO_RESULT_RANGE_ERROR,	/* supplied range value out of bounds */
  GO_RESULT_DOMAIN_ERROR,	/* resulting domain out of bounds */
  GO_RESULT_ERROR,		/* action can't be done, a problem */
  GO_RESULT_IMPL_ERROR,		/* function not implemented */
  GO_RESULT_NORM_ERROR,		/* a value is expected to be normalized */
  GO_RESULT_DIV_ERROR,		/* divide by zero */
  GO_RESULT_SINGULAR,		/* a matrix is singular */
  GO_RESULT_NO_SPACE,		/* no space for append operation */
  GO_RESULT_EMPTY,		/* data structure is empty */
  GO_RESULT_BUG			/* a bug in Go, e.g., unknown case */
};

#define go_result_to_string(r)				\
(r) == GO_RESULT_OK ? "Ok" :				\
(r) == GO_RESULT_IGNORED ? "Ignored" :			\
(r) == GO_RESULT_BAD_ARGS ? "Bad Args" :		\
(r) == GO_RESULT_RANGE_ERROR ? "Range Error" :		\
(r) == GO_RESULT_DOMAIN_ERROR ? "Domain Error" :	\
(r) == GO_RESULT_ERROR ? "General Error" :		\
(r) == GO_RESULT_IMPL_ERROR ? "Implementation Error" :	\
(r) == GO_RESULT_NORM_ERROR ? "Norm Error" :		\
(r) == GO_RESULT_DIV_ERROR ? "Div Error" :		\
(r) == GO_RESULT_SINGULAR ? "Singular" :		\
(r) == GO_RESULT_NO_SPACE ? "No Space" :		\
(r) == GO_RESULT_EMPTY ? "Empty" :			\
(r) == GO_RESULT_BUG ? "Bug" : "?"

/*!
  Joints are characterized by the quantities they affect, such as
  length for linear joints and angle for rotary joints.
*/
enum {
  GO_QUANTITY_NONE = 0,
  GO_QUANTITY_LENGTH,
  GO_QUANTITY_ANGLE
};

#define go_quantity_to_string(q)		\
(q) == GO_QUANTITY_LENGTH ? "Length" :		\
(q) == GO_QUANTITY_ANGLE ? "Angle" : "None"

/* go_real: float, long double, default double; GO_INF is defined as
 the associated max value from float.h */

/*
  In IEEE floating point,

  FLT_MIN = 1.175494e-38, FLT_EPSILON 1.192093e-07
  DBL_MIN = 2.225074e-308, DBL_EPSILON 2.220446e-16
*/

#if defined(GO_REAL_FLOAT)
typedef float go_real;
#define GO_REAL go_real_float
extern int go_real_float;
#define GO_REAL_MIN FLT_MIN
#define GO_REAL_MAX FLT_MAX
#define GO_REAL_EPSILON (1.0e-4)
#define GO_INF FLT_MAX

#elif defined(GO_REAL_LONG_DOUBLE)
typedef long double go_real;
#define GO_REAL go_real_long_double
extern int go_real_long_double;
#define GO_REAL_MIN DBL_MIN
#define GO_REAL_MAX DBL_MAX
#define GO_REAL_EPSILON (1.0e-10)
#define GO_INF DBL_MAX

#else
#define GO_REAL_DOUBLE
typedef double go_real;
#define GO_REAL go_real_double
extern int go_real_double;
#define GO_REAL_MIN DBL_MIN
#define GO_REAL_MAX DBL_MAX
#define GO_REAL_EPSILON (1.0e-7)
#define GO_INF DBL_MAX
#endif

/* go_integer: short, long, long long, default int */

#if defined(GO_INTEGER_SHORT)
typedef short int go_integer;
#define GO_INTEGER go_integer_short
extern int go_integer_short;
#if defined(SHRT_MAX)
#define GO_INTEGER_MAX SHRT_MAX
#endif

#elif defined(GO_INTEGER_LONG)
typedef long int go_integer;
#define GO_INTEGER go_integer_long
extern int go_integer_long;
#if defined(LONG_MAX)
#define GO_INTEGER_MAX LONG_MAX
#endif

#elif defined(GO_INTEGER_LONG_LONG)
typedef long long int go_integer;
#define GO_INTEGER go_integer_long_long
extern int go_integer_long_long;
#if defined(LONG_MAX)
#define GO_INTEGER_MAX LONG_MAX
#endif

#else
#define GO_INTEGER_INT
typedef int go_integer;
#define GO_INTEGER go_integer_int
extern int go_integer_int;
#if defined(INT_MAX)
#define GO_INTEGER_MAX INT_MAX
#endif
#endif

/* go_flag: unsigned short, unsigned int, default unsigned char */

#if defined(GO_FLAG_USHORT)
typedef unsigned short go_flag;
#define GO_FLAG go_flag_ushort
extern int go_flag_ushort;

#elif defined(GO_FLAG_UINT)
typedef unsigned int go_flag;
#define GO_FLAG go_flag_uint
extern int go_flag_uint;

#else
#define GO_FLAG_UCHAR
typedef unsigned char go_flag;
#define GO_FLAG go_flag_uchar
extern int go_flag_uchar;
#endif

#endif /* GO_TYPES_H */