예제 #1
0
bool json::operator<(const Number& num1, const Number& num2) {
    bool result = false;

    switch (num1.get_type()) {
    case Number::Type::INT:
        result = (num1.m_int < Int(num2));
        break;
    case Number::Type::UINT:
        result = (num1.m_uint < Uint(num2));
        break;
    case Number::Type::DOUBLE:
        result = num1.m_double < Double(num2);
        break;
    default:
        result = false;
        break;
    }

    return result;
}
예제 #2
0
bool json::operator==(const Number& num1, const Number& num2) {
    bool result = false;

    switch (num1.get_type()) {
    case Number::Type::INT:
        result = (num1.m_int == Int(num2));
        break;
    case Number::Type::UINT:
        result = (num1.m_uint == Uint(num2));
        break;
    case Number::Type::DOUBLE:
        result = std::fabs(num1.m_double - Double(num2)) <
                 std::numeric_limits<Double>::epsilon();
        break;
    default:
        result = false;
        break;
    }

    return result;
}