From e07622386b10c158cb0cc653ace264e24c5702af Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 10 Oct 2017 14:49:35 -0400 Subject: clone saturating cast code for doubles Bug: skia: Change-Id: I4f35413995cf73c6f130476d6b36e530120aa7ed Reviewed-on: https://skia-review.googlesource.com/57901 Reviewed-by: Mike Klein Commit-Queue: Mike Reed --- tests/MathTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/MathTest.cpp') diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index fcbd63ddca..0d0bdce67d 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -693,3 +693,27 @@ DEF_TEST(FloatSaturate, reporter) { REPORTER_ASSERT(reporter, r.fExpectedInt == i); } } + +DEF_TEST(DoubleSaturate, reporter) { + const struct { + double fDouble; + int fExpectedInt; + } recs[] = { + { 0, 0 }, + { 100.5, 100 }, + { SK_MaxS32, SK_MaxS32 }, + { SK_MinS32, SK_MinS32 }, + { SK_MaxS32 - 1, SK_MaxS32 - 1 }, + { SK_MinS32 + 1, SK_MinS32 + 1 }, + { SK_MaxS32 * 100.0, SK_MaxS32 }, + { SK_MinS32 * 100.0, SK_MinS32 }, + { SK_ScalarInfinity, SK_MaxS32 }, + { SK_ScalarNegativeInfinity, SK_MinS32 }, + { SK_ScalarNaN, SK_MaxS32 }, + }; + + for (auto r : recs) { + int i = sk_double_saturate2int(r.fDouble); + REPORTER_ASSERT(reporter, r.fExpectedInt == i); + } +} -- cgit v1.2.3