fix decimal bug (#181)

This commit is contained in:
yubingpeng
2018-01-23 19:11:06 +08:00
committed by GitHub
parent 0008399987
commit ef15bf424e
2 changed files with 4 additions and 2 deletions

View File

@ -132,6 +132,7 @@ public:
// Note: the base is 10^9 for parameter frac_value, which means the max length of fraction part
// is 9, and the parameter frac_value need to be divided by 10^9.
DecimalValue(int64_t int_value, int64_t frac_value) : _buffer_length(DECIMAL_BUFF_LENGTH) {
set_to_zero();
if (int_value < 0 || frac_value < 0) {
_sign = true;
} else {
@ -148,6 +149,7 @@ public:
}
DecimalValue(int64_t int_value) : _buffer_length(DECIMAL_BUFF_LENGTH){
set_to_zero();
_sign = int_value < 0 ? true : false;
int32_t big_digit_length = copy_int_to_decimal_int(
@ -390,7 +392,7 @@ public:
// set DecimalValue to zero
void set_to_zero() {
_buffer_length = DECIMAL_BUFF_LENGTH;
_buffer[0] = 0;
memset(_buffer, 0, sizeof(int32_t) * DECIMAL_BUFF_LENGTH);
_int_length = 1;
_frac_length = 0;
_sign = false;

View File

@ -672,7 +672,7 @@ struct DecimalVal : public AnyVal {
}
void set_to_zero() {
buffer[0] = 0;
memset(buffer, 0, sizeof(int32_t) * 9);
int_len = 0;
frac_len = 0;
sign = 0;