gotypes.h
1 /******************************************************************** 2 * Description: gotypes.h 3 * Library file with various functions for working with matrices 4 * 5 * Derived from a work by Fred Proctor, 6 * changed to work with emc2 and HAL 7 * 8 * Adapting Author: Alex Joni 9 * License: LGPL Version 2 10 * System: Linux 11 * 12 ******************************************************************* 13 Similar to posemath, but using different functions. 14 15 TODO: 16 * find the new functions, add them to posemath, convert the rest 17 */ 18 19 20 #ifndef GO_TYPES_H 21 #define GO_TYPES_H 22 23 #include <float.h> /* DBL_MAX, FLOAT_MAX */ 24 25 /*! 26 GO_RESULT symbols run through a small range of values, on the 27 order of tens, suitable for a byte. GO_RESULT_OK is zero for easy 28 detection of error conditions, e.g., if (result) { handle error } 29 */ 30 enum { 31 GO_RESULT_OK = 0, 32 GO_RESULT_IGNORED, /* action can't be done, ignored */ 33 GO_RESULT_BAD_ARGS, /* arguments bad, e.g., null pointer */ 34 GO_RESULT_RANGE_ERROR, /* supplied range value out of bounds */ 35 GO_RESULT_DOMAIN_ERROR, /* resulting domain out of bounds */ 36 GO_RESULT_ERROR, /* action can't be done, a problem */ 37 GO_RESULT_IMPL_ERROR, /* function not implemented */ 38 GO_RESULT_NORM_ERROR, /* a value is expected to be normalized */ 39 GO_RESULT_DIV_ERROR, /* divide by zero */ 40 GO_RESULT_SINGULAR, /* a matrix is singular */ 41 GO_RESULT_NO_SPACE, /* no space for append operation */ 42 GO_RESULT_EMPTY, /* data structure is empty */ 43 GO_RESULT_BUG /* a bug in Go, e.g., unknown case */ 44 }; 45 46 #define go_result_to_string(r) \ 47 (r) == GO_RESULT_OK ? "Ok" : \ 48 (r) == GO_RESULT_IGNORED ? "Ignored" : \ 49 (r) == GO_RESULT_BAD_ARGS ? "Bad Args" : \ 50 (r) == GO_RESULT_RANGE_ERROR ? "Range Error" : \ 51 (r) == GO_RESULT_DOMAIN_ERROR ? "Domain Error" : \ 52 (r) == GO_RESULT_ERROR ? "General Error" : \ 53 (r) == GO_RESULT_IMPL_ERROR ? "Implementation Error" : \ 54 (r) == GO_RESULT_NORM_ERROR ? "Norm Error" : \ 55 (r) == GO_RESULT_DIV_ERROR ? "Div Error" : \ 56 (r) == GO_RESULT_SINGULAR ? "Singular" : \ 57 (r) == GO_RESULT_NO_SPACE ? "No Space" : \ 58 (r) == GO_RESULT_EMPTY ? "Empty" : \ 59 (r) == GO_RESULT_BUG ? "Bug" : "?" 60 61 /*! 62 Joints are characterized by the quantities they affect, such as 63 length for linear joints and angle for rotary joints. 64 */ 65 enum { 66 GO_QUANTITY_NONE = 0, 67 GO_QUANTITY_LENGTH, 68 GO_QUANTITY_ANGLE 69 }; 70 71 #define go_quantity_to_string(q) \ 72 (q) == GO_QUANTITY_LENGTH ? "Length" : \ 73 (q) == GO_QUANTITY_ANGLE ? "Angle" : "None" 74 75 /* go_real: float, long double, default double; GO_INF is defined as 76 the associated max value from float.h */ 77 78 /* 79 In IEEE floating point, 80 81 FLT_MIN = 1.175494e-38, FLT_EPSILON 1.192093e-07 82 DBL_MIN = 2.225074e-308, DBL_EPSILON 2.220446e-16 83 */ 84 85 #if defined(GO_REAL_FLOAT) 86 typedef float go_real; 87 #define GO_REAL go_real_float 88 extern int go_real_float; 89 #define GO_REAL_MIN FLT_MIN 90 #define GO_REAL_MAX FLT_MAX 91 #define GO_REAL_EPSILON (1.0e-4) 92 #define GO_INF FLT_MAX 93 94 #elif defined(GO_REAL_LONG_DOUBLE) 95 typedef long double go_real; 96 #define GO_REAL go_real_long_double 97 extern int go_real_long_double; 98 #define GO_REAL_MIN DBL_MIN 99 #define GO_REAL_MAX DBL_MAX 100 #define GO_REAL_EPSILON (1.0e-10) 101 #define GO_INF DBL_MAX 102 103 #else 104 #define GO_REAL_DOUBLE 105 typedef double go_real; 106 #define GO_REAL go_real_double 107 extern int go_real_double; 108 #define GO_REAL_MIN DBL_MIN 109 #define GO_REAL_MAX DBL_MAX 110 #define GO_REAL_EPSILON (1.0e-7) 111 #define GO_INF DBL_MAX 112 #endif 113 114 /* go_integer: short, long, long long, default int */ 115 116 #if defined(GO_INTEGER_SHORT) 117 typedef short int go_integer; 118 #define GO_INTEGER go_integer_short 119 extern int go_integer_short; 120 #if defined(SHRT_MAX) 121 #define GO_INTEGER_MAX SHRT_MAX 122 #endif 123 124 #elif defined(GO_INTEGER_LONG) 125 typedef long int go_integer; 126 #define GO_INTEGER go_integer_long 127 extern int go_integer_long; 128 #if defined(LONG_MAX) 129 #define GO_INTEGER_MAX LONG_MAX 130 #endif 131 132 #elif defined(GO_INTEGER_LONG_LONG) 133 typedef long long int go_integer; 134 #define GO_INTEGER go_integer_long_long 135 extern int go_integer_long_long; 136 #if defined(LONG_MAX) 137 #define GO_INTEGER_MAX LONG_MAX 138 #endif 139 140 #else 141 #define GO_INTEGER_INT 142 typedef int go_integer; 143 #define GO_INTEGER go_integer_int 144 extern int go_integer_int; 145 #if defined(INT_MAX) 146 #define GO_INTEGER_MAX INT_MAX 147 #endif 148 #endif 149 150 /* go_flag: unsigned short, unsigned int, default unsigned char */ 151 152 #if defined(GO_FLAG_USHORT) 153 typedef unsigned short go_flag; 154 #define GO_FLAG go_flag_ushort 155 extern int go_flag_ushort; 156 157 #elif defined(GO_FLAG_UINT) 158 typedef unsigned int go_flag; 159 #define GO_FLAG go_flag_uint 160 extern int go_flag_uint; 161 162 #else 163 #define GO_FLAG_UCHAR 164 typedef unsigned char go_flag; 165 #define GO_FLAG go_flag_uchar 166 extern int go_flag_uchar; 167 #endif 168 169 #endif /* GO_TYPES_H */