Skip to content

Commit 57fc024

Browse files
author
Chaithra Reddy
committed
Bug#18469276: MOD FOR SMALL DECIMALS FAILS
Problem: If leading zeroes of fractional part of a decimal number exceeds 45, mod operation on the same fails. Analysis: Currently there is a miscalcultion of fractional part for very small decimals in do_div_mod. For ex: For 0.000(45 times).....3 length of the integer part becomes -5 (for a length of one, buffer can hold 9 digits. Since number of zeroes are 45, integer part becomes 5) and it is negative because of the leading zeroes present in the fractional part. Fractional part is the number of digits present after the point which is 46 and therefore rounded off to the nearest 9 multiple which is 54. So the length of the resulting fractional part becomes 6. Because of this, the combined length of integer part and fractional part exceeds the max length allocated which is 9 and thereby failing. Solution: In case of negative integer value, it indicates there are leading zeroes in fractional part. As a result stop1 pointer should be set not just based on frac0 but also intg0. This is because the detination buffer will be filled with 0's for the length of intg0.
1 parent 76e690f commit 57fc024

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

strings/decimal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -2322,7 +2322,7 @@ static int do_div_mod(const decimal_t *from1, const decimal_t *from2,
23222322
error=E_DEC_TRUNCATED;
23232323
goto done;
23242324
}
2325-
stop1=start1+frac0;
2325+
stop1= start1 + frac0 + intg0;
23262326
frac0+=intg0;
23272327
to->intg=0;
23282328
while (intg0++ < 0)

0 commit comments

Comments
 (0)