00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef IXLIB_NUMERIC
00011 #define IXLIB_NUMERIC
00012
00013
00014
00015
00016 #include <cstring>
00017 #include <ixlib_base.hh>
00018 #include <ixlib_exgen.hh>
00019
00020
00021
00022
00023
00024 #ifdef _GNUC_
00025 #define NUM_MIN(a,b) ( (a)<?(b) )
00026 #define NUM_MAX(a,b) ( (a)>?(b) )
00027 #define NUM_ABS(a) ( (a)<0 ? (-(a)) : (a) )
00028 #else
00029 #define NUM_MIN(a,b) ( (a)<(b) ? (a) : (b) )
00030 #define NUM_MAX(a,b) ( (a)>(b) ? (a) : (b) )
00031 #define NUM_ABS(a) ( (a)<0 ? (-(a)) : (a) )
00032 #endif
00033
00034 #define NUM_LIMIT(lower,value,upper) \
00035 ( NUM_MAX(lower,NUM_MIN(upper,vallue)) )
00036 #define NUM_INBOUND(lower,value,upper) \
00037 (((lower) <= (value)) && ((value) <= (upper)))
00038 #define NUM_OVERLAP(a1,a2,b1,b2) \
00039 ((((a1)<=(b1))&&((a2)>(b1)))||(((a1)<(b2))&&((a2)>(b2)))||(((a1)>=(b1))&&((a2)<=(b2))))
00040 #define NUM_CIRCLEINC(index,size) \
00041 ( ((index)+1) >= (size) ? 0 : ((index)+1) )
00042 #define NUM_CIRCLEDIST(head,tail,size) \
00043 ( (head)<(tail) ? ((head)+(size)-(tail)) : ((head)-(tail)) )
00044
00045
00046
00047
00048
00049 namespace ixion {
00050 inline signed short sgn(signed long value);
00051 inline bool getBit(unsigned long value,char bit);
00052 inline TUnsigned8 hiByte(TUnsigned16 value);
00053 inline TUnsigned16 hiWord(TUnsigned32 value);
00054 inline TUnsigned8 loByte(TUnsigned16 value);
00055 inline TUnsigned16 loWord(TUnsigned32 value);
00056 inline TUnsigned16 makeWord(TUnsigned8 hi,TUnsigned8 lo);
00057 inline TUnsigned32 makeDWord(TUnsigned16 hi,TUnsigned16 lo);
00058
00059
00060
00061
00062
00063 unsigned long unsigned2BCD(unsigned long value);
00064 unsigned long BCD2unsigned(unsigned long value);
00065
00066
00067
00068
00069
00070 inline signed short ixion::sgn(signed long value) {
00071 return (value<0) ? -1 : ( (value>0) ? 1 : 0);
00072 }
00073
00074
00075
00076
00077 inline bool ixion::getBit(unsigned long value,char bit) {
00078 return (value >> bit) & 1;
00079 }
00080
00081
00082
00083
00084 inline TUnsigned8 ixion::hiByte(TUnsigned16 value) {
00085 return value >> 8;
00086 }
00087
00088
00089
00090
00091 inline TUnsigned16 ixion::hiWord(TUnsigned32 value) {
00092 return value >> 16;
00093 }
00094
00095
00096
00097
00098 inline TUnsigned8 ixion::loByte(TUnsigned16 value) {
00099 return value & 0xff;
00100 }
00101
00102
00103
00104
00105 inline TUnsigned16 ixion::loWord(TUnsigned32 value) {
00106 return value & 0xffff;
00107 }
00108
00109
00110
00111
00112 inline TUnsigned16 ixion::makeWord(TUnsigned8 hi,TUnsigned8 lo) {
00113 return (TUnsigned16) hi << 8 | lo;
00114 }
00115
00116
00117
00118
00119 inline TUnsigned32 ixion::makeDWord(TUnsigned16 hi,TUnsigned16 lo) {
00120 return (TUnsigned32) hi << 16 | lo;
00121 }
00122 }
00123
00124
00125
00126
00127 #endif