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.
Unified · Split
| @@ -14,6 +14,12 @@ test() · 13 unmodified lines | |||
| 14 | } | 14 | } |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | double coerce(double x) | ||
| 18 | { | ||
| 19 | x++; | ||
| 20 | return x; | ||
| 21 | } | ||
| 22 | |||
| 17 | int main() | 23 | int main() |
| 18 | { | 24 | { |
| 19 | // variables | 25 | // variables |
| @@ -55,7 +61,31 @@ int main() · 35 unmodified lines | |||
| 55 | // type coercion | 61 | // 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 | } |
| @@ -13,4 +13,10 @@ · 12 unmodified lines | |||
| 13 | 12.340000 | 13 | 12.340000 |
| 14 | -12.340000 | 14 | -12.340000 |
| 15 | 2.000000 | 15 | 2.000000 |
| 16 | 0.909297 | 16 | 3.000000 |
| 17 | 3421 | ||
| 18 | 7855 | ||
| 19 | 2469 | ||
| 20 | 18446744073709548195 | ||
| 21 | 18446744073709543761 | ||
| 22 | 18446744073709549147 | ||