Last change
on this file since 969 was
969,
checked in by sam, 11 years ago
|
core: switch real mantissa to uint16_t instead of uint32_t to ease the
multiplication.
|
File size:
1.2 KB
|
Line | |
---|
1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <cmath> |
---|
16 | |
---|
17 | #include "core.h" |
---|
18 | #include "lol/unit.h" |
---|
19 | |
---|
20 | namespace lol |
---|
21 | { |
---|
22 | |
---|
23 | LOLUNIT_FIXTURE(RealTest) |
---|
24 | { |
---|
25 | public: |
---|
26 | LOLUNIT_TEST(test_real_from_float) |
---|
27 | { |
---|
28 | float x = real(0.0f); |
---|
29 | float y = real(1.0f); |
---|
30 | float z = real(1.5f); |
---|
31 | |
---|
32 | LOLUNIT_ASSERT_EQUAL(x, 0.0f); |
---|
33 | LOLUNIT_ASSERT_EQUAL(y, 1.0f); |
---|
34 | LOLUNIT_ASSERT_EQUAL(z, 1.5f); |
---|
35 | } |
---|
36 | |
---|
37 | LOLUNIT_TEST(test_real_mul) |
---|
38 | { |
---|
39 | real x(1.25f); |
---|
40 | real y(1.5f); |
---|
41 | real z(1.99999f); |
---|
42 | real w(-1.5f); |
---|
43 | |
---|
44 | float m1 = x * x; |
---|
45 | float m2 = y * y; |
---|
46 | float m3 = z * z; |
---|
47 | float m4 = w * w; |
---|
48 | |
---|
49 | LOLUNIT_ASSERT_EQUAL(m1, 1.25f * 1.25f); |
---|
50 | LOLUNIT_ASSERT_EQUAL(m2, 1.5f * 1.5f); |
---|
51 | LOLUNIT_ASSERT_EQUAL(m3, 1.99999f * 1.99999f); |
---|
52 | LOLUNIT_ASSERT_EQUAL(m4, -1.5f * -1.5f); |
---|
53 | } |
---|
54 | }; |
---|
55 | |
---|
56 | } /* namespace lol */ |
---|
57 | |
---|
Note: See
TracBrowser
for help on using the repository browser.