OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "Test.h" | 8 #include "Test.h" |
9 | |
10 #include <cmath> | |
11 | |
9 #include "SkAutoPixmapStorage.h" | 12 #include "SkAutoPixmapStorage.h" |
10 #include "SkColor.h" | 13 #include "SkColor.h" |
11 #include "SkHalf.h" | 14 #include "SkHalf.h" |
12 #include "SkOpts.h" | 15 #include "SkOpts.h" |
13 #include "SkPixmap.h" | 16 #include "SkPixmap.h" |
14 #include "SkPM4f.h" | 17 #include "SkPM4f.h" |
15 #include "SkRandom.h" | 18 #include "SkRandom.h" |
16 | 19 |
17 static bool eq_within_half_float(float a, float b) { | 20 static bool eq_within_half_float(float a, float b) { |
18 const float kTolerance = 1.0f / (1 << (8 + 10)); | 21 const float kTolerance = 1.0f / (1 << (8 + 10)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 | 96 |
94 uint16_t expected = SkFloatToHalf(f); | 97 uint16_t expected = SkFloatToHalf(f); |
95 if (!is_finite(expected)) { | 98 if (!is_finite(expected)) { |
96 // _finite_ftz() only works for values that can be represented as a finite half float. | 99 // _finite_ftz() only works for values that can be represented as a finite half float. |
97 continue; | 100 continue; |
98 } | 101 } |
99 | 102 |
100 uint16_t alternate = expected; | 103 uint16_t alternate = expected; |
101 if (is_denorm(expected)) { | 104 if (is_denorm(expected)) { |
102 // _finite_ftz() may flush denorms to zero, and happens to keep the sign bit. | 105 // _finite_ftz() may flush denorms to zero, and happens to keep the sign bit. |
103 alternate = signbit(f) ? 0x8000 : 0x0000; | 106 alternate = std::signbit(f) ? 0x8000 : 0x0000; |
bungeman-skia
2016/11/09 19:30:56
This change seems unrelated?
herb_g
2016/11/09 20:20:05
Removed
| |
104 } | 107 } |
105 | 108 |
106 uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0]; | 109 uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0]; |
107 // _finite_ftz() may truncate instead of rounding, so it may be one too small. | 110 // _finite_ftz() may truncate instead of rounding, so it may be one too small. |
108 REPORTER_ASSERT(r, actual == expected || actual == expected - 1 || | 111 REPORTER_ASSERT(r, actual == expected || actual == expected - 1 || |
109 actual == alternate || actual == alternate - 1); | 112 actual == alternate || actual == alternate - 1); |
110 } | 113 } |
111 } | 114 } |
OLD | NEW |