1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* 2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements. See the NOTICE file distributed with 4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership. 5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with 7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. You may obtain a copy of the License at 8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software 12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * See the License for the specific language governing permissions and 15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * limitations under the License. 16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 18ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.lang; 19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.COPYSIGN_DD_CASES; 21ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.COPYSIGN_FF_CASES; 22ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.GETEXPONENT_D_CASES; 23ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.GETEXPONENT_D_RESULTS; 24ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.GETEXPONENT_F_CASES; 25ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.GETEXPONENT_F_RESULTS; 26ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.NEXTAFTER_DD_START_CASES; 27ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.NEXTAFTER_DD_FD_DIRECTION_CASES; 28ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathimport static org.apache.harmony.tests.java.lang.MathTest.NEXTAFTER_FD_START_CASES; 29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class StrictMathTest extends junit.framework.TestCase { 31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath private static final double HYP = StrictMath.sqrt(2.0); 33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath private static final double OPP = 1.0; 35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath private static final double ADJ = 1.0; 37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /* Required to make previous preprocessor flags work - do not remove */ 39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath int unused = 0; 40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#abs(double) 43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_absD() { 45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.abs(double) 46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect double abs value", 48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(-1908.8976) == 1908.8976)); 49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect double abs value", 50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(1908.8976) == 1908.8976)); 51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#abs(float) 55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_absF() { 57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method float java.lang.StrictMath.abs(float) 58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float abs value", 59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(-1908.8976f) == 1908.8976f)); 60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float abs value", 61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(1908.8976f) == 1908.8976f)); 62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#abs(int) 66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_absI() { 68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method int java.lang.StrictMath.abs(int) 69cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect int abs value", 70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(-1908897) == 1908897)); 71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect int abs value", 72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(1908897) == 1908897)); 73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#abs(long) 77cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 78cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_absJ() { 79cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method long java.lang.StrictMath.abs(long) 80cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect long abs value", (StrictMath 81cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(-19088976000089L) == 19088976000089L)); 82cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect long abs value", 83cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (StrictMath.abs(19088976000089L) == 19088976000089L)); 84cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 85cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 86cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 87cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#acos(double) 88cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 89cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_acosD() { 90cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.acos(double) 91cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath 92cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .acos(ADJ / HYP)) == ADJ / HYP); 93cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 94cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 95cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 96cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#asin(double) 97cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 98cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_asinD() { 99cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.asin(double) 100cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath 101cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .asin(OPP / HYP)) == OPP / HYP); 102cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 103cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 104cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 105cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#atan(double) 106cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 107cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_atanD() { 108cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.atan(double) 109cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double answer = StrictMath.tan(StrictMath.atan(1.0)); 110cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 111cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath && answer >= 9.9999999999999983E-1); 112cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 113cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 114cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 115cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#atan2(double, double) 116cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 117cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_atan2DD() { 118cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.atan2(double, double) 119cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double answer = StrictMath.atan(StrictMath.tan(1.0)); 120cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 121cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath && answer >= 9.9999999999999983E-1); 122cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 123cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 124cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 125cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#cbrt(double) 126cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 127cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 128cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_cbrt_D() { 129cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special situations 130cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return Double.NaN", Double.isNaN(StrictMath 131cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cbrt(Double.NaN))); 132cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return Double.POSITIVE_INFINITY", 133cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 134cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cbrt(Double.POSITIVE_INFINITY)); 135cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return Double.NEGATIVE_INFINITY", 136cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath 137cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cbrt(Double.NEGATIVE_INFINITY)); 138cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 139cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.cbrt(0.0))); 140cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 141cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.cbrt(+0.0))); 142cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 143cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.cbrt(-0.0))); 144cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 145cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0)); 146cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 23.111993172558684", 23.111993172558684, 147cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cbrt(12345.6)); 148cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 5.643803094122362E102", 149cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE)); 150cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001)); 151cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 152cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0)); 153cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -23.111993172558684", -23.111993172558684, 154cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cbrt(-12345.6)); 155cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.7031839360032603E-108", 156cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE)); 157cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001)); 158cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 159cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 160cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cbrt((Double) null); 161cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 162cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 163cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath //expected 164cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 165cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 166cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 167cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 168cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#ceil(double) 169cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 170cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ceilD() { 171cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.ceil(double) 172cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect ceiling for double", 173cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 79, StrictMath.ceil(78.89), 0.0); 174cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect ceiling for double", 175cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -78, StrictMath.ceil(-78.89), 0.0); 176cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 177cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 178cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 179cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#copySign(double, double)} 180cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 181cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 182cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 183cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_copySign_DD() { 184cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < COPYSIGN_DD_CASES.length; i++) { 185cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double magnitude = COPYSIGN_DD_CASES[i]; 186cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long absMagnitudeBits = Double.doubleToLongBits(StrictMath 187cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(magnitude)); 188cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long negMagnitudeBits = Double.doubleToLongBits(-StrictMath 189cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(magnitude)); 190cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 191cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // cases for NaN 192cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("If the sign is NaN, the result should be positive.", 193cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath absMagnitudeBits, Double.doubleToLongBits(StrictMath 194cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(magnitude, Double.NaN))); 195cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 196cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(Double.NaN, magnitude))); 197cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 198cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int j = 0; j < COPYSIGN_DD_CASES.length; j++) { 199cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double sign = COPYSIGN_DD_CASES[j]; 200cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long resultBits = Double.doubleToLongBits(StrictMath 201cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(magnitude, sign)); 202cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 203cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (sign > 0 || Double.valueOf(+0.0).equals(sign) 204cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath || Double.valueOf(0.0).equals(sign)) { 205cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals( 206cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "If the sign is positive, the result should be positive.", 207cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath absMagnitudeBits, resultBits); 208cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 209cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (sign < 0 || Double.valueOf(-0.0).equals(sign)) { 210cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals( 211cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "If the sign is negative, the result should be negative.", 212cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath negMagnitudeBits, resultBits); 213cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 214cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 215cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 216cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 217cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 218cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(Double.NaN, Double.NaN))); 219cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 220cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 221cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign((Double) null, 2.3); 222cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 223cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 224cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 225cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 226cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 227cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign(2.3, (Double) null); 228cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 229cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 230cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 231cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 232cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 233cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign((Double) null, (Double) null); 234cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 235cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 236cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 237cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 238cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 239cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double d = Double.longBitsToDouble(0xfff8000000000000L); 240cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.copySign(1.0, d), 0d); 241cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 242cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 243cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 244cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#copySign(float, float)} 245cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 246cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 247cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 248cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_copySign_FF() { 249cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < COPYSIGN_FF_CASES.length; i++) { 250cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final float magnitude = COPYSIGN_FF_CASES[i]; 251cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int absMagnitudeBits = Float.floatToIntBits(StrictMath 252cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(magnitude)); 253cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int negMagnitudeBits = Float.floatToIntBits(-StrictMath 254cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(magnitude)); 255cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 256cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // cases for NaN 257cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("If the sign is NaN, the result should be positive.", 258cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath absMagnitudeBits, Float.floatToIntBits(StrictMath.copySign( 259cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath magnitude, Float.NaN))); 260cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 261cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(Float.NaN, magnitude))); 262cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 263cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int j = 0; j < COPYSIGN_FF_CASES.length; j++) { 264cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final float sign = COPYSIGN_FF_CASES[j]; 265cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int resultBits = Float.floatToIntBits(StrictMath 266cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(magnitude, sign)); 267cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (sign > 0 || Float.valueOf(+0.0f).equals(sign) 268cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath || Float.valueOf(0.0f).equals(sign)) { 269cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals( 270cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "If the sign is positive, the result should be positive.", 271cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath absMagnitudeBits, resultBits); 272cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 273cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (sign < 0 || Float.valueOf(-0.0f).equals(sign)) { 274cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals( 275cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "If the sign is negative, the result should be negative.", 276cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath negMagnitudeBits, resultBits); 277cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 278cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 279cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 280cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 281cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 282cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .copySign(Float.NaN, Float.NaN))); 283cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 284cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 285cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign((Float) null, 2.3f); 286cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 287cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 288cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 289cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 290cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 291cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign(2.3f, (Float) null); 292cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 293cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 294cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 295cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 296cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 297cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.copySign((Float) null, (Float) null); 298cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 299cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 300cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 301cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 302cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 303cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath float f = Float.intBitsToFloat(0xffc00000); 304cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.copySign(1.0f, f), 0f); 305cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 306cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 307cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 308cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#cos(double) 309cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 310cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_cosD() { 311cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.cos(double) 312cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 313cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath 314cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .acos(ADJ / HYP)) == ADJ / HYP); 315cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 316cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 317cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 318cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#cosh(double) 319cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 320cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 321cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_cosh_D() { 322cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special situations 323cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath 324cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cosh(Double.NaN))); 325cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 326cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 327cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cosh(Double.POSITIVE_INFINITY)); 328cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 329cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 330cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cosh(Double.NEGATIVE_INFINITY)); 331cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0)); 332cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0)); 333cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 334cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 335cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56)); 336cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 337cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56)); 338cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0000000000005", 1.0000000000005, 339cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cosh(0.000001)); 340cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0000000000005", 1.0000000000005, 341cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cosh(-0.000001)); 342cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 5.212214351945598", 5.212214351945598, 343cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.cosh(2.33482)); 344cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 345cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 346cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE)); 347cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0", 1.0, StrictMath 348cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .cosh(Double.MIN_VALUE)); 349cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 350cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 351cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 352cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#exp(double) 353cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 354cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_expD() { 355cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.exp(double) 356cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect answer returned for simple power", StrictMath 357cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E 358cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * StrictMath.E * StrictMath.E) < 0.1D); 359cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect answer returned for larger power", StrictMath 360cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D); 361cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 362cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 363cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 364cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#expm1(double) 365cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 366cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 367cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_expm1_D() { 368cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath //Test for special cases 369cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN))); 370cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 371cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY)); 372cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -1.0", -1.0, StrictMath 373cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .expm1(Double.NEGATIVE_INFINITY)); 374cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 375cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.expm1(0.0))); 376cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 377cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.expm1(+0.0))); 378cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 379cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.expm1(-0.0))); 380cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 381cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -9.999950000166666E-6", 382cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -9.999950000166666E-6, StrictMath.expm1(-0.00001)); 383cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0145103074469635E60", 384cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0145103074469635E60, StrictMath.expm1(138.16951162)); 385cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 386cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 387cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .expm1(123456789123456789123456789.4521584223)); 388cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 389cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE)); 390cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath 391cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .expm1(Double.MIN_VALUE)); 392cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 393cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 394cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 395cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 396cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#floor(double) 397cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 398cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_floorD() { 399cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.floor(double) 400cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect floor for double", 401cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 78, StrictMath.floor(78.89), 0.0); 402cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect floor for double", 403cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -79, StrictMath.floor(-78.89), 0.0); 404cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 405cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 406cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 407cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#getExponent(double)} 408cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 409cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 410cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 411cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getExponent_D() { 412cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) { 413cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double number = GETEXPONENT_D_CASES[i]; 414cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int result = GETEXPONENT_D_RESULTS[i]; 415cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Wrong result of getExponent(double).", result, 416cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.getExponent(number)); 417cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 418cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 419cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 420cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.getExponent((Double) null); 421cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 422cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 423cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 424cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 425cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 426cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 427cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 428cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#getExponent(float)} 429cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 430cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 431cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 432cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getExponent_F() { 433cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) { 434cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final float number = GETEXPONENT_F_CASES[i]; 435cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int result = GETEXPONENT_F_RESULTS[i]; 436cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Wrong result of getExponent(float).", result, 437cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.getExponent(number)); 438cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 439cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 440cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.getExponent((Float) null); 441cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 442cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 443cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 444cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 445cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 446cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 447cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 448cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#hypot(double, double) 449cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 450cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 451cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_hypot_DD() { 452cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special cases 453cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 454cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY, 455cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0)); 456cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 457cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY, 458cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 123.324)); 459cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 460cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587, 461cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY)); 462cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 463cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21, 464cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY)); 465cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 466cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY, 467cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY)); 468cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 469cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY, 470cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY)); 471cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(Double.NaN, 472cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 2342301.89843))); 473cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(-345.2680, 474cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NaN))); 475cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 476cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath 477cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .hypot(12322.12, -2396393.2258)); 478cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 138.16958070558556", 138.16958070558556, 479cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.hypot(-138.16951162, 0.13817035864)); 480cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.7976931348623157E308", 481cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35)); 482cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot( 483cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -5413.7185, Double.MIN_VALUE)); 484cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 485cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 486cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 487cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 488cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#IEEEremainder(double, double) 489cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 490cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_IEEEremainderDD() { 491cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.IEEEremainder(double, 492cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // double) 493cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder( 494cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0, 1.0), 0.0); 495cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue( 496cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "Incorrect remainder returned", 497cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2 498cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2); 499cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 500cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 501cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 502cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#log(double) 503cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 504cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_logD() { 505cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.log(double) 506cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (double d = 10; d >= -10; d -= 0.5) { 507cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double answer = StrictMath.log(StrictMath.exp(d)); 508cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Answer does not equal expected answer for d = " + d 509cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath + " answer = " + answer, 510cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.abs(answer - d) <= StrictMath 511cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .abs(d * 0.00000001)); 512cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 513cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 514cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 515cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 516cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#log10(double) 517cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 518cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 519cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_log10_D() { 520cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special cases 521cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath 522cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log10(Double.NaN))); 523cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath 524cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log10(-2541.05745687234187532))); 525cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 526cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 527cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log10(Double.POSITIVE_INFINITY)); 528cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return NEGATIVE_INFINITY", 529cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath.log10(0.0)); 530cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return NEGATIVE_INFINITY", 531cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0)); 532cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return NEGATIVE_INFINITY", 533cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0)); 534cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath 535cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .pow(10, 14))); 536cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 537cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 3.7389561269540406", 3.7389561269540406, 538cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log10(5482.2158)); 539cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 14.661551142893833", 14.661551142893833, 540cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log10(458723662312872.125782332587)); 541cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -0.9083828622192334", -0.9083828622192334, 542cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log10(0.12348583358871)); 543cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 308.25471555991675", 308.25471555991675, 544cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log10(Double.MAX_VALUE)); 545cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -323.3062153431158", -323.3062153431158, 546cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log10(Double.MIN_VALUE)); 547cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 548cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 549cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 550cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#log1p(double) 551cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 552cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 553cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_log1p_D() { 554cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special cases 555cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath 556cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log1p(Double.NaN))); 557cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double.isNaN(StrictMath 558cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log1p(-32.0482175))); 559cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 560cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 561cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .log1p(Double.POSITIVE_INFINITY)); 562cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 563cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.log1p(0.0))); 564cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 565cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.log1p(+0.0))); 566cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 567cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.log1p(-0.0))); 568cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 569cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -0.2941782295312541", -0.2941782295312541, 570cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log1p(-0.254856327)); 571cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 7.368050685564151", 7.368050685564151, 572cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log1p(1583.542)); 573cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 0.4633708685409921", 0.4633708685409921, 574cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log1p(0.5894227)); 575cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 709.782712893384", 709.782712893384, 576cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log1p(Double.MAX_VALUE)); 577cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, 578cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.log1p(Double.MIN_VALUE)); 579cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 580cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 581cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 582cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#max(double, double) 583cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 584cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_maxDD() { 585cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.max(double, double) 586cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max( 587cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.6000089, 1908897.6000089), 0D); 588cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0, 589cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.6000089), 0D); 590cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0, 591cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.6000089), 0D); 592cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 593cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 594cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 595cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 596cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#max(float, float) 597cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 598cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_maxFF() { 599cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method float java.lang.StrictMath.max(float, float) 600cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f, 601cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.600f) == 1908897.600f); 602cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float max value", StrictMath.max(2.0f, 603cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.600f) == 1908897.600f); 604cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float max value", StrictMath.max(-2.0f, 605cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.600f) == -2.0f); 606cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 607cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 608cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 609cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#max(int, int) 610cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 611cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_maxII() { 612cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method int java.lang.StrictMath.max(int, int) 613cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976, 614cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976)); 615cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int max value", 616cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976, StrictMath.max(20, 19088976)); 617cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int max value", 618cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -20, StrictMath.max(-20, -19088976)); 619cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 620cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 621cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 622cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#max(long, long) 623cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 624cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_maxJJ() { 625cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method long java.lang.StrictMath.max(long, long) 626cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L, 627cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976000089L)); 628cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20, 629cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976000089L)); 630cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long max value", -20, StrictMath.max(-20, 631cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -19088976000089L)); 632cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 633cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 634cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 635cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#min(double, double) 636cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 637cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_minDD() { 638cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.min(double, double) 639cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min( 640cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.6000089, 1908897.6000089), 0D); 641cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0, 642cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.6000089), 0D); 643cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0, 644cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.6000089), 0D); 645cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 646cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 647cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 648cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#min(float, float) 649cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 650cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_minFF() { 651cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method float java.lang.StrictMath.min(float, float) 652cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f, 653cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.600f) == -1908897.600f); 654cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float min value", StrictMath.min(2.0f, 655cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1908897.600f) == 2.0f); 656cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect float min value", StrictMath.min(-2.0f, 657cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1908897.600f) == -1908897.600f); 658cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 659cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 660cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 661cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#min(int, int) 662cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 663cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_minII() { 664cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method int java.lang.StrictMath.min(int, int) 665cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976, 666cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976)); 667cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int min value", 668cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20, StrictMath.min(20, 19088976)); 669cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect int min value", 670cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -19088976, StrictMath.min(-20, -19088976)); 671cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 672cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 673cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 674cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 675cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#min(long, long) 676cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 677cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_minJJ() { 678cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method long java.lang.StrictMath.min(long, long) 679cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L, 680cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976000089L)); 681cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long min value", 20, StrictMath.min(20, 682cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 19088976000089L)); 683cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20, 684cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -19088976000089L)); 685cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 686cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 687cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 688cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#nextAfter(double, double)} 689cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 690cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 691cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 692cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_nextAfter_DD() { 693cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for most cases without exception 694cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) { 695cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double start = NEXTAFTER_DD_START_CASES[i][0]; 696cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long nextUpBits = Double 697cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]); 698cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long nextDownBits = Double 699cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]); 700cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 701cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) { 702cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j]; 703cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long resultBits = Double.doubleToLongBits(StrictMath 704cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(start, direction)); 705cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long directionBits = Double.doubleToLongBits(direction); 706cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (direction > start) { 707cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next up-number.", 708cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath nextUpBits, resultBits); 709cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } else if (direction < start) { 710cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next down-number.", 711cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath nextDownBits, resultBits); 712cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } else { 713cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be direction.", directionBits, 714cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath resultBits); 715cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 716cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 717cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 718cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 719cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for cases with NaN 720cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) { 721cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 722cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(NEXTAFTER_DD_START_CASES[i][0], Double.NaN))); 723cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 724cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) { 725cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 726cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(Double.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i]))); 727cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 728cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 729cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(Double.NaN, Double.NaN))); 730cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 731cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 732cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 733cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter((Double) null, 2.3); 734cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 735cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 736cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 737cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 738cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 739cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter(2.3, (Double) null); 740cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 741cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 742cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 743cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 744cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 745cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter((Double) null, (Double) null); 746cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 747cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 748cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 749cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 750cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 751cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 752cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 753cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#nextAfter(float, double)} 754cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 755cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 756cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 757cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_nextAfter_FD() { 758cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for most cases without exception 759cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) { 760cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final float start = NEXTAFTER_FD_START_CASES[i][0]; 761cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int nextUpBits = Float 762cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]); 763cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int nextDownBits = Float 764cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]); 765cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 766cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) { 767cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j]; 768cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int resultBits = Float.floatToIntBits(StrictMath 769cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(start, direction)); 770cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (direction > start) { 771cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next up-number.", 772cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath nextUpBits, resultBits); 773cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } else if (direction < start) { 774cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next down-number.", 775cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath nextDownBits, resultBits); 776cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } else { 777cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int equivalentBits = Float.floatToIntBits(new Float( 778cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath direction)); 779cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals( 780cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "Result should be a number equivalent to direction.", 781cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath equivalentBits, resultBits); 782cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 783cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 784cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 785cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 786cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for cases with NaN 787cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) { 788cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 789cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(NEXTAFTER_FD_START_CASES[i][0], Float.NaN))); 790cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 791cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) { 792cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 793cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(Float.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i]))); 794cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 795cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 796cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextAfter(Float.NaN, Float.NaN))); 797cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 798cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 799cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 800cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter((Float) null, 2.3); 801cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 802cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 803cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 804cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 805cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 806cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter(2.3, (Float) null); 807cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 808cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 809cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 810cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 811cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 812cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextAfter((Float) null, (Float) null); 813cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 814cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 815cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 816cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 817cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 818cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 819cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 820cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#nextUp(double)} 821cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 822cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 823cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 824cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_nextUp_D() { 825cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // This method is semantically equivalent to nextAfter(d, 826cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Double.POSITIVE_INFINITY), 827cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // so we use the data of test_nextAfter_DD 828cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) { 829cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final double start = NEXTAFTER_DD_START_CASES[i][0]; 830cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long nextUpBits = Double 831cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]); 832cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final long resultBits = Double.doubleToLongBits(StrictMath 833cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextUp(start)); 834cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next up-number.", nextUpBits, 835cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath resultBits); 836cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 837cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 838cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for cases with NaN 839cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Double.isNaN(StrictMath 840cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextUp(Double.NaN))); 841cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 842cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 843cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 844cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextUp((Double) null); 845cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 846cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 847cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 848cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 849cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 850cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 851cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 852cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#nextUp(float)} 853cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 854cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 855cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 856cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_nextUp_F() { 857cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // This method is semantically equivalent to nextAfter(f, 858cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Float.POSITIVE_INFINITY), 859cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // so we use the data of test_nextAfter_FD 860cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) { 861cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final float start = NEXTAFTER_FD_START_CASES[i][0]; 862cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int nextUpBits = Float 863cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]); 864cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final int resultBits = Float.floatToIntBits(StrictMath 865cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextUp(start)); 866cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Result should be next up-number.", nextUpBits, 867cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath resultBits); 868cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 869cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 870cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for cases with NaN 871cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("The result should be NaN.", Float.isNaN(StrictMath 872cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .nextUp(Float.NaN))); 873cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 874cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 875cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 876cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.nextUp((Float) null); 877cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 878cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 879cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 880cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 881cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 882cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 883cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 884cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#pow(double, double) 885cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 886cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_powDD() { 887cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.pow(double, double) 888cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("pow returned incorrect value", 889cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath (long) StrictMath.pow(2, 8) == 256l); 890cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("pow returned incorrect value", 891cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.pow(2, -8) == 0.00390625d); 892cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 893cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 894cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 895cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#rint(double) 896cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 897cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_rintD() { 898cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.rint(double) 899cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Failed to round properly - up to odd", 900cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 3.0, StrictMath.rint(2.9), 0D); 901cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath 902cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .rint(Double.NaN))); 903cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Failed to round properly down to even", 2.0, StrictMath 904cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .rint(2.1), 0D); 905cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath 906cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .rint(2.5) == 2.0); 907cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 908cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 909cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 910cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#round(double) 911cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 912cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_roundD() { 913cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method long java.lang.StrictMath.round(double) 914cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect rounding of a float", 915cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -91, StrictMath.round(-90.89d)); 916cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 917cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 918cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 919cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#round(float) 920cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 921cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_roundF() { 922cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method int java.lang.StrictMath.round(float) 923cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect rounding of a float", 924cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -91, StrictMath.round(-90.89f)); 925cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 926cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 927cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 928cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#scalb(double, int)} 929cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 930cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 931cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 932cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_scalb_DI() { 933cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is normal 934cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(4.1422946304E7, StrictMath.scalb(1.2345, 25)); 935cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(3.679096698760986E-8, StrictMath.scalb(1.2345, -25)); 936cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.2345, StrictMath.scalb(1.2345, 0)); 937cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(7868514.304, StrictMath.scalb(0.2345, 25)); 938cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 939cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double normal = StrictMath.scalb(0.2345, -25); 940cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(6.98864459991455E-9, normal); 941cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision kept 942cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0.2345, StrictMath.scalb(normal, 25)); 943cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 944cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0.2345, StrictMath.scalb(0.2345, 0)); 945cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-4.1422946304E7, StrictMath.scalb(-1.2345, 25)); 946cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-6.98864459991455E-9, StrictMath.scalb(-0.2345, -25)); 947cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(2.0, StrictMath.scalb(Double.MIN_NORMAL / 2, 1024)); 948cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(64.0, StrictMath.scalb(Double.MIN_VALUE, 1080)); 949cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(234, StrictMath.getExponent(StrictMath.scalb(1.0, 234))); 950cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(3.9999999999999996, StrictMath.scalb(Double.MAX_VALUE, 951cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_EXPONENT)); 952cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 953cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is near infinity 954cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double halfMax = StrictMath.scalb(1.0, Double.MAX_EXPONENT); 955cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(8.98846567431158E307, halfMax); 956cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MAX_VALUE, halfMax - StrictMath.ulp(halfMax) 957cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath + halfMax); 958cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, halfMax + halfMax); 959cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.7976931348623155E308, StrictMath.scalb(1.0 - StrictMath 960cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(1.0), Double.MAX_EXPONENT + 1)); 961cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 962cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0 - StrictMath.ulp(1.0), Double.MAX_EXPONENT + 2)); 963cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 964cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath halfMax = StrictMath.scalb(-1.0, Double.MAX_EXPONENT); 965cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-8.98846567431158E307, halfMax); 966cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-Double.MAX_VALUE, halfMax + StrictMath.ulp(halfMax) 967cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath + halfMax); 968cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.NEGATIVE_INFINITY, halfMax + halfMax); 969cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 970cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(0.345, 1234)); 971cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath 972cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(44.345E102, 934)); 973cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(-44.345E102, 974cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 934)); 975cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 976cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 977cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_NORMAL / 2, 4000)); 978cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 979cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_VALUE, 8000)); 980cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 981cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MAX_VALUE, 1)); 982cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 983cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, 0)); 984cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb( 985cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, -1)); 986cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb( 987cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, -1)); 988cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb( 989cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, Double.MIN_EXPONENT)); 990cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 991cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is subnormal/zero 992cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath long posZeroBits = Double.doubleToLongBits(+0.0); 993cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath long negZeroBits = Double.doubleToLongBits(-0.0); 994cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 995cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath +0.0, Integer.MAX_VALUE))); 996cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 997cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath +0.0, -123))); 998cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 999cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath +0.0, 0))); 1000cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1001cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -0.0, 123))); 1002cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1003cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -0.0, Integer.MIN_VALUE))); 1004cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1005cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MIN_VALUE, StrictMath.scalb(1.0, -1074)); 1006cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(1.0, 1007cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1075))); 1008cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1009cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1.0, -1075))); 1010cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1011cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision lost 1012cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(StrictMath.scalb(21.405, -1078), StrictMath.scalb(21.405, 1013cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1079)); 1014cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MIN_VALUE, StrictMath.scalb(21.405, -1079)); 1015cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-Double.MIN_VALUE, StrictMath.scalb(-21.405, -1079)); 1016cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1017cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 21.405, -1080))); 1018cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1019cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -21.405, -1080))); 1020cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1021cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_VALUE, -1))); 1022cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1023cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Double.MIN_VALUE, -1))); 1024cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL, -52)); 1025cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1026cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_NORMAL, -53))); 1027cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1028cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Double.MIN_NORMAL, -53))); 1029cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MIN_VALUE, StrictMath 1030cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(Double.MAX_VALUE, -2098)); 1031cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1032cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MAX_VALUE, -2099))); 1033cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1034cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Double.MAX_VALUE, -2099))); 1035cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL / 3, 1036cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -51)); 1037cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1038cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_NORMAL / 3, -52))); 1039cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb( 1040cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Double.MIN_NORMAL / 3, -52))); 1041cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double subnormal = StrictMath.scalb(Double.MIN_NORMAL / 3, -25); 1042cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(2.2104123E-316, subnormal); 1043cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision lost 1044cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertFalse(Double.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 25)); 1045cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1046cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // NaN 1047cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 1))); 1048cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 0))); 1049cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, -120))); 1050cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1051cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1283457024, Double.doubleToLongBits(StrictMath.scalb( 1052cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.MIN_VALUE * 153, 23))); 1053cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-9223372035571318784L, Double.doubleToLongBits(StrictMath 1054cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(-Double.MIN_VALUE * 153, 23))); 1055cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(36908406321184768L, Double.doubleToLongBits(StrictMath 1056cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(Double.MIN_VALUE * 153, 52))); 1057cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-9186463630533591040L, Double.doubleToLongBits(StrictMath 1058cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(-Double.MIN_VALUE * 153, 52))); 1059cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1060cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 1061cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1062cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb((Double) null, (Integer) null); 1063cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1064cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1065cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1066cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1067cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1068cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb(1.0, (Integer) null); 1069cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1070cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1071cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1072cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1073cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1074cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb((Double) null, 1); 1075cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1076cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1077cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1078cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1079cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1080cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1081cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1082cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * {@link java.lang.StrictMath#scalb(float, int)} 1083cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 1084cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1085cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 1086cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_scalb_FI() { 1087cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is normal 1088cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(4.1422946304E7f, StrictMath.scalb(1.2345f, 25)); 1089cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(3.679096698760986E-8f, StrictMath.scalb(1.2345f, -25)); 1090cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.2345f, StrictMath.scalb(1.2345f, 0)); 1091cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(7868514.304f, StrictMath.scalb(0.2345f, 25)); 1092cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1093cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath float normal = StrictMath.scalb(0.2345f, -25); 1094cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(6.98864459991455E-9f, normal); 1095cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision kept 1096cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0.2345f, StrictMath.scalb(normal, 25)); 1097cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1098cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0.2345f, StrictMath.scalb(0.2345f, 0)); 1099cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-4.1422946304E7f, StrictMath.scalb(-1.2345f, 25)); 1100cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-6.98864459991455E-9f, StrictMath.scalb(-0.2345f, -25)); 1101cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(2.0f, StrictMath.scalb(Float.MIN_NORMAL / 2, 128)); 1102cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(64.0f, StrictMath.scalb(Float.MIN_VALUE, 155)); 1103cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(34, StrictMath.getExponent(StrictMath.scalb(1.0f, 34))); 1104cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(3.9999998f, StrictMath.scalb(Float.MAX_VALUE, 1105cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_EXPONENT)); 1106cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1107cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is near infinity 1108cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath float halfMax = StrictMath.scalb(1.0f, Float.MAX_EXPONENT); 1109cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.7014118E38f, halfMax); 1110cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MAX_VALUE, halfMax - StrictMath.ulp(halfMax) 1111cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath + halfMax); 1112cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, halfMax + halfMax); 1113cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(3.4028233E38f, StrictMath.scalb(1.0f - StrictMath 1114cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(1.0f), Float.MAX_EXPONENT + 1)); 1115cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb( 1116cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0f - StrictMath.ulp(1.0f), Float.MAX_EXPONENT + 2)); 1117cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1118cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath halfMax = StrictMath.scalb(-1.0f, Float.MAX_EXPONENT); 1119cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.7014118E38f, halfMax); 1120cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-Float.MAX_VALUE, halfMax + StrictMath.ulp(halfMax) 1121cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath + halfMax); 1122cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.NEGATIVE_INFINITY, halfMax + halfMax); 1123cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1124cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(0.345f, 1234)); 1125cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(44.345E10f, 934)); 1126cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.NEGATIVE_INFINITY, StrictMath 1127cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .scalb(-44.345E10f, 934)); 1128cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1129cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb( 1130cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_NORMAL / 2, 400)); 1131cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MIN_VALUE, 1132cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 800)); 1133cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MAX_VALUE, 1134cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1)); 1135cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb( 1136cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.POSITIVE_INFINITY, 0)); 1137cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb( 1138cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.POSITIVE_INFINITY, -1)); 1139cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb( 1140cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.NEGATIVE_INFINITY, -1)); 1141cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb( 1142cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.NEGATIVE_INFINITY, Float.MIN_EXPONENT)); 1143cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1144cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // result is subnormal/zero 1145cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath int posZeroBits = Float.floatToIntBits(+0.0f); 1146cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath int negZeroBits = Float.floatToIntBits(-0.0f); 1147cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f, 1148cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Integer.MAX_VALUE))); 1149cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f, 1150cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -123))); 1151cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f, 1152cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 0))); 1153cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f, 1154cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 123))); 1155cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f, 1156cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Integer.MIN_VALUE))); 1157cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1158cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MIN_VALUE, StrictMath.scalb(1.0f, -149)); 1159cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(1.0f, 1160cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -150))); 1161cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-1.0f, 1162cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -150))); 1163cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1164cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision lost 1165cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(StrictMath.scalb(21.405f, -154), StrictMath.scalb(21.405f, 1166cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -153)); 1167cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MIN_VALUE, StrictMath.scalb(21.405f, -154)); 1168cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-Float.MIN_VALUE, StrictMath.scalb(-21.405f, -154)); 1169cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb( 1170cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 21.405f, -155))); 1171cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb( 1172cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -21.405f, -155))); 1173cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb( 1174cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_VALUE, -1))); 1175cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb( 1176cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MIN_VALUE, -1))); 1177cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL, -23)); 1178cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb( 1179cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_NORMAL, -24))); 1180cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb( 1181cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MIN_NORMAL, -24))); 1182cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MAX_VALUE, -277)); 1183cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb( 1184cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MAX_VALUE, -278))); 1185cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb( 1186cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MAX_VALUE, -278))); 1187cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL / 3, 1188cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -22)); 1189cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb( 1190cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_NORMAL / 3, -23))); 1191cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb( 1192cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MIN_NORMAL / 3, -23))); 1193cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath float subnormal = StrictMath.scalb(Float.MIN_NORMAL / 3, -11); 1194cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.913E-42f, subnormal); 1195cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // precision lost 1196cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertFalse(Float.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 11)); 1197cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1198cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(68747264, Float.floatToIntBits(StrictMath.scalb( 1199cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_VALUE * 153, 23))); 1200cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-2078736384, Float.floatToIntBits(StrictMath.scalb( 1201cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MIN_VALUE * 153, 23))); 1202cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1203cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(4896, Float.floatToIntBits(StrictMath.scalb( 1204cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Float.MIN_VALUE * 153, 5))); 1205cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-2147478752, Float.floatToIntBits(StrictMath.scalb( 1206cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -Float.MIN_VALUE * 153, 5))); 1207cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1208cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // NaN 1209cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 1))); 1210cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 0))); 1211cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, -120))); 1212cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1213cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // test for exception 1214cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1215cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb((Float) null, (Integer) null); 1216cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1217cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1218cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1219cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1220cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1221cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb(1.0f, (Integer) null); 1222cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1223cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1224cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1225cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1226cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 1227cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.scalb((Float) null, 1); 1228cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Should throw NullPointerException"); 1229cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 1230cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 1231cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1232cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1233cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1234cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1235cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#signum(double) 1236cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1237cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_signum_D() { 1238cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.signum(Double.NaN))); 1239cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 1240cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.signum(0.0))); 1241cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 1242cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.signum(+0.0))); 1243cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 1244cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.signum(-0.0))); 1245cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1246cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.signum(253681.2187962), 0D); 1247cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D); 1248cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D); 1249cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D); 1250cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1251cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D); 1252cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D); 1253cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D); 1254cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D); 1255cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D); 1256cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D); 1257cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1258cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1259cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1260cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1261cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#signum(float) 1262cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1263cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_signum_F() { 1264cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Float.isNaN(StrictMath.signum(Float.NaN))); 1265cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.floatToIntBits(0.0f), Float 1266cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(StrictMath.signum(0.0f))); 1267cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.floatToIntBits(+0.0f), Float 1268cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(StrictMath.signum(+0.0f))); 1269cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Float.floatToIntBits(-0.0f), Float 1270cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .floatToIntBits(StrictMath.signum(-0.0f))); 1271cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1272cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f); 1273cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f); 1274cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f); 1275cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f); 1276cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1277cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f); 1278cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f); 1279cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f); 1280cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f); 1281cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f); 1282cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f); 1283cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1284cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1285cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1286cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#sin(double) 1287cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1288cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_sinD() { 1289cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.sin(double) 1290cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath 1291cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .asin(OPP / HYP)) == OPP / HYP); 1292cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1293cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1294cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1295cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#sinh(double) 1296cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1297cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_sinh_D() { 1298cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special situations 1299cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN))); 1300cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 1301cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath 1302cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .sinh(Double.POSITIVE_INFINITY), 0D); 1303cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return NEGATIVE_INFINITY", 1304cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath 1305cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .sinh(Double.NEGATIVE_INFINITY), 0D); 1306cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 1307cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.sinh(0.0))); 1308cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 1309cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.sinh(+0.0))); 1310cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 1311cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.sinh(-0.0))); 1312cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1313cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 1314cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D); 1315cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return NEGATIVE_INFINITY", 1316cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D); 1317cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0000000000001666E-6", 1318cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D); 1319cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -1.0000000000001666E-6", 1320cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D); 1321cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 5.115386441963859", 5.115386441963859, 1322cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.sinh(2.33482), 0D); 1323cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return POSITIVE_INFINITY", 1324cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D); 1325cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath 1326cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .sinh(Double.MIN_VALUE), 0D); 1327cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1328cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1329cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1330cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#sqrt(double) 1331cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1332cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_sqrtD() { 1333cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.sqrt(double) 1334cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect root returned1", 1335cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0); 1336cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0); 1337cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1338cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1339cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1340cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#tan(double) 1341cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1342cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_tanD() { 1343cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for method double java.lang.StrictMath.tan(double) 1344cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue( 1345cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "Returned incorrect tangent: ", 1346cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.tan(StrictMath.atan(1.0)) <= 1.0 1347cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1); 1348cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1349cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1350cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1351cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#tanh(double) 1352cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1353cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_tanh_D() { 1354cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special situations 1355cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN))); 1356cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return +1.0", +1.0, StrictMath 1357cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .tanh(Double.POSITIVE_INFINITY), 0D); 1358cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -1.0", -1.0, StrictMath 1359cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .tanh(Double.NEGATIVE_INFINITY), 0D); 1360cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(0.0), Double 1361cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.tanh(0.0))); 1362cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(+0.0), Double 1363cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.tanh(+0.0))); 1364cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(Double.doubleToLongBits(-0.0), Double 1365cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .doubleToLongBits(StrictMath.tanh(-0.0))); 1366cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1367cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D); 1368cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D); 1369cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 9.999999999996666E-7", 1370cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 9.999999999996666E-7, StrictMath.tanh(0.000001), 0D); 1371cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 0.981422884124941", 0.981422884124941, 1372cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.tanh(2.33482), 0D); 1373cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 1.0", 1.0, StrictMath 1374cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .tanh(Double.MAX_VALUE), 0D); 1375cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath 1376cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .tanh(Double.MIN_VALUE), 0D); 1377cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1378cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1379cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1380cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#random() 1381cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1382cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_random() { 1383cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // There isn't a place for these tests so just stick them here 1384cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Wrong value E", 1385cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 4613303445314885481L, Double.doubleToLongBits(StrictMath.E)); 1386cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Wrong value PI", 1387cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI)); 1388cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1389cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (int i = 500; i >= 0; i--) { 1390cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double d = StrictMath.random(); 1391cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Generated number is out of range: " + d, d >= 0.0 1392cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath && d < 1.0); 1393cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1394cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1395cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1396cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1397cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#toRadians(double) 1398cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1399cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_toRadiansD() { 1400cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (double d = 500; d >= 0; d -= 1.0) { 1401cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double converted = StrictMath.toDegrees(StrictMath.toRadians(d)); 1402cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Converted number not equal to original. d = " + d, 1403cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath converted >= d * 0.99999999 && converted <= d * 1.00000001); 1404cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1405cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1406cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1407cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1408cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#toDegrees(double) 1409cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1410cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_toDegreesD() { 1411cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath for (double d = 500; d >= 0; d -= 1.0) { 1412cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath double converted = StrictMath.toRadians(StrictMath.toDegrees(d)); 1413cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Converted number not equal to original. d = " + d, 1414cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath converted >= d * 0.99999999 && converted <= d * 1.00000001); 1415cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1416cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1417cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1418cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1419cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#ulp(double) 1420cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1421cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 1422cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ulp_D() { 1423cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special cases 1424cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Double 1425cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .isNaN(StrictMath.ulp(Double.NaN))); 1426cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, 1427cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(Double.POSITIVE_INFINITY), 0D); 1428cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, 1429cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D); 1430cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 1431cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(0.0), 0D); 1432cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 1433cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(+0.0), 0D); 1434cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 1435cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-0.0), 0D); 1436cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", StrictMath.pow(2, 971), 1437cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(Double.MAX_VALUE), 0D); 1438cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", StrictMath.pow(2, 971), 1439cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(-Double.MAX_VALUE), 0D); 1440cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1441cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 1442cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(Double.MIN_VALUE), 0D); 1443cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 1444cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-Double.MIN_VALUE), 0D); 1445cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1446cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 2.220446049250313E-16, 1447cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(1.0), 0D); 1448cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 2.220446049250313E-16, 1449cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(-1.0), 0D); 1450cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 2.2737367544323206E-13, 1451cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(1153.0), 0D); 1452cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1453cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1454cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 1455cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.lang.StrictMath#ulp(float) 1456cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 1457cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath @SuppressWarnings("boxing") 1458cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ulp_f() { 1459cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for special cases 1460cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN))); 1461cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, 1462cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(Float.POSITIVE_INFINITY), 0f); 1463cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, 1464cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f); 1465cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 1466cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(0.0f), 0f); 1467cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 1468cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(+0.0f), 0f); 1469cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 1470cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-0.0f), 0f); 1471cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 2.028241E31f, StrictMath 1472cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(Float.MAX_VALUE), 0f); 1473cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 2.028241E31f, StrictMath 1474cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-Float.MAX_VALUE), 0f); 1475cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1476cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 1.4E-45f, StrictMath 1477cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(Float.MIN_VALUE), 0f); 1478cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 1.4E-45f, StrictMath 1479cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-Float.MIN_VALUE), 0f); 1480cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 1481cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath 1482cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(1.0f), 0f); 1483cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath 1484cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(-1.0f), 0f); 1485cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath 1486cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(1153.0f), 0f); 1487cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Returned incorrect value", 5.6E-45f, Math 1488cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .ulp(9.403954E-38f), 0f); 1489cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 1490cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath} 1491