From: John D'Errico on 21 Jul 2010 15:11 "Brandon Moore" <moorebj.nospamplease(a)umich.edu> wrote in message <i27ebu$mkb$1(a)fred.mathworks.com>... > Wondering if there is some easy way to adjust the tolerances on the relational operators (==, <, etc.) in MATLAB so I don't have things like sum([0.4 0.3 0.2 0.1])==1 come back false. I.e., I don't want to have to include a +tolerance or -tolerance term every time I use a relational operator in order for it to not have these sort of errors (or rather, to error more on the side of logical true instead of logical false). No, there is no easy way to do this automatically, beyond overloading the ops themselves. And that might be a VERY dangerous thing to do. Note that all of matlab would then be using your overloaded relops, possibly causing incredibly difficult to find bugs in the base matlab codes. In some cases, they may actually be relying on exact behaviors for those operators. An author who is careful may choose to take advantage of such things. At the very least, this will cause all of matlab to now run more slowly. So I would strongly recommend NOT going down this overloading path. It will come back to bite you in the butt one day. You might choose to implement your own distinct tests, passing in an explicit tolerance, and use these new functions where you wish to employ a test with a tolerance. This will be safe for all concerned. And if there is a bug, it will be easier for you to track down. John
|
Pages: 1 Prev: relational operator tolerences Next: relational operator tolerences |