0
Why it print command working?
#include<stdio.h> int main(){ float a=0.7; if(0.7>a) printf("Hi" ); return 0; }
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);
0
Slick no, the result of 0.7>a is true, because 0.7 is double and a is float ^^
0
Kaptan Kaan Yıldırım you can also log 0.7f-a to see the difference:
printf("Hi %e",0.7f-a);
- 1
Because .7 is not greater than .7, they are equal.
test: if a == 0.7