9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4851776 4907265 6177836 6876282 27 * @summary Some tests for the divide methods. 28 * @author Joseph D. Darcy 29 * @compile -source 1.5 DivideTests.java 30 * @run main DivideTests 31 */ 32 33 import java.math.*; 34 import static java.math.BigDecimal.*; 35 36 public class DivideTests { 37 38 // Preliminary exact divide method; could be used for comparison 39 // purposes. 40 BigDecimal anotherDivide(BigDecimal dividend, BigDecimal divisor) { 41 /* 42 * Handle zero cases first. 43 */ 44 if (divisor.signum() == 0) { // x/0 45 if (dividend.signum() == 0) // 0/0 46 throw new ArithmeticException("Division undefined"); // NaN 47 throw new ArithmeticException("Division by zero"); 48 } 49 if (dividend.signum() == 0) // 0/y 50 return BigDecimal.ZERO; | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4851776 4907265 6177836 6876282 27 * @summary Some tests for the divide methods. 28 * @author Joseph D. Darcy 29 */ 30 31 import java.math.*; 32 import static java.math.BigDecimal.*; 33 34 public class DivideTests { 35 36 // Preliminary exact divide method; could be used for comparison 37 // purposes. 38 BigDecimal anotherDivide(BigDecimal dividend, BigDecimal divisor) { 39 /* 40 * Handle zero cases first. 41 */ 42 if (divisor.signum() == 0) { // x/0 43 if (dividend.signum() == 0) // 0/0 44 throw new ArithmeticException("Division undefined"); // NaN 45 throw new ArithmeticException("Division by zero"); 46 } 47 if (dividend.signum() == 0) // 0/y 48 return BigDecimal.ZERO; |