Changeset 1481
- Timestamp:
- 04/13/18 14:29:20 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/XIOS_DEV_CMIP6/src/parse_expr/operator_expr.hpp
r1158 r1481 7 7 #include "exception.hpp" 8 8 #include "array_new.hpp" 9 #include "utils.hpp" 9 10 10 11 using namespace std; … … 253 254 static inline double div_ss(double x, double y) { return x / y; } 254 255 static inline double pow_ss(double x, double y) { return std::pow(x,y); } 255 static inline double eq_ss(double x, double y) { return x == y; } 256 257 static inline double eq_ss(double x, double y) // specific check for NaN 258 { 259 bool xNan=NumTraits<double>::isNan(x) ; 260 bool yNan=NumTraits<double>::isNan(y) ; 261 if (xNan && yNan) return true ; 262 else if (xNan) return false ; 263 else if (yNan) return false ; 264 else return x == y; 265 } 266 256 267 static inline double lt_ss(double x, double y) { return x < y; } 257 268 static inline double gt_ss(double x, double y) { return x > y; } 258 269 static inline double le_ss(double x, double y) { return x <= y; } 259 270 static inline double ge_ss(double x, double y) { return x >= y; } 260 static inline double ne_ss(double x, double y) { return x != y; } 261 271 272 static inline double ne_ss(double x, double y) // specific check for NaN 273 { 274 bool xNan=NumTraits<double>::isNan(x) ; 275 bool yNan=NumTraits<double>::isNan(y) ; 276 if (xNan && yNan) return false ; 277 else if (xNan) return true ; 278 else if (yNan) return true ; 279 else return x != y; 280 } 281 262 282 static inline CArray<double,1> neg_f(const CArray<double,1>& x) { return Array<double,1>(-x); } 263 283 static inline CArray<double,1> cos_f(const CArray<double,1>& x) { return Array<double,1>(cos(x)); } … … 286 306 static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x / y); } 287 307 static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y) { return Array<double,1>(pow(x,y)); } 288 static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x == y); } 308 309 static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y) // specific check for NaN 310 { 311 if (NumTraits<double>::isNan(y)) 312 { 313 CArray<double,1> ret(x.numElements()) ; 314 Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); 315 Array<double,1>::iterator itret=ret.begin() ; 316 for(;itx!=itxe;++itx,++itret) *itret=NumTraits<double>::isNan(*itx) ; 317 return ret ; 318 } 319 else return Array<double,1>(x == y); 320 } 321 289 322 static inline CArray<double,1> lt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x < y); } 290 323 static inline CArray<double,1> gt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x > y); } 291 324 static inline CArray<double,1> le_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x <= y); } 292 325 static inline CArray<double,1> ge_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x >= y); } 293 static inline CArray<double,1> ne_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x != y); } 326 327 static inline CArray<double,1> ne_fs(const CArray<double,1>& x, double y) // specific check for NaN 328 { 329 if (NumTraits<double>::isNan(y)) 330 { 331 CArray<double,1> ret(x.numElements()) ; 332 Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); 333 Array<double,1>::iterator itret=ret.begin() ; 334 for(;itx!=itxe;++itx,++itret) *itret = !NumTraits<double>::isNan(*itx) ; 335 return ret ; 336 } 337 else return Array<double,1>(x != y); 338 } 294 339 295 340 static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x + y); } … … 297 342 static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x * y); } 298 343 static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x / y); } 299 static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x == y); } 344 345 static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y) // specific check for NaN 346 { 347 if (NumTraits<double>::isNan(x)) 348 { 349 CArray<double,1> ret(y.numElements()) ; 350 Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); 351 Array<double,1>::iterator itret=ret.begin() ; 352 for(;ity!=itye;++ity,++itret) *itret=NumTraits<double>::isNan(*ity) ; 353 return ret ; 354 } 355 else return Array<double,1>(x == y); 356 } 300 357 static inline CArray<double,1> lt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x < y); } 301 358 static inline CArray<double,1> gt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x > y); } 302 359 static inline CArray<double,1> le_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x <= y); } 303 360 static inline CArray<double,1> ge_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x >= y); } 304 static inline CArray<double,1> ne_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x != y); } 305 306 361 362 static inline CArray<double,1> ne_sf(double x, const CArray<double,1>& y) // specific check for NaN 363 { 364 if (NumTraits<double>::isNan(x)) 365 { 366 CArray<double,1> ret(y.numElements()) ; 367 Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); 368 Array<double,1>::iterator itret=ret.begin() ; 369 for(;ity!=itye;++ity,++itret) *itret=!NumTraits<double>::isNan(*ity) ; 370 return ret ; 371 } 372 else return Array<double,1>(x != y); 373 } 307 374 static inline double cond_sss(double x, double y, double z) { return (x==0) ? z : y ; } 308 375
Note: See TracChangeset
for help on using the changeset viewer.