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
1414 }
1515 }
1616
17+double coerce(double x)
18+{
19+ x++;
20+ return x;
21+}
22+
1723 int main()
1824 {
1925 // variables
@@ -55,7 +61,31 @@ int main() · 35 unmodified lines
5561 // type coercion
5662 a = 2;
5763 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+
5989
6090 return 0;
6191 }
tests/tests2/22_floating_point.expect+7−1
@@ -13,4 +13,10 @@ · 12 unmodified lines
1313 12.340000
1414 -12.340000
1515 2.000000
16−0.909297
16+3.000000
17+3421
18+7855
19+2469
20+18446744073709548195
21+18446744073709543761
22+18446744073709549147

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