blob: df957b1e491dfa320c6a7b6f572d17f9063b1dad [file] [log] [blame]
Mike Kleind280d422016-10-31 09:20:54 -04001/*
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
11DEF_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 }
Mike Kleind32b8172017-01-17 10:19:50 -050029
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 }
Mike Kleind280d422016-10-31 09:20:54 -040034}