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 INT19INT35-C. Correctly compute Use correct integer widths 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 assert(UWIDTH(INT_MAX) <= DBL_MANT_DIG);
  int big = 1234567890;
  double approx = big;
  printf("%d\n", (big - (int)approx));
  return 0;
}

...