0

I'm writing a matrix library in c++. After some debugging I found that a simple double difference is not zero for two "equals" numbers. This is due how double are represented in a computer of course. So my question is, what I could use to improve the numeric stability? I tried to use long double but I have the same problem. The same algorithm in MATLAB works so MATLAB must use some trick about internal number representation.

greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • 4
    This isn't a duplicate of the one indicated. I marked it for closing because it is way too broad -- whole libraries have been filled with books and papers on the topic and I would advise OP to spend some time with an *introduction to numerical analysis*. – High Performance Mark Mar 11 '17 at 12:55
  • 1
    Why do you not use an existing matrix library such as [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)? I think you are reinventing the wheel. – m7913d Mar 11 '17 at 12:59
  • 1
    @m7913d Because I want learn something new instead of using a "black box" without to know how it works. – greywolf82 Mar 11 '17 at 13:00
  • 1
    As it is, this question is not technically a duplicate of the one indicated, but one for which there is no clear answer. You may have more luck asking it on http://scicomp.stackexchange.com/ – André Mar 11 '17 at 13:19
  • I'll just leave this here - http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon – Jesper Juhl Mar 11 '17 at 13:54
  • It really depends how critical this is. There is nothing wrong with using tools that have already been made - it's unlikely for example, that you will write a library that comes close to standard libraries without considerable time, effort, and ingenuity. – anon01 Mar 11 '17 at 21:28

0 Answers0