/* * This file is part of the Jikes RVM project (http://jikesrvm.org). * * This file is licensed to You under the Eclipse Public License (EPL); * You may not use this file except in compliance with the License. You * may obtain a copy of the License at * * http://www.opensource.org/licenses/eclipse-1.0.php * * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. * * Alternatively, this file is licensed to You under the MIT License: * http://opensource.org/licenses/MIT . */ package test.org.jikesrvm.basic.core.bytecode; import gnu.testlet.TestHarness; import gnu.testlet.Testlet; class TestFloatingRem implements Testlet { public int getExpectedPass() { return 50; } public int getExpectedFail() { return 0; } public int getExpectedKnownFail() { return 0; } TestHarness th; public void test(TestHarness th) { this.th = th; // easy cases testFREM(5f, 3f); testFREM(-5f, 3f); testFREM(5f, -3f); testFREM(-5f, -3f); // harder cases testFREM(3f, 2f); testFREM(-3f, 2f); testFREM(3f, -2f); testFREM(-3f, -2f); // fringe cases float Inff = 1f/0f, NaNf = 0f/0f; testFREM(5.6f, 0f, NaNf); testFREM(7f, 0f, NaNf); testFREM(0f, 5.6f, 0f); testFREM(-0f, 5.6f, -0f); testFREM(0f, 7f, 0f); testFREM(-0f, 7f, -0f); testFREM(NaNf, NaNf, NaNf); testFREM(NaNf, 1f, NaNf); testFREM(1f, NaNf, NaNf); testFREM(Inff, Inff, NaNf); testFREM(Inff, -Inff, NaNf); testFREM(-Inff, Inff, NaNf); testFREM(-Inff, -Inff, NaNf); testFREM(Inff, 1f, NaNf); testFREM(1f, Inff, 1f); testFREM(-Inff, 1f, NaNf); testFREM(1f, -Inff, 1f); // easy cases testDREM(5, 3); testDREM(-5, 3); testDREM(5, -3); testDREM(-5, -3); // harder cases testDREM(3, 2); testDREM(-3, 2); testDREM(3, -2); testDREM(-3, -2); // fringe cases double Inf = 1.0/0.0, NaN = 0.0/0.0; testDREM(5.6, 0, NaN); testDREM(7, 0, NaN); testDREM(0, 5.6, 0); testDREM(-0, 5.6, -0); testDREM(0, 7, 0); testDREM(-0, 7, -0); testDREM(NaN, NaN, NaN); testDREM(NaN, 1, NaN); testDREM(1, NaN, NaN); testDREM(Inf, Inf, NaN); testDREM(Inf, -Inf, NaN); testDREM(-Inf, Inf, NaN); testDREM(-Inf, -Inf, NaN); testDREM(Inf, 1, NaN); testDREM(1, Inf, 1); testDREM(-Inf, 1, NaN); testDREM(1, -Inf, 1); } private void testFREM(float a, float b) { float apb = a % b; float adb = a / b; int q = (int) adb; float res = a - b*q; th.check(Float.toString(apb), Float.toString(res)); } private void testFREM(float a, float b, float res) { float apb = a % b; float adb = a / b; th.check(Float.toString(apb), Float.toString(res)); } private void testDREM(double a, double b) { double apb = a % b; double adb = a / b; int q = (int) adb; double res = a - b*q; th.check(Double.toString(apb), Double.toString(res)); } private void testDREM(double a, double b, double res) { double apb = a % b; double adb = a / b; th.check(Double.toString(apb), Double.toString(res)); } }