History

add tests for float conversions to u64

Note: I removed the test that used sin() function because it makes no sense to use that there and besides I could not get the test to work because sin requires -lm linked but for some reason make does not compile with -lm and I get errors like undefined symbol sin. Coerce function should do the same thing for the purposes of that test.

Kyryl Melekhin committed 6 years ago

Commit a5e714a1 parent 618ba552 files · +38 −2Browse files

Unified · Split

2 files
  1. tests/tests2/22_floating_point.c +31 −1
  2. tests/tests2/22_floating_point.expect +7 −1
tests/tests2/22_floating_point.c+31−1
@@ -14,6 +14,12 @@ test() · 13 unmodified lines
14 }14 }
15}15}
16 16
17double coerce(double x)
18{
19 x++;
20 return x;
21}
22
17int main()23int main()
18{24{
19 // variables25 // variables
@@ -55,7 +61,31 @@ int main() · 35 unmodified lines
55 // type coercion61 // type coercion
56 a = 2;62 a = 2;
57 printf("%f\n", a);63 printf("%f\n", a);
58 printf("%f\n", sin(2));64 printf("%f\n", coerce(2));
65
66 //type conversion to unsigned long int
67 float f = 3421.439;
68 double d = 7855.332231;
69 long double ld = 2469.346786989643234;
70
71 unsigned long int i;
72 i = f;
73 printf("%lu\n", i);
74 i = d;
75 printf("%lu\n", i);
76 i = ld;
77 printf("%lu\n", i);
78
79 f = -3421.439;
80 d = -7855.332231;
81 ld = -2469.346786989643234;
82 i = f;
83 printf("%lu\n", i);
84 i = d;
85 printf("%lu\n", i);
86 i = ld;
87 printf("%lu\n", i);
88
59 89
60 return 0;90 return 0;
61}91}
tests/tests2/22_floating_point.expect+7−1
@@ -13,4 +13,10 @@ · 12 unmodified lines
1312.3400001312.340000
14-12.34000014-12.340000
152.000000152.000000
160.909297163.000000
173421
187855
192469
2018446744073709548195
2118446744073709543761
2218446744073709549147

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t