DivideTests.java revision 2362
2362N/A * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. 809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 809N/A * This code is free software; you can redistribute it and/or modify it 809N/A * under the terms of the GNU General Public License version 2 only, as 809N/A * published by the Free Software Foundation. 809N/A * This code is distributed in the hope that it will be useful, but WITHOUT 809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 809N/A * version 2 for more details (a copy is included in the LICENSE file that 809N/A * accompanied this code). 809N/A * You should have received a copy of the GNU General Public License version 809N/A * 2 along with this work; if not, write to the Free Software Foundation, 809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 1598N/A * @bug 4851776 4907265 6177836 6876282 809N/A * @summary Some tests for the divide methods. 809N/A * @author Joseph D. Darcy 809N/A // Preliminary exact divide method; could be used for comparison 809N/A * Handle zero cases first. 809N/A * Determine if there is a result with a terminating 809N/A * decimal expansion. Putting aside overflow and 809N/A * underflow considerations, the existance of an exact 809N/A * result only depends on the ratio of the intVal's of the 809N/A * dividend (i.e. this) and and divisor since the scales 809N/A * of the argument just affect where the decimal point 809N/A * For the ratio of (a = this.intVal) and (b = 809N/A * divisor.intVal) to have a finite decimal expansion, 809N/A * once a/b is put in lowest terms, b must be equal to 809N/A * (2^i)*(5^j) for some integer i,j >= 0. Therefore, we 809N/A * first compute to see if b_prime =(b/gcd(a,b)) is equal 809N/A // b_prime divisible by 10=2*5, increment i and j 809N/A // b_prime divisible by 5, increment j 809N/A // b_prime divisible by 2, increment i 809N/A default:
// hit something we shouldn't have 809N/A // What is a rule for determining how many digits are 809N/A // needed? Once that is determined, cons up a new 809N/A // MathContext object and pass it on to the divide(bd, 809N/A // mc) method; precision == ?, roundingMode is unnecessary. 809N/A // Are we sure this is the right scale to use? Should 809N/A // also determine a precision-based method. 809N/A // Should do some more work here to rescale, etc. 809N/A for(
int i =
0; i <
6; i++) {
809N/A for(
int j =
0; j <
6; j++) {
809N/A // For each pair of prime products, verify the ratio of 809N/A // non-equal products has a non-terminating expansion. 809N/A " returned for non-terminating fraction " +
809N/A // Tests of the traditional scaled divide under different 809N/A // Encode rounding mode and scale for the divide in a 809N/A // BigDecimal with the significand equal to the rounding mode 809N/A // and the scale equal to the number's scale. 809N/A // {dividend, dividisor, rounding, quotient} 1598N/A // { dividend, divisor, expected quotient } 809N/A " failures while testing exact divide.");