int compareFloats(float f1, float f2) { char *b1, *b2; int i; b1 = (char *)&f1; b2 = (char *)&f2; /* Assuming sizeof(float) is 4 bytes) */ for (i = 0; i < 4; i++, b1++, b2++) { if (*b1 != *b2) { return(NOT_EQUAL); /* You must have defined this before */ } } return(EQUAL); }
You can easily compare floats or any other data types variable by using memcmp() .
int float_cmp(float *f1, float *f2) { return memcmp((void *)f1, (void *)f2, sizeof(float)); }
Using fprintf() print a single floating point number right-justified in a field of 20 spaces, no leading zeros, and 4 decimal places. The destination should be stderr and the variable is called num.
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all ??