Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 where the radix of the exponent representation is 2. (See INT35-C. Use correct integer widthsprecisions for the definition and rationale of the UWIDTH() macro):

Code Block
bgColor#ccccff
langc
#include <assert.h>
#include <stdio.h>
#include <float.h>
#include <limits.h>

static_assert(FLT_RADIX != 2, "radix of the exponent representation is not 2"); 

 int int main(void) {
  assert(UWIDTH(INT_MAX) <= DBL_MANT_DIG * log2(DBL_MANT_DIG));
   int big = 1234567890;
  double approx = big;
  printf("%d\n", (big - (int)approx));
  return 0;
}

...