Skip to content

Commit

Permalink
Bug#18469276: MOD FOR SMALL DECIMALS FAILS
Browse files Browse the repository at this point in the history
      
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.
  • Loading branch information
Chaithra Reddy committed Jul 3, 2014
1 parent 76e690f commit 57fc024
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions strings/decimal.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -2322,7 +2322,7 @@ static int do_div_mod(const decimal_t *from1, const decimal_t *from2,
error=E_DEC_TRUNCATED;
goto done;
}
stop1=start1+frac0;
stop1= start1 + frac0 + intg0;
frac0+=intg0;
to->intg=0;
while (intg0++ < 0)
Expand Down

0 comments on commit 57fc024

Please sign in to comment.