Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: tests/MathTest.cpp

Issue 1251423002: Update fallback rsqrt implementation to use optimal constants. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkFloatingPoint.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MathTest.cpp
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 772bade1856cbe8b70bbc32eb8125419047372c9..3c2bc644073ddcd211e732c645a28fd894a4b00d 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -382,6 +382,40 @@ static void unittest_half(skiatest::Reporter* reporter) {
}
+static void test_rsqrt(skiatest::Reporter* reporter) {
+ const float maxRelativeError = 6.50196699e-4f;
+
+ // test close to 0 up to 1
+ float input = 0.000001f;
+ for (int i = 0; i < 1000; ++i) {
+ float exact = 1.0f/sk_float_sqrt(input);
+ float estimate = sk_float_rsqrt(input);
+ float relativeError = sk_float_abs(exact - estimate)/exact;
+ REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
+ input += 0.001f;
+ }
+
+ // test 1 to ~100
+ input = 1.0f;
+ for (int i = 0; i < 1000; ++i) {
+ float exact = 1.0f/sk_float_sqrt(input);
+ float estimate = sk_float_rsqrt(input);
+ float relativeError = sk_float_abs(exact - estimate)/exact;
+ REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
+ input += 0.01f;
+ }
+
+ // test some big numbers
+ input = 1000000.0f;
+ for (int i = 0; i < 100; ++i) {
+ float exact = 1.0f/sk_float_sqrt(input);
+ float estimate = sk_float_rsqrt(input);
+ float relativeError = sk_float_abs(exact - estimate)/exact;
+ REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
+ input += 754326.f;
+ }
+}
+
static void test_muldiv255(skiatest::Reporter* reporter) {
for (int a = 0; a <= 255; a++) {
for (int b = 0; b <= 255; b++) {
@@ -521,6 +555,7 @@ DEF_TEST(Math, reporter) {
unittest_fastfloat(reporter);
unittest_isfinite(reporter);
unittest_half(reporter);
+ test_rsqrt(reporter);
for (i = 0; i < 10000; i++) {
SkFixed numer = rand.nextS();
« no previous file with comments | « include/core/SkFloatingPoint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698