MATLAB Answers

1.0010 DOES NOT EQUAL 1.0010

13 views (last 30 days)
Jeff on 10 Nov 2011
Hi all,
I have a segment of code that is evaluating curfactor(sc) == 1.0010 as 0 when curfactor(sc) == 1.0010 (should evaluate as 1). Both numbers are exactly 1.0010. I checked the class of both numbers and they are both double. What on Earth is happening here?!
I should note that curfactor is an array of size 1x3, and is defined at the very beginning of the function. The expression that is being evaluated is nested within 2 other helper functions. Maybe it's a scope issue? In any case, someone's breath stinks here, and it's certainly not mine.

Accepted Answer

Image Analyst
Image Analyst on 10 Nov 2011
Jeff: Read the FAQ and then come back: Like you said, it IS a scope issue, and I'd recommend Scope mouthwash for you - it's an excellent mouthwash.
  1 Comment
Jeff on 10 Nov 2011
Cheers. I will use a tolerance value instead of making a direct comparison.
Readers Beware: I used the round2 function from the Mathworks File Exchange to obtain a number of arbitrary precision and stored it in curfactor(sc). When using this function, take caution that the number is not rounded exactly to the precision specified, there may be hidden bits.

Sign in to comment.

More Answers (2)

bym on 10 Nov 2011
did you check that they were exactly equal with a variable precision package like the symbolic toolbox?
Jeff on 10 Nov 2011
Thanks for the tip!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!