@@ -82,20 +82,71 @@ namespace librapid {
82
82
}
83
83
84
84
LR_FORCE_INLINE
85
- VecImpl operator >(const VecImpl &other) {
85
+ VecImpl cmp (const VecImpl &other, const char *mode) const {
86
+ // Mode:
87
+ // 0: ==
88
+ // 1: !=
89
+ // 2: <
90
+ // 3: <=
91
+ // 4: >
92
+ // 5: >=
93
+
86
94
VecImpl res (*this );
95
+ i16 modeInt = *(i16 *)mode;
96
+ fmt::print (" Info: {:Lb}\n " , modeInt);
97
+ fmt::print (" Info: {:Lb}\n " , (' g' << 8 ) | ' t' );
87
98
for (i64 i = 0 ; i < Dims; ++i) {
88
- if (res[i] > other[i]) {
89
- res[i] = 1 ;
90
- } else {
91
- res[i] = 0 ;
99
+ switch (modeInt) {
100
+ case ' e' | (' q' << 8 ):
101
+ if (res[i] == other[i]) {
102
+ res[i] = 1 ;
103
+ } else {
104
+ res[i] = 0 ;
105
+ }
106
+ break ;
107
+ case ' n' | (' e' << 8 ):
108
+ if (res[i] != other[i]) {
109
+ res[i] = 1 ;
110
+ } else {
111
+ res[i] = 0 ;
112
+ }
113
+ break ;
114
+ case ' l' | (' t' << 8 ):
115
+ if (res[i] < other[i]) {
116
+ res[i] = 1 ;
117
+ } else {
118
+ res[i] = 0 ;
119
+ }
120
+ break ;
121
+ case ' l' | (' e' << 8 ):
122
+ if (res[i] <= other[i]) {
123
+ res[i] = 1 ;
124
+ } else {
125
+ res[i] = 0 ;
126
+ }
127
+ break ;
128
+ case ' g' | (' t' << 8 ):
129
+ if (res[i] > other[i]) {
130
+ res[i] = 1 ;
131
+ } else {
132
+ res[i] = 0 ;
133
+ }
134
+ break ;
135
+ case ' g' | (' e' << 8 ):
136
+ if (res[i] >= other[i]) {
137
+ res[i] = 1 ;
138
+ } else {
139
+ res[i] = 0 ;
140
+ }
141
+ break ;
142
+ default : LR_ASSERT (false , " Invalid mode {}" , mode);
92
143
}
93
144
}
94
145
return res;
95
146
}
96
147
97
148
LR_FORCE_INLINE
98
- VecImpl cmp (const VecImpl &other, char mode[ 2 ]) {
149
+ VecImpl cmp (const Scalar &value, const char * mode) const {
99
150
// Mode:
100
151
// 0: ==
101
152
// 1: !=
@@ -105,46 +156,48 @@ namespace librapid {
105
156
// 5: >=
106
157
107
158
VecImpl res (*this );
108
- i16 modeInt = (mode[1 ] << 8 ) | mode[0 ];
159
+ i16 modeInt = *(i16 *)mode;
160
+ fmt::print (" Info: {:Lb}\n " , modeInt);
161
+ fmt::print (" Info: {:Lb}\n " , (' g' << 8 ) | ' t' );
109
162
for (i64 i = 0 ; i < Dims; ++i) {
110
163
switch (modeInt) {
111
- case ( ' e' << 8 ) | ' q' :
112
- if (res[i] == other[i] ) {
164
+ case ' e' | ( ' q' << 8 ) :
165
+ if (res[i] == value ) {
113
166
res[i] = 1 ;
114
167
} else {
115
168
res[i] = 0 ;
116
169
}
117
170
break ;
118
- case ( ' n' << 8 ) | ' e' :
119
- if (res[i] != other[i] ) {
171
+ case ' n' | ( ' e' << 8 ) :
172
+ if (res[i] != value ) {
120
173
res[i] = 1 ;
121
174
} else {
122
175
res[i] = 0 ;
123
176
}
124
177
break ;
125
- case ( ' l' << 8 ) | ' t' :
126
- if (res[i] < other[i] ) {
178
+ case ' l' | ( ' t' << 8 ) :
179
+ if (res[i] < value ) {
127
180
res[i] = 1 ;
128
181
} else {
129
182
res[i] = 0 ;
130
183
}
131
184
break ;
132
- case ( ' l' << 8 ) | ' e' :
133
- if (res[i] <= other[i] ) {
185
+ case ' l' | ( ' e' << 8 ) :
186
+ if (res[i] <= value ) {
134
187
res[i] = 1 ;
135
188
} else {
136
189
res[i] = 0 ;
137
190
}
138
191
break ;
139
- case ( ' g' << 8 ) | ' t' :
140
- if (res[i] > other[i] ) {
192
+ case ' g' | ( ' t' << 8 ) :
193
+ if (res[i] > value ) {
141
194
res[i] = 1 ;
142
195
} else {
143
196
res[i] = 0 ;
144
197
}
145
198
break ;
146
- case ( ' g' << 8 ) | ' e' :
147
- if (res[i] >= other[i] ) {
199
+ case ' g' | ( ' e' << 8 ) :
200
+ if (res[i] >= value ) {
148
201
res[i] = 1 ;
149
202
} else {
150
203
res[i] = 0 ;
@@ -163,6 +216,13 @@ namespace librapid {
163
216
LR_FORCE_INLINE VecImpl operator ==(const VecImpl &other) const { return cmp (other, " eq" ); }
164
217
LR_FORCE_INLINE VecImpl operator !=(const VecImpl &other) const { return cmp (other, " ne" ); }
165
218
219
+ LR_FORCE_INLINE VecImpl operator <(const Scalar &other) const { return cmp (other, " lt" ); }
220
+ LR_FORCE_INLINE VecImpl operator <=(const Scalar &other) const { return cmp (other, " le" ); }
221
+ LR_FORCE_INLINE VecImpl operator >(const Scalar &other) const { return cmp (other, " gt" ); }
222
+ LR_FORCE_INLINE VecImpl operator >=(const Scalar &other) const { return cmp (other, " ge" ); }
223
+ LR_FORCE_INLINE VecImpl operator ==(const Scalar &other) const { return cmp (other, " eq" ); }
224
+ LR_FORCE_INLINE VecImpl operator !=(const Scalar &other) const { return cmp (other, " ne" ); }
225
+
166
226
LR_NODISCARD (" " ) LR_INLINE Scalar mag2 () const { return (m_data * m_data).sum (); }
167
227
LR_NODISCARD (" " ) LR_INLINE Scalar mag () const { return ::librapid::sqrt (mag2 ()); }
168
228
LR_NODISCARD (" " ) LR_INLINE Scalar invMag () const { return 1.0 / mag (); }
0 commit comments