Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: width->precision

...

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
bgColor#ccccff
langc
#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;
}

...