00001
00002
00003
00004
00005
00006 #ifndef __J2K__MATH_STATE_HPP__
00007 #define __J2K__MATH_STATE_HPP__
00008
00009
00010
00011
00012
00013
00014
00015
00016 // Compare reminder: //
00017
00018
00019
00020 // NaN is not equal to NaN, since the first NaN could be a Real/Infinite //
00021
00022
00023
00024
00025 // It might look stupid, but you have to think about it twice //
00026
00027
00028 // NOTICE: Before complaining about BUGS, verify it twice on paper. //
00029
00030 // FPError is Real and not infinite. ] -inf, +inf [ //
00031
00032 // "enum" is converted to int by the compiler; however, it's easier //
00033
00034
00035
00036 #define J2K_MAX_MathState 7
00037
00038 enum MathState {
00039 Zero = 0,
00040 Positive = 1,
00041 Negative = 2,
00042
00043 Valid = 1,
00044
00045 PosInfinity = 3,
00046 NegInfinity = 4,
00047
00048 NaN = 5,
00049
00050 FPError = 6,
00051
00052 Inf = 3,
00053 PosInf = 3,
00054 NegInf = 4,
00055 Pos = 1,
00056 Neg = 2
00057 };
00058
00059
00060 const int MathStateLessThan[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00061 { 0, 1, 0, 1, 0, 6, 2 },
00062 { 0, 2, 0, 1, 0, 6, 2 },
00063 { 1, 1, 2, 1, 0, 6, 2 },
00064
00065 { 0, 0, 0, 0, 0, 0, 0 },
00066 { 1, 1, 1, 1, 0, 6, 1 },
00067 { 6, 6, 6, 6, 0, 6, 6 },
00068 { 2, 2, 2, 1, 0, 6, 2 }
00069 };
00070
00071
00072 const int MathStateBiggerThan[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00073 { 0, 0, 1, 0, 1, 6, 2 },
00074 { 1, 2, 1, 0, 1, 6, 2 },
00075 { 0, 0, 2, 0, 1, 6, 2 },
00076
00077 { 1, 1, 1, 0, 1, 6, 1 },
00078 { 0, 0, 0, 0, 0, 0, 0 },
00079 { 6, 6, 6, 0, 6, 6, 6 },
00080 { 2, 2, 2, 0, 1, 6, 2 }
00081 };
00082
00083 const int MathStateEqualTo[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00084 { 1, 0, 0, 0, 0, 6, 2 },
00085 { 0, 2, 0, 0, 0, 6, 2 },
00086 { 0, 0, 2, 0, 0, 6, 2 },
00087
00088 { 0, 0, 0, 1, 0, 6, 0 },
00089 { 0, 0, 0, 0, 1, 6, 0 },
00090 { 6, 6, 6, 6, 6, 6, 6 },
00091 { 2, 2, 2, 0, 0, 6, 2 }
00092 };
00093
00094
00095 const MathState MathStateAdd[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00096 { Zero, Pos, Neg, PosInf, NegInf, NaN, FPError },
00097 { Pos, Pos, Valid, PosInf, NegInf, NaN, FPError },
00098 { Neg, Valid, Neg, PosInf, NegInf, NaN, FPError },
00099 { PosInf, PosInf, PosInf, PosInf, NaN, NaN, PosInf },
00100 { NegInf, NegInf, NegInf, NaN, NegInf, NaN, NegInf },
00101 { NaN, NaN, NaN, NaN, NaN, NaN, NaN },
00102 { FPError, FPError, FPError, PosInf, NegInf, NaN, FPError }
00103 };
00104
00105
00106 const MathState MathStateSub[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00107 { Zero, Neg, Pos, NegInf, PosInf, NaN, FPError },
00108 { Pos, Valid, Pos, NegInf, PosInf, NaN, FPError },
00109 { Neg, Neg, Valid, NegInf, PosInf, NaN, FPError },
00110 { PosInf, PosInf, PosInf, NaN, PosInf, NaN, PosInf },
00111 { NegInf, NegInf, NegInf, NegInf, NaN, NaN, NegInf },
00112 { NaN, NaN, NaN, NaN, NaN, NaN, NaN },
00113 { FPError, FPError, FPError, NegInf, PosInf, NaN, FPError }
00114 };
00115
00116
00117 const MathState MathStateMult[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00118 { Zero, Zero, Zero, NaN, NaN, NaN, Zero },
00119 { Zero, Pos, Neg, PosInf, NegInf, NaN, FPError },
00120 { Zero, Neg, Pos, NegInf, PosInf, NaN, FPError },
00121 { NaN, PosInf, NegInf, PosInf, NegInf, NaN, NaN },
00122 { NaN, NegInf, PosInf, NegInf, PosInf, NaN, NaN },
00123 { NaN, NaN, NaN, NaN, NaN, NaN, NaN },
00124 { Zero, FPError, FPError, NaN, NaN, NaN, FPError }
00125 };
00126
00127
00128
00129
00130 const MathState MathStateDiv[ J2K_MAX_MathState ][ J2K_MAX_MathState ] = {
00131 { NaN, Zero, Zero, NaN, NaN, NaN, Zero },
00132 { PosInf, Pos, Neg, Zero, Zero, NaN, FPError },
00133 { NegInf, Neg, Pos, Zero, Zero, NaN, FPError },
00134 { NaN, PosInf, NegInf, NaN, NaN, NaN, NaN },
00135 { NaN, NegInf, PosInf, NaN, NaN, NaN, NaN },
00136 { NaN, NaN, NaN, NaN, NaN, NaN, NaN },
00137 { NaN, FPError, FPError, NaN, NaN, NaN, NaN }
00138 };
00139
00140
00141
00142
00143
00144 const char* MathStateTxt[ J2K_MAX_MathState ] = {
00145 "Zero",
00146 "Pos",
00147 "Neg",
00148 "Inf",
00149 "-Inf",
00150 "NaN",
00151 "Error"
00152 };
00153
00154 #endif