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

Side by Side Diff: tests/MathTest.cpp

Issue 1707023002: Add pinned versions of *ToFixed. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Rebase. Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « include/private/SkFixed.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "float.h"
9
8 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
9 #include "SkEndian.h" 11 #include "SkEndian.h"
10 #include "SkFixed.h" 12 #include "SkFixed.h"
11 #include "SkFloatBits.h" 13 #include "SkFloatBits.h"
12 #include "SkFloatingPoint.h" 14 #include "SkFloatingPoint.h"
13 #include "SkHalf.h" 15 #include "SkHalf.h"
14 #include "SkMathPriv.h" 16 #include "SkMathPriv.h"
15 #include "SkPoint.h" 17 #include "SkPoint.h"
16 #include "SkRandom.h" 18 #include "SkRandom.h"
17 #include "Test.h" 19 #include "Test.h"
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 test_divmod<int16_t>(r); 692 test_divmod<int16_t>(r);
691 } 693 }
692 694
693 DEF_TEST(divmod_s32, r) { 695 DEF_TEST(divmod_s32, r) {
694 test_divmod<int32_t>(r); 696 test_divmod<int32_t>(r);
695 } 697 }
696 698
697 DEF_TEST(divmod_s64, r) { 699 DEF_TEST(divmod_s64, r) {
698 test_divmod<int64_t>(r); 700 test_divmod<int64_t>(r);
699 } 701 }
702
703 DEF_TEST(PinToFixed, reporter) {
704 // double
705 REPORTER_ASSERT(reporter, 0 == SkDoublePinToFixed(0.0));
706 REPORTER_ASSERT(reporter, 0x10000 == SkDoublePinToFixed(1.0));
707 REPORTER_ASSERT(reporter, 0x7FFFFFFE == SkDoublePinToFixed(32767.999984741)) ;
708 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32767.999984742)) ;
709 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32767.999999999)) ;
710 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(32768.0));
711 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(5e10));
712 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkDoublePinToFixed(DBL_MAX));
713 REPORTER_ASSERT(reporter, -0x10000 == SkDoublePinToFixed(-1.0));
714 // SK_FixedMin is defined to be -SK_FixedMax.
715 REPORTER_ASSERT(reporter, -0x7FFFFFFE == SkDoublePinToFixed(-32767.999984741 ));
716 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32767.999984742 ));
717 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32767.999999999 ));
718 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-32768.0));
719 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-5e10));
720 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkDoublePinToFixed(-DBL_MAX));
721
722 // float
723 REPORTER_ASSERT(reporter, 0 == SkFloatPinToFixed(0.0f));
724 REPORTER_ASSERT(reporter, 0x10000 == SkFloatPinToFixed(1.0f));
725 // SkFixed has more precision than float near SK_FixedMax, so SkFloatPinToFi xed will never
726 // produce output between 0x7FFFFF80 and 0x7FFFFFFF.
727 REPORTER_ASSERT(reporter, 0x7FFFFF80 == SkFloatPinToFixed(32767.9990f));
728 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(32767.9991f));
729 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(32768.0f));
730 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(5e10f));
731 REPORTER_ASSERT(reporter, 0x7FFFFFFF == SkFloatPinToFixed(FLT_MAX));
732 REPORTER_ASSERT(reporter, -0x10000 == SkFloatPinToFixed(-1.0f));
733 // SK_FixedMin is defined to be -SK_FixedMax.
734 REPORTER_ASSERT(reporter, -0x7FFFFF80 == SkFloatPinToFixed(-32767.9990f));
735 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-32767.9991f));
736 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-32768.0f));
737 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-5e10f));
738 REPORTER_ASSERT(reporter, -0x7FFFFFFF == SkFloatPinToFixed(-FLT_MAX));
739 }
OLDNEW
« no previous file with comments | « include/private/SkFixed.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698