Possible duplicate:strange output in comparison of float with floating literal
#include<stdio.h> int main() { float me = 1.7; if(me==1.7) printf("C"); else printf("C++"); } Output: C++
Now the reason for this behavior is that many floating point numbers cannot be represented with absolute precision in binary format.
My question is - if the computer thinks and manipulates in binary format. Any inconsistency in presentation mewould be the same for 1.7comparison. Therefore, both must be equal.
me
1.7
ALSO, how does typing solve this problem? (float)1.7
(float)1.7
You are comparing a float to a double. literal 1.7is double.
, , double, me == 1.7 1.7 float ( double) 1.7 double.
me == 1.7
me == 1.7f me double double me = 1.7;
me == 1.7f
double me = 1.7;
, , , epsilon, @duffymo.
, .
1.7 float double, float .
, , , , , - - (x + y) + z x + (y + z) ( , , , , ).
, (100 - (100 -.0000000001))! =.00000000001 IEEE-754 , , . , , .00000000001, . , , , .
IEEE-754 , , .
" ": http://docs.sun.com/source/806-3568/ncg_goldberg.html
IEEE-754, 1.7f 1.7 :
1.7f == 1.7000000476837158203125 1.7 == 1.6999999999999999555910790149937383830547332763671875
, , .
float me = 1.7f;
numerical analysis, , , , , , .
numerical analysis
1.7 . , 1.7 1.7d, , , () epsilons.
Source: https://habr.com/ru/post/1762428/More articles:Как анализировать различные файлы XML, используя SAX на Android? - androidWhy emails don’t upload images directly - securityTesting the role of the Elk in the non Moose class - perlС# - DevExpress XtraGrid - Мастер/Деталь - Формат отображения - c#vb.net конвертировать строку на сегодняшний день - datetimeWhy is there such a big difference in the execution time of a query executed by ADF and in SQL Developer - oracle-adfMVVM Light and Undo / Redo? - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1762431/jquery-detect-which-element-a-onclick-occurs-to&usg=ALkJrhjNKv_o_mWy5gXP9K0urS2ixLxVbwerror C2440: '=': cannot convert from 'char [5]' to 'char [20]' - c ++Problem Starting With Caliburn Micro - c #All Articles