Strange results with floating-point comparison

后端 未结 10 1750
余生分开走
余生分开走 2020-12-10 08:34

I have this simple test:

double h;
...
// code that assigns h its initial value, used below
...
if ((h>0) && (h<1)){
 //branch 1 -some computati         


        
10条回答
  •  青春惊慌失措
    2020-12-10 09:24

    if you have to use floats in checks, round them off and store it in for example a integer. 1f could be 1.0000000000000000000000000000000001 or 0.999999999999999999999999999999999999

提交回复
热议问题