249 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
250 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
251 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
252 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
253 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
254 {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
255 };
256
257 for(int i = 0; i < specialTestCases.length; i++) {
258 failures += testSinhCaseWithUlpDiff(specialTestCases[i][0],
259 specialTestCases[i][1],
260 0.0);
261 }
262
263 // For powers of 2 less than 2^(-27), the second and
264 // subsequent terms of the Taylor series expansion will get
265 // rounded away since |n-n^3| > 53, the binary precision of a
266 // double significand.
267
268 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
269 double d = FpUtils.scalb(2.0, i);
270
271 // Result and expected are the same.
272 failures += testSinhCaseWithUlpDiff(d, d, 2.5);
273 }
274
275 // For values of x larger than 22, the e^(-x) term is
276 // insignificant to the floating-point result. Util exp(x)
277 // overflows around 709.8, sinh(x) ~= exp(x)/2; will will test
278 // 10000 values in this range.
279
280 long trans22 = Double.doubleToLongBits(22.0);
281 // (approximately) largest value such that exp shouldn't
282 // overflow
283 long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
284
285 for(long i = trans22;
286 i < transExpOvfl;
287 i +=(transExpOvfl-trans22)/10000) {
288
289 double d = Double.longBitsToDouble(i);
327 *
328 * than exp(x+offset) alone. (The expected result cannot be
329 * computed as exp(x)*exp(offset) since exp(x) by itself would
330 * overflow to infinity.)
331 */
332 double offset = StrictMath.log(0.5);
333 for(long i = transExpOvfl+1; i < transSinhOvfl;
334 i += (transSinhOvfl-transExpOvfl)/1000 ) {
335 double input = Double.longBitsToDouble(i);
336
337 double expected =
338 StrictMath.exp(input + offset) *
339 StrictMath.exp( offset - ((input + offset) - input) );
340
341 failures += testSinhCaseWithUlpDiff(input, expected, 4.0);
342 }
343
344 // sinh(x) overflows for values greater than 710; in
345 // particular, it overflows for all 2^i, i > 10.
346 for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
347 double d = FpUtils.scalb(2.0, i);
348
349 // Result and expected are the same.
350 failures += testSinhCaseWithUlpDiff(d,
351 Double.POSITIVE_INFINITY, 0.0);
352 }
353
354 return failures;
355 }
356
357 public static int testSinhCaseWithTolerance(double input,
358 double expected,
359 double tolerance) {
360 int failures = 0;
361 failures += Tests.testTolerance("Math.sinh(double)",
362 input, Math.sinh(input),
363 expected, tolerance);
364 failures += Tests.testTolerance("Math.sinh(double)",
365 -input, Math.sinh(-input),
366 -expected, tolerance);
367
608 {Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
609 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
610 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
611 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
612 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
613 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
614 {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
615 };
616
617 for(int i = 0; i < specialTestCases.length; i++ ) {
618 failures += testCoshCaseWithUlpDiff(specialTestCases[i][0],
619 specialTestCases[i][1],
620 0.0);
621 }
622
623 // For powers of 2 less than 2^(-27), the second and
624 // subsequent terms of the Taylor series expansion will get
625 // rounded.
626
627 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
628 double d = FpUtils.scalb(2.0, i);
629
630 // Result and expected are the same.
631 failures += testCoshCaseWithUlpDiff(d, 1.0, 2.5);
632 }
633
634 // For values of x larger than 22, the e^(-x) term is
635 // insignificant to the floating-point result. Util exp(x)
636 // overflows around 709.8, cosh(x) ~= exp(x)/2; will will test
637 // 10000 values in this range.
638
639 long trans22 = Double.doubleToLongBits(22.0);
640 // (approximately) largest value such that exp shouldn't
641 // overflow
642 long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
643
644 for(long i = trans22;
645 i < transExpOvfl;
646 i +=(transExpOvfl-trans22)/10000) {
647
648 double d = Double.longBitsToDouble(i);
686 *
687 * than exp(x+offset) alone. (The expected result cannot be
688 * computed as exp(x)*exp(offset) since exp(x) by itself would
689 * overflow to infinity.)
690 */
691 double offset = StrictMath.log(0.5);
692 for(long i = transExpOvfl+1; i < transCoshOvfl;
693 i += (transCoshOvfl-transExpOvfl)/1000 ) {
694 double input = Double.longBitsToDouble(i);
695
696 double expected =
697 StrictMath.exp(input + offset) *
698 StrictMath.exp( offset - ((input + offset) - input) );
699
700 failures += testCoshCaseWithUlpDiff(input, expected, 4.0);
701 }
702
703 // cosh(x) overflows for values greater than 710; in
704 // particular, it overflows for all 2^i, i > 10.
705 for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
706 double d = FpUtils.scalb(2.0, i);
707
708 // Result and expected are the same.
709 failures += testCoshCaseWithUlpDiff(d,
710 Double.POSITIVE_INFINITY, 0.0);
711 }
712 return failures;
713 }
714
715 public static int testCoshCaseWithTolerance(double input,
716 double expected,
717 double tolerance) {
718 int failures = 0;
719 failures += Tests.testTolerance("Math.cosh(double)",
720 input, Math.cosh(input),
721 expected, tolerance);
722 failures += Tests.testTolerance("Math.cosh(double)",
723 -input, Math.cosh(-input),
724 expected, tolerance);
725
726 failures += Tests.testTolerance("StrictMath.cosh(double)",
967 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
968 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
969 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
970 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
971 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
972 {Double.POSITIVE_INFINITY, 1.0}
973 };
974
975 for(int i = 0; i < specialTestCases.length; i++) {
976 failures += testTanhCaseWithUlpDiff(specialTestCases[i][0],
977 specialTestCases[i][1],
978 0.0);
979 }
980
981 // For powers of 2 less than 2^(-27), the second and
982 // subsequent terms of the Taylor series expansion will get
983 // rounded away since |n-n^3| > 53, the binary precision of a
984 // double significand.
985
986 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
987 double d = FpUtils.scalb(2.0, i);
988
989 // Result and expected are the same.
990 failures += testTanhCaseWithUlpDiff(d, d, 2.5);
991 }
992
993 // For values of x larger than 22, tanh(x) is 1.0 in double
994 // floating-point arithmetic.
995
996 for(int i = 22; i < 32; i++) {
997 failures += testTanhCaseWithUlpDiff(i, 1.0, 2.5);
998 }
999
1000 for(int i = 5; i <= DoubleConsts.MAX_EXPONENT; i++) {
1001 double d = FpUtils.scalb(2.0, i);
1002
1003 failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5);
1004 }
1005
1006 return failures;
1007 }
1008
1009 public static int testTanhCaseWithTolerance(double input,
1010 double expected,
1011 double tolerance) {
1012 int failures = 0;
1013 failures += Tests.testTolerance("Math.tanh(double",
1014 input, Math.tanh(input),
1015 expected, tolerance);
1016 failures += Tests.testTolerance("Math.tanh(double",
1017 -input, Math.tanh(-input),
1018 -expected, tolerance);
1019
1020 failures += Tests.testTolerance("StrictMath.tanh(double",
1021 input, StrictMath.tanh(input),
|
249 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
250 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
251 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
252 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
253 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
254 {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
255 };
256
257 for(int i = 0; i < specialTestCases.length; i++) {
258 failures += testSinhCaseWithUlpDiff(specialTestCases[i][0],
259 specialTestCases[i][1],
260 0.0);
261 }
262
263 // For powers of 2 less than 2^(-27), the second and
264 // subsequent terms of the Taylor series expansion will get
265 // rounded away since |n-n^3| > 53, the binary precision of a
266 // double significand.
267
268 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
269 double d = Math.scalb(2.0, i);
270
271 // Result and expected are the same.
272 failures += testSinhCaseWithUlpDiff(d, d, 2.5);
273 }
274
275 // For values of x larger than 22, the e^(-x) term is
276 // insignificant to the floating-point result. Util exp(x)
277 // overflows around 709.8, sinh(x) ~= exp(x)/2; will will test
278 // 10000 values in this range.
279
280 long trans22 = Double.doubleToLongBits(22.0);
281 // (approximately) largest value such that exp shouldn't
282 // overflow
283 long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
284
285 for(long i = trans22;
286 i < transExpOvfl;
287 i +=(transExpOvfl-trans22)/10000) {
288
289 double d = Double.longBitsToDouble(i);
327 *
328 * than exp(x+offset) alone. (The expected result cannot be
329 * computed as exp(x)*exp(offset) since exp(x) by itself would
330 * overflow to infinity.)
331 */
332 double offset = StrictMath.log(0.5);
333 for(long i = transExpOvfl+1; i < transSinhOvfl;
334 i += (transSinhOvfl-transExpOvfl)/1000 ) {
335 double input = Double.longBitsToDouble(i);
336
337 double expected =
338 StrictMath.exp(input + offset) *
339 StrictMath.exp( offset - ((input + offset) - input) );
340
341 failures += testSinhCaseWithUlpDiff(input, expected, 4.0);
342 }
343
344 // sinh(x) overflows for values greater than 710; in
345 // particular, it overflows for all 2^i, i > 10.
346 for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
347 double d = Math.scalb(2.0, i);
348
349 // Result and expected are the same.
350 failures += testSinhCaseWithUlpDiff(d,
351 Double.POSITIVE_INFINITY, 0.0);
352 }
353
354 return failures;
355 }
356
357 public static int testSinhCaseWithTolerance(double input,
358 double expected,
359 double tolerance) {
360 int failures = 0;
361 failures += Tests.testTolerance("Math.sinh(double)",
362 input, Math.sinh(input),
363 expected, tolerance);
364 failures += Tests.testTolerance("Math.sinh(double)",
365 -input, Math.sinh(-input),
366 -expected, tolerance);
367
608 {Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
609 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
610 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
611 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
612 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
613 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
614 {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
615 };
616
617 for(int i = 0; i < specialTestCases.length; i++ ) {
618 failures += testCoshCaseWithUlpDiff(specialTestCases[i][0],
619 specialTestCases[i][1],
620 0.0);
621 }
622
623 // For powers of 2 less than 2^(-27), the second and
624 // subsequent terms of the Taylor series expansion will get
625 // rounded.
626
627 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
628 double d = Math.scalb(2.0, i);
629
630 // Result and expected are the same.
631 failures += testCoshCaseWithUlpDiff(d, 1.0, 2.5);
632 }
633
634 // For values of x larger than 22, the e^(-x) term is
635 // insignificant to the floating-point result. Util exp(x)
636 // overflows around 709.8, cosh(x) ~= exp(x)/2; will will test
637 // 10000 values in this range.
638
639 long trans22 = Double.doubleToLongBits(22.0);
640 // (approximately) largest value such that exp shouldn't
641 // overflow
642 long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
643
644 for(long i = trans22;
645 i < transExpOvfl;
646 i +=(transExpOvfl-trans22)/10000) {
647
648 double d = Double.longBitsToDouble(i);
686 *
687 * than exp(x+offset) alone. (The expected result cannot be
688 * computed as exp(x)*exp(offset) since exp(x) by itself would
689 * overflow to infinity.)
690 */
691 double offset = StrictMath.log(0.5);
692 for(long i = transExpOvfl+1; i < transCoshOvfl;
693 i += (transCoshOvfl-transExpOvfl)/1000 ) {
694 double input = Double.longBitsToDouble(i);
695
696 double expected =
697 StrictMath.exp(input + offset) *
698 StrictMath.exp( offset - ((input + offset) - input) );
699
700 failures += testCoshCaseWithUlpDiff(input, expected, 4.0);
701 }
702
703 // cosh(x) overflows for values greater than 710; in
704 // particular, it overflows for all 2^i, i > 10.
705 for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
706 double d = Math.scalb(2.0, i);
707
708 // Result and expected are the same.
709 failures += testCoshCaseWithUlpDiff(d,
710 Double.POSITIVE_INFINITY, 0.0);
711 }
712 return failures;
713 }
714
715 public static int testCoshCaseWithTolerance(double input,
716 double expected,
717 double tolerance) {
718 int failures = 0;
719 failures += Tests.testTolerance("Math.cosh(double)",
720 input, Math.cosh(input),
721 expected, tolerance);
722 failures += Tests.testTolerance("Math.cosh(double)",
723 -input, Math.cosh(-input),
724 expected, tolerance);
725
726 failures += Tests.testTolerance("StrictMath.cosh(double)",
967 {Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
968 {Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
969 {Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
970 {Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
971 {Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
972 {Double.POSITIVE_INFINITY, 1.0}
973 };
974
975 for(int i = 0; i < specialTestCases.length; i++) {
976 failures += testTanhCaseWithUlpDiff(specialTestCases[i][0],
977 specialTestCases[i][1],
978 0.0);
979 }
980
981 // For powers of 2 less than 2^(-27), the second and
982 // subsequent terms of the Taylor series expansion will get
983 // rounded away since |n-n^3| > 53, the binary precision of a
984 // double significand.
985
986 for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
987 double d = Math.scalb(2.0, i);
988
989 // Result and expected are the same.
990 failures += testTanhCaseWithUlpDiff(d, d, 2.5);
991 }
992
993 // For values of x larger than 22, tanh(x) is 1.0 in double
994 // floating-point arithmetic.
995
996 for(int i = 22; i < 32; i++) {
997 failures += testTanhCaseWithUlpDiff(i, 1.0, 2.5);
998 }
999
1000 for(int i = 5; i <= DoubleConsts.MAX_EXPONENT; i++) {
1001 double d = Math.scalb(2.0, i);
1002
1003 failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5);
1004 }
1005
1006 return failures;
1007 }
1008
1009 public static int testTanhCaseWithTolerance(double input,
1010 double expected,
1011 double tolerance) {
1012 int failures = 0;
1013 failures += Tests.testTolerance("Math.tanh(double",
1014 input, Math.tanh(input),
1015 expected, tolerance);
1016 failures += Tests.testTolerance("Math.tanh(double",
1017 -input, Math.tanh(-input),
1018 -expected, tolerance);
1019
1020 failures += Tests.testTolerance("StrictMath.tanh(double",
1021 input, StrictMath.tanh(input),
|