@ -17,8 +17,7 @@
|
||||
|
||||
#include "exprs/cast_functions.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#include "exprs/anyval_util.h"
|
||||
#include "runtime/datetime_value.h"
|
||||
@ -113,7 +112,9 @@ CAST_FUNCTION(FloatVal, DoubleVal, double_val)
|
||||
num_type ret; \
|
||||
ret.val = StringParser::string_parser_fn<native_type>( \
|
||||
reinterpret_cast<char*>(val.ptr), val.len, &result); \
|
||||
if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) return num_type::null(); \
|
||||
if (UNLIKELY(result != StringParser::PARSE_SUCCESS || std::isnan(ret.val) || std::isinf(ret.val))) { \
|
||||
return num_type::null(); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
@ -362,6 +362,9 @@ public class FEFunctions {
|
||||
|
||||
@FEFunction(name = "divide", argTypes = { "DOUBLE", "DOUBLE" }, returnType = "DOUBLE")
|
||||
public static FloatLiteral divideDouble(LiteralExpr first, LiteralExpr second) throws AnalysisException {
|
||||
if (second.getDoubleValue() == 0.0) {
|
||||
return null;
|
||||
}
|
||||
double result = first.getDoubleValue() / second.getDoubleValue();
|
||||
return new FloatLiteral(result, Type.DOUBLE);
|
||||
}
|
||||
@ -370,6 +373,9 @@ public class FEFunctions {
|
||||
public static DecimalLiteral divideDecimal(LiteralExpr first, LiteralExpr second) throws AnalysisException {
|
||||
BigDecimal left = new BigDecimal(first.getStringValue());
|
||||
BigDecimal right = new BigDecimal(second.getStringValue());
|
||||
if (right.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return null;
|
||||
}
|
||||
BigDecimal result = left.divide(right);
|
||||
return new DecimalLiteral(result);
|
||||
}
|
||||
@ -378,7 +384,9 @@ public class FEFunctions {
|
||||
public static DecimalLiteral divideDecimalV2(LiteralExpr first, LiteralExpr second) throws AnalysisException {
|
||||
BigDecimal left = new BigDecimal(first.getStringValue());
|
||||
BigDecimal right = new BigDecimal(second.getStringValue());
|
||||
|
||||
if (right.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return null;
|
||||
}
|
||||
BigDecimal result = left.divide(right);
|
||||
return new DecimalLiteral(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user