]> pd.if.org Git - lice/blob - tests/float.c
autocommit for files dated 2014-11-17 20:13:34
[lice] / tests / float.c
1 // floats
2
3 float  ffunc1(float  arg) { return arg; }
4 float  ffunc2(double arg) { return arg; }
5 float  ffunc3(int    arg) { return arg; }
6 double dfunc1(float  arg) { return arg; }
7 double dfunc2(double arg) { return arg; }
8 double dfunc3(int    arg) { return arg; }
9
10 // deal with recursive calls for floats / doubles
11 // requires stack alignment on some architectures
12 // to properly work.
13 float frecurse(float a) {
14     if (a < 10)
15         return a;
16     return frecurse(3.14);
17 }
18
19 double drecurse(double a) {
20     if (a < 10)
21         return a;
22     return drecurse(6.28);
23 }
24
25 int main(void) {
26     // all float
27     expectf(1.0,       1.0);
28     expectf(1.0 + 0.5, 1.5);
29     expectf(1.0 - 0.5, 0.5);
30     expectf(1.0 * 2.0, 2.0);
31     expectf(1.0 / 4.0, 0.25);
32
33     // float and int
34     expectf(1.0,       1.0);
35     expectf(1.0 + 1,   2.0);
36     expectf(1.0 - 1,   0.0);
37     expectf(1.0 * 2,   2.0);
38     expectf(1.0 / 4,   0.25);
39
40     expectf(ffunc1(3.14f), 3.14f);
41     expectf(ffunc1(3.0f),  3.0f);
42     expectf(ffunc2(3.14f), 3.14f);
43     expectf(ffunc2(3.0f),  3.0f);
44     expectf(ffunc3(3.14f), 3.0f);
45     expectf(ffunc3(3),    3);
46     expectd(dfunc1(1.0),  1.0);
47     expectd(dfunc1(10.0), 10.0);
48     expectd(dfunc2(2.0),  2.0);
49     expectd(dfunc2(10),   10.0);
50     expectd(dfunc3(11.5), 11.0);
51     expectd(dfunc3(10),   10.0);
52     // Bug: these are still broken
53     //expectf(frecurse(1024), 3.14);
54     //expectd(drecurse(1024), 6.28);
55     float a = 1024.0f;
56     float b = a;
57     expectf(a, 1024.0f);
58     expectf(b, 1024.0f);
59
60     double c = 2048.0;
61     double d = c;
62     expectd(c, 2048.0);
63     expectd(d, 2048.0);
64
65     expectf(0.7, .7);
66
67     return 0;
68 }