0

Why it print command working?

#include<stdio.h> int main(){ float a=0.7; if(0.7>a) printf("Hi" ); return 0; }

29th Jun 2021, 8:23 PM
Kaptan Kaan Yıldırım
Kaptan Kaan Yıldırım - avatar
4 Réponses
0
because of decimal floating point storage innacurracy and default literal stored as double: https://en.m.wikipedia.org/wiki/Floating-point_error_mitigation try: if (0.7f>a) instead, or log value of 0.7-a in exponent notation: printf("Hi %e",0.7-a);
29th Jun 2021, 9:43 PM
visph
visph - avatar
0
Slick no, the result of 0.7>a is true, because 0.7 is double and a is float ^^
29th Jun 2021, 9:44 PM
visph
visph - avatar
0
Kaptan Kaan Yıldırım you can also log 0.7f-a to see the difference: printf("Hi %e",0.7f-a);
29th Jun 2021, 9:46 PM
visph
visph - avatar
- 1
Because .7 is not greater than .7, they are equal. test: if a == 0.7
29th Jun 2021, 9:34 PM
Slick
Slick - avatar