#include<stdio.h> void main() { float a = 2.3; if(a == 2.3) { pritnf("hello"); } else { printf("hi"); } }
It prints "hi" at the output, or we can say that if the condition gets a false value.
#include<stdio.h> void main() { float a = 2.5; if(a == 2.5) printf("Hello"); else printf("Hi"); }
Sends greetings.
A variable ais one floatthat has some value close to mathematical value 2.3.
a
float
2.3 double, , 2.3, double , float, a. float double , , .
2.3
double
a == 2.3 float double. ( ), , , 2.3.
a == 2.3
, :
assert(a == 2.3f); // ^
2.3 01000000000100110011001100110011... float 2.3 : 2.299999952316284
01000000000100110011001100110011...
2.299999952316284
double float, :
float a = 2.3;
if, float a double 2.299999952316284
float a
double 2.299999952316284
:
float a = 2.3f;
if (a == 2.3f) { ... }
if (fabs(a - 2.3f) < 0.00001) { ... }
2.5, : 01000000001000000000000000000000
2.5
01000000001000000000000000000000
EDIT: fabs <math.h> <cmath>
fabs
<math.h>
<cmath>
, , float .
, ( ). 2 , (epsilon):
if( fabs(a - 2.3f) < epsion) { ... }
where epsilon is small enough for your calculation, but not too small (more Machine epsilon ).
Source: https://habr.com/ru/post/1655323/More articles:Обновление до Thymeleaf 3 и повторная реализация Rich HTML Email в Spring - javaHow to write cordova plugin in Swift with CocoaPods? - iosWayland Clipboard API - clipboardBoot grid with correct fixed sidebar - css3Entity Framework takes about 30 seconds on first request - c #Python - multiple 3D plots in one window - python-2.7Creating table space on PostgreSQL RDS - postgresqlMySQL TRUNCATE (double, 4) changes the value instead of truncating - mysqlJenkins displays echo command on console output page - bashРазница между std:: atomic и std:: mutex - multithreadingAll Articles