Hello,
I have a single (VERY LONG) line of code written in both C++ and matlab that evaluates a mathematical expression. The expression is just under 31,000 characters long, so it's pretty darn complicated.
When I evaluate this expression in matlab vs. C++ I get very different numbers:
MATLAB: 31856235311612.7
C++: 31745938896594.422
However, as you'll probably notice, they're not different enough to think I made a mistake in the transfer. I basically just copied and pasted the expression from C++, so no issues there.
I have two similar expressions of lower order that I also ported; one on the order of 10^9 (differs by about 1%), and one of order 10^7 which does not suffer the same magnitude of error:
MATLAB=3087973.34551207
C++=3087973.3455120716
The question is, which is "correct", and from where are these differences arising? I'm happy to provide code, but the first entry code is a 31,000 character expression!
FYI, in C++ all variables are stored as doubles.
Best Answer