30 #include "errmessages.h"
32 #define VALID(a) (a.isValid() && a->isValid())
37 typedef unsigned char byte;
39 const quint8 bUNDEF = 2;
40 const short shUNDEF = -32767;
41 const short shILLEGAL = shUNDEF + 1;
42 const long iUNDEF = -2147483647L;
43 const long iILLEGAL = iUNDEF + 1;
44 const double rUNDEF = -1e308;
45 const double rILLEGAL = rUNDEF + 1;
46 const float flUNDEF = ((float)-1e38);
47 const qint64 i64UNDEF = std::numeric_limits < qint64 >::min();
52 inline long roundx(
float x) {
53 if ((x == flUNDEF) || (x > LONG_MAX) || (x < LONG_MIN))
56 return (
long)floor(x + 0.5);
58 inline long roundx(
double x) {
59 if ((x == rUNDEF) || (x > LONG_MAX) || (x < LONG_MIN))
62 return (
long)floor(x + 0.5);
66 inline byte byteConv(
short x) {
return x < 0 ? (byte)0 : x > 255 ? (byte)0 : (byte)x; }
67 inline byte byteConv(
long x) {
return x < 0 ? (byte)0 : x > 255 ? (byte)0 : (byte)x; }
68 inline byte byteConv(
int x) {
return x < 0 ? (byte)0 : x > 255 ? (byte)0 : (byte)x; }
69 inline byte byteConv(
double x) {
return byteConv(roundx(x)); }
70 inline short shortConv (
long x) {
return ((x == iUNDEF) || (x > SHRT_MAX) || (x < SHRT_MIN)) ? shUNDEF : (short)x; }
71 inline short shortConv(
double x) {
return shortConv(roundx(x)); }
72 inline short shortConv(
short x) {
return x; }
73 inline short shortConv(
int x) {
return ((x == iUNDEF) || (x > SHRT_MAX) || (x < SHRT_MIN)) ? shUNDEF : (short)x;}
74 inline long longConv(
short x) {
return x == shUNDEF ? iUNDEF : (long)x; }
75 inline long longConv(
int x) {
return (
long)x; }
76 inline long longConv(
float x) {
return roundx(x); }
77 inline long longConv(
double x) {
return roundx(x); }
78 inline float floatConv(
short x) {
return x == shUNDEF ? flUNDEF : (float)x; }
79 inline float floatConv(
long x) {
return x == iUNDEF ? flUNDEF : (float)x; }
80 inline float floatConv(
double x) {
return ((x == rUNDEF) || (x < -FLT_MAX) || (x > FLT_MAX)) ? flUNDEF : (float)x; }
81 inline double doubleConv(
short x) {
return x == shUNDEF ? rUNDEF : (double)x; }
82 inline double doubleConv(
long x) {
return x == iUNDEF ? rUNDEF : (double)x; }
83 inline double doubleConv(
float x) {
return x == flUNDEF ? rUNDEF : (double)x; }
84 inline double min(
double a,
double b) {
return ((a<=b && a!=rUNDEF && a!= iUNDEF) || b==rUNDEF) ? a : b; }
85 inline double max(
double a,
double b) {
return (a>=b && a!=rUNDEF && a != iUNDEF) ? a : b; }
86 inline long min(
long a,
long b) {
return ((a<=b && a!=iUNDEF) || b==iUNDEF) ? a : b; }
87 inline long max(
long a,
long b) {
return (a>=b && a!=iUNDEF) ? a : b; }
88 inline qint64 max(qint64 a, qint64 b) {
return a>=b && a!=i64UNDEF ? a : b;}
90 enum LogicalOperator{loNONE,loAND, loOR, loXOR, loLESS, loLESSEQ, loNEQ, loEQ, loGREATER, loGREATEREQ};
93 #include "ilwistypes.h"
97 #define M_PI 3.14159265358979323846
101 #define M_1_SQRTPI 0.564189583547756286948
104 #define M_SQRT_2 0.707106781186547524401
105 #define M_RAD_BASE 57.29577951308232087502
107 const double EPS15=1.e-15;
108 const double EPS12=1.e-12;
109 const double EPS10=1.e-10;
110 const double EPS8=1.e-8;
111 const double EPS7=1.e-7;
112 const double EPS6=1.e-6;
113 const double EPS5=1.e-5;
116 template<
class T>
inline IlwisTypes numericType() {
117 bool isSigned = std::numeric_limits<T>::is_signed;
118 if ( std::numeric_limits<T>::is_integer) {
119 qint64 m2 = std::numeric_limits<T>::max();
121 return isSigned ? itINT8 : itUINT8;
122 else if ( m2 < 65536 )
123 return isSigned ? itINT16 : itUINT16;
124 else if ( m2 <= 4294967296L)
125 return isSigned ? itINT32 : itUINT32;
126 else if ( m2 <= qint64(9223372036854775807))
127 return (T)(isSigned ? itINT64 : itUINT64);
129 double m2 = std::numeric_limits<T>::max();
130 if ( m2 == std::numeric_limits<double>::max()){
132 }
else if ( m2 == std::numeric_limits<float>::max())
138 template<
class T> T undef() {
139 IlwisTypes type = numericType<T>();
146 return (T)Ilwis::shUNDEF;
149 return (T)Ilwis::iUNDEF;
151 return (T)Ilwis::flUNDEF;
153 return (T)Ilwis::rUNDEF;
155 return (T)Ilwis::i64UNDEF;
166 #define isNumericalUndef(v) (v == Ilwis::rUNDEF || v == Ilwis::iUNDEF || v == Ilwis::shUNDEF || v == Ilwis::flUNDEF)