Mex: useful comparing float values?

1 view (last 30 days)
Hello,
i have a mex-script which returns to matlab some float-values. As i have to check the returning data i have also a c-script with the same function as the mex-script. When i want to compare the data i noticed that the matlab-data and c-data have different number of decimal places although both are using float(single) as datatype.
As i am quite a beginner in c and matlab i am not sure how to solve this usefully. thx for any advise! :)

Accepted Answer

Image Analyst
Image Analyst on 4 May 2013
You have to check if they are within some tolerance of each other. Please see the FAQ. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F . It gives you some code you can use.
  3 Comments
Image Analyst
Image Analyst on 4 May 2013
I think c can show to more than 6 or 7 decimal places. I think you misunderstood. Maybe what they were saying was that single precision numbers are accurate only out to the 6 or 7th decimal place, and that if you show anything after that, it could be just garbage. Those are two different things to say.
Yes, I think using a tolerance, like they do in the FAQ I referred you to, is a good solution.
mick strife
mick strife on 5 May 2013
Thx "image analyst". Yes, i misunderstood that. He told me that float is only accurate with 6,7 decimal places and if i want more decimal places i should use an other data type.
thx for your advice! :-)

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!