osx - Simple arithmetic calculus that should be 0 returns infinity -


so...i have check values if equal. never , knew should be, debugged application , reached following conclusion

-2.5f - mathf.round(1.1f) * 0.6f - (-3.1f) doest not equal 0 instead it's value -1.192093e-07

is there reasonable explanation , there workaround? need equation in format.

ps: values here hardcoded variables , have other values too. problem when result should 0

here line of code: debug.log(string.format("{0} ", -2.5f - mathf.round(1.1f) * 0.6f - (-3.1f)));

using unity 4.5.1f3 monodevelop 4.0.1 on os x 10.9.5.

like said in comments -1.192093e-07 not infinity close zero. notice minus sign after "e". value .0000001192093.

when comparing floating point numbers should never use ==, because floating point arithmetic causing kind of small errors. instead can use this:

float diff = avalue - bvalue; if(diff < 0.000001f && diff > -0.000001f){  } 

it might idea read "what every programmer should know floating-point arithmetic" example here.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -