IsFloatEqual

Description

Checks whether two float or double values are equal.

Prototype

template <typename T>
auto IsFloatEqual(T a, T b) -> typename std::enable_if<std::is_floating_point<T>::value, bool>::type

Parameters

Parameter

Input/Output

Description

a

Input

Parameter to be compared. The parameter type can be float or double.

b

Input

Parameter to be compared. The parameter type can be float or double.

Return Value

Return type: bool

  • true: The two float/double values are equal.
  • false: The two float/double values are not equal.

Constraints

None.

Example

The following sample code is for reference only. Do not copy and run it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
float delta;
if (op.GetAttr("delta", delta) == ge::GRAPH_FAILED) {
    std::string err_msg = GetInputInvalidErrMsg("delta");
    VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
    return GRAPH_FAILED;
}
if (IsFloatEqual(delta, 0.0f)) {
    string excepted_value = ConcatString("not equal to 0");
    std::string err_msg = GetAttrValueErrMsg("delta", ConcatString("delta"), excepted_value);
    VECTOR_INFER_SHAPE_INNER_ERR_REPORT(TbeGetName(op), err_msg);
    return GRAPH_FAILED;
}