...
This solution replaces the float
with a double
. Furthermore, it uses an assertion to guarantee that the double
type can represent any int
without loss of precision for implementations. (See INT35-C. Use correct integer precisions for the definition and rationale of the UWIDTHthe PRECISION()
macro):
Code Block | ||||
---|---|---|---|---|
| ||||
#include <assert.h> #include <stdio.h> #include <float.h> #include <limits.h> int main(void) { assert(UWIDTHPRECISION(INT_MAX) <= DBL_MANT_DIG * log2(DBL_MANT_DIG)); int big = 1234567890; double approx = big; printf("%d\n", (big - (int)approx)); return 0; } |
...