• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "Test.h"
9 #include "SkFixed15.h"
10 
DEF_TEST(SkFixed15,r)11 DEF_TEST(SkFixed15, r) {
12     // For all v, v*0 == 0, v*1 == v.
13     for (uint16_t bits = 0; bits <= 32768; bits++) {
14         auto v = SkFixed15::Load(bits);
15         REPORTER_ASSERT(r, v * 0.0f == 0.0f);
16         REPORTER_ASSERT(r, v * 1.0f == v);
17     }
18 
19     // Division and multiplication by powers of 2 is exact.
20     SkFixed15 v = 1.0f;
21     REPORTER_ASSERT(r, (v>>1)    == 0.50f);
22     REPORTER_ASSERT(r, (v>>2)    == 0.25f);
23     REPORTER_ASSERT(r, (v>>2<<1) == 0.50f);
24 
25     // FromU8() should be just as good as going through float.
26     for (int x = 0; x < 256; x++) {
27         REPORTER_ASSERT(r, SkFixed15::FromU8(x) == SkFixed15(x * (1/255.0f)));
28     }
29 
30     // to_u8() and FromU8() should roundtrip all bytes.
31     for (int x = 0; x < 256; x++) {
32         REPORTER_ASSERT(r, x == SkFixed15::FromU8(x).to_u8());
33     }
34 }
35