oceanbase / oceanbase

OceanBase is an enterprise distributed relational database with high availability, high performance, horizontal scalability, and compatibility with SQL standards.
https://open.oceanbase.com
Other
8.27k stars 1.66k forks source link

[WhiteScan] [622822235] [FLOATING_POINT_EQUALITY] oceanbase/src/sql/engine/expr/ob_datum_cast.cpp #1357

Open ob-robot opened 1 year ago

ob-robot commented 1 year ago

oceanbase/src/sql/engine/expr/ob_datum_cast.cpp

----8<--------------8<-------

5448:{

5449:  int ret = OB_SUCCESS;

5450:  ObObjTypeClass type_class = ob_obj_type_class(type);

5451:  if (OB_UNLIKELY(ObFloatTC != type_class && ObDoubleTC != type_class)) {

5452:    ret = OB_INVALID_ARGUMENT;

5453:    LOG_WARN("obj type is invalid, must be float/double tc", K(ret), K(type), K(type_class));

5454:  } else {

5455:    IN_TYPE in_val = *(reinterpret_cast<const IN_TYPE*>(in_datum.ptr_));

5456:    IN_TYPE out_val = in_val;

Medium:(FLOATING_POINT_EQUALITY)

CWEnone: Floating-point expressions shall not be directly or indirectly tested for equality or inequality.

Floating point expression "0." is compared using operator "==".

oceanbase/src/sql/engine/expr/ob_datum_cast.cpp: int oceanbase::sql::float_range_check(unsigned long const &, oceanbase::common::ObAccuracy const &, oceanbase::common::ObObjType, oceanbase::common::ObDatum const &, oceanbase::common::ObDatum &, int &)

5457:    if (lib::is_oracle_mode() && 0.0 == in_val) {

5458:      if (ObFloatTC == type_class) {

5459:        res_datum.set_float(0.0);

5460:      } else {

5461:        res_datum.set_double(0.0);

5462:      }

5463:    } else {

5464:      if (CAST_FAIL_CM(real_range_check(accuracy, out_val), cast_mode)) {

5465:        LOG_WARN("real_range_check failed", K(ret));

5466:      } else if (in_val != out_val) {

5467:        if (ObFloatTC == type_class) {

warr99 commented 11 months ago

Hi there,

I'm interested in working on this issue. Is it available for me to work on?

Is there anything specific I should keep in mind while working on this? Any additional context or guidance would be appreciated.

Looking forward to contributing to the project!

Best regards,

hnwyllmm commented 11 months ago

Thanks. There are some definition named epsilon(maybe), please take a look.

warr99 commented 11 months ago

Should I use the epsilon value defined in the C/C++ standard library for floating-point types, which is FLT_EPSILON ?

hnwyllmm commented 11 months ago

It looks good