Answer the question
In order to leave comments, you need to log in
Why might the if ( a == a) condition fail for Embedded development?
I went to an interview for the position of Embedded C Developer. At the interview they asked:
Why, what and under what conditions will the if statement not be executed?
int a;
float b;
int main(){
if (a == a){
...
(some code)
...
}
if (b == b){
...
(some code)
...
}
Answer the question
In order to leave comments, you need to log in
float b; ... if (b == b)
Two values (other
than NaNs) with the same object representation compare equal, but values that compare
equal may have different object representations.
.
Well, I'd say (b == b) won't work because the float storage format is such that it's impossible to make an exact comparison. A floating point number is a mathematical abstraction, for the implementation of which in computing (which operates with specific zeros and ones) a number of assumptions are applied;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question