c++ - Is it safe to cast a float with value 0.0f to boolean? -


i know due precision errors, float varibale should checked equal value with tolerance. what's case if manually set float variable 0.0f?

for example there function returning distance.

float distance() {     float value;     if(/* ... */)     {         // ...         return value;     }     else return 0.0f; } 

can cast result bool safely?

if(distance()) {    // ... } 

when write:

if(distance()) 

you checking whether float 0 or not.

your code equivalent to

if(distance() != 0) 

this safe do, , can determine whether or not has meaning require.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -