-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8338694: x86_64 intrinsic for tanh using libm #20657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0328101
79766f1
4739ad4
39350a3
4aa52bf
d4ddc31
ca3314c
c151123
d249508
e908eb4
7416537
3664be1
b438555
1ee4c1f
aa16389
5da2754
4dc2e36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| */ | ||
|
|
||
| import static java.lang.Double.longBitsToDouble; | ||
| import java.util.Random; | ||
|
|
||
| public class HyperbolicTests { | ||
| private HyperbolicTests(){} | ||
|
|
@@ -972,6 +973,46 @@ static int testTanh() { | |
| return failures; | ||
| } | ||
|
|
||
| /** | ||
| * Test accuracy of Math.tanh intrinsic using StrictMath.tanh as the reference. | ||
| * The specified accuracy is 2.5 ulps. | ||
| * | ||
| */ | ||
| static int testTanhIntrinsicWithReference() { | ||
| double b1 = 0.02; | ||
| double b2 = 5.1; | ||
| double b3 = 55 * Math.log(2)/2; // ~19.062 | ||
|
|
||
| int failures = 0; | ||
|
|
||
| failures += testTanhWithReferenceInRange(0.0, b3 + 2.0); // entire range | ||
| failures += testTanhWithReferenceInRange(b1 - 0.005, 0.01); | ||
| failures += testTanhWithReferenceInRange(b2 - 0.5, 1.0); | ||
| failures += testTanhWithReferenceInRange(b3 - 2.5, 5.0); | ||
|
|
||
| return failures; | ||
|
|
||
| } | ||
|
|
||
| static int testTanhWithReferenceInRange(double min, double range) { | ||
| int failures = 0; | ||
|
|
||
| double [] testCases = new double[500]; | ||
|
|
||
| Random rand = new Random(0); | ||
| for (int i = 0; i < testCases.length; i++) { | ||
| testCases[i] = min + range * rand.nextDouble(); | ||
| } | ||
|
|
||
| for(int i = 0; i < testCases.length; i++) { | ||
vamsi-parasa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| double testCase = testCases[i]; | ||
| failures += testTanhWithReferenceUlpDiff(testCase, StrictMath.tanh(testCase), 2.5); | ||
|
||
| } | ||
|
|
||
| return failures; | ||
| } | ||
|
|
||
|
|
||
| public static int testTanhCaseWithTolerance(double input, | ||
| double expected, | ||
| double tolerance) { | ||
|
|
@@ -996,4 +1037,15 @@ public static int testTanhCaseWithUlpDiff(double input, | |
| failures += Tests.testUlpDiffWithAbsBound("StrictMath.tanh", -input, StrictMath::tanh, -expected, ulps, 1.0); | ||
| return failures; | ||
| } | ||
|
|
||
| public static int testTanhWithReferenceUlpDiff(double input, | ||
| double expected, | ||
| double ulps) { | ||
| int failures = 0; | ||
|
|
||
| failures += Tests.testUlpDiffWithAbsBound("Math.tanh", input, Math::tanh, expected, ulps, 1.0); | ||
| failures += Tests.testUlpDiffWithAbsBound("Math.tanh", -input, Math::tanh, -expected, ulps, 1.0); | ||
|
|
||
| return failures; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to use StrictMath.log here or, better use, precompute the value as a constant and document its conceptual origin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the updated code which uses the precomputed value of
b3.