Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <stdbool.h>
- #include <float.h> //FLT_EPSILON
- bool fltAEqual(float a, float b, float epsilon)
- {
- return fabs(a-b) < epsilon;
- }
- bool fltCmp2(float a, float b, unsigned int precision)
- {
- int i1, i2;
- if (a > 0) i1 = (int)(a * precision + .5);
- else i1 = (int)(a * precision - .5);
- if (b > 0) i2 = (int)(b * precision + .5);
- else i2 = (int)(b * precision - .5);
- return (i1 == i2);
- }
- int main (int argc, char **argv)
- {
- if(fltAEqual(0.0f, 0.0f, FLT_EPSILON)) printf("Equal\n");
- else printf("Not equal\n");
- if(fltCmp2(0.0f, 0.0f, 100000)) printf("Equal\n");
- else printf("Not equal\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment