/* compile me with -std=c99 */
#define _ISOC99_SOURCE
#include <math.h>
#include <stdio.h>
#include <limits.h>

/* This program checks if subtracting 5% and scaling by 95%
 * arrive at the same result.
 *
 * The first failures are at 
 *
 * 1103769 - (1103769 * 0.05) = 1048581 but 1103769 * 0.95 = 1048580
 *
 * for floats (32-bit, 23-bit mantissa, "single precision") and 
 *
 * 421868867682369 - (421868867682369 * 0.05) = 400775424298251 but
 * 421868867682369 * 0.95 = 400775424298250
 *
 * for doubles (64-bit, 52-bit mantissa, "double precision")
 *
 * */

int main()
{
	long long int i;
	int counter = 0;
	for (i=1; i < LLONG_MAX; i += 1) {
		long long int fivepercent = llrint/*f*/(i * 0.05/*f*/);
		long long int ninteyfivepercent = llrint/*f*/(i * 0.95/*f*/);
		if (i - fivepercent != ninteyfivepercent) {
			printf("%lld - (%lld * 0.05) = %lld but %lld * 0.95 = %lld\n",
			        i, i, i - fivepercent, i, ninteyfivepercent);
		}
		if (++counter >= 100000000) {
			counter = 0;
			fprintf(stderr, "%lld\r", i);
			fflush(stderr);
		}
	}
	return 0;
}

