3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2010 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Math/fixed.hpp"
24 #include "TestUtil.hpp"
28 int main(int argc
, char** argv
) {
31 /* check the division operator */
32 ok((fixed_one
/ fixed_one
) * fixed(1000) == fixed(1000), "1/1", 0);
33 ok((fixed_two
/ fixed_two
) * fixed(1000) == fixed(1000), "2/2", 0);
34 ok((fixed_one
/ fixed_two
) * fixed(1000) == fixed(500), "1/2", 0);
35 ok((fixed(1000) / fixed(100)) * fixed(1000) == fixed(10000), "1000/100", 0);
36 ok((fixed(100) / fixed(20)) * fixed(1000) == fixed(5000), "100/20", 0);
37 ok((fixed(1000000) / fixed(2)) * fixed(1000) == fixed(500000000), "1M/2", 0);
38 ok((fixed_minus_one
/ fixed_one
) * fixed(1000) == -fixed(1000), "-1/1", 0);
39 ok((fixed_one
/ fixed_minus_one
) * fixed(1000) == -fixed(1000), "1/-1", 0);
40 ok((fixed_minus_one
/ fixed_minus_one
) * fixed(1000) == fixed(1000), "-1/-1", 0);
41 ok((fixed(-1000000) / fixed(2)) * fixed(1000) == -fixed(500000000), "-1M/2", 0);
42 ok((long)((fixed_one
/ (fixed_one
/ fixed(10))) * fixed(1000)) == (10000), "1/0.1", 0);
43 ok((long)((fixed_one
/ (fixed_one
/ fixed(-10))) * fixed(1000)) == -(10000) ||
44 (long)((fixed_one
/ (fixed_one
/ fixed(-10))) * fixed(1000)) == -(10001), "1/-0.1", 0);
46 ok(equals(fixed_one
/ fixed_half
, 2), "1/0.5", 0);
47 ok(equals(fixed(1000) / fixed_half
, 2000), "1/0.5", 0);
48 ok(equals(fixed(1000) / (fixed_one
/ 5), 5000), "1/0.5", 0);
50 ok(equals(fixed(1000000) / (fixed_one
/ 5), 5000000), "1/0.5", 0);
51 ok(equals(fixed(10000000) / (fixed_one
/ 5), 50000000), "1/0.5", 0);
54 double dsina
= sin(da
);
59 printf("a=%g, sin(a)=%g\n", FIXED_DOUBLE(a
), FIXED_DOUBLE(sina
));
60 printf("a=%g, sin(a)=%g\n", da
, dsina
);
62 ok(fabs(sina
- fixed(dsina
)) < fixed(1.0e5
), "sin(a)", 0);
66 double dt
= atan2(dy
, dx
);
72 printf("x=%g, y=%g atan(y,x)=%g\n",
73 FIXED_DOUBLE(x
), FIXED_DOUBLE(y
), FIXED_DOUBLE(t
));
74 printf("x=%g, y=%g atan(y,x)=%g\n", dx
, dy
, dt
);
76 ok(fabs(t
- fixed(dt
)) < fixed(1.0e5
), "atan(y,x)", 0);