Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Loss of information using small numbers (e-10), MEX, C++
Replies: 7   Last Post: Dec 30, 2013 11:53 AM

 Messages: [ Previous | Next ]
 Håkon Seljåsen Posts: 10 Registered: 12/4/13
Re: Loss of information using small numbers (e-10), MEX, C++
Posted: Dec 30, 2013 9:49 AM

"James Tursa" wrote in message <l9r887\$ck9\$1@newscl01ah.mathworks.com>...
>
> What is pi? If it is 0 then your result will be zero. Maybe you forgot to set it? Did you >include math.h?

pi is defined earlier in the code:
long double pi = 3.1415926535897932384626433832795028841971693993751;
math.h is included.

> Also the pow calls are in double, so you are not going to get the benefit of long double >precision for those calculations (if it is longer than a double).

I did not think about that, but guss it will do with double as the number is of magnitude 1500^2=2250000.
I assume it is automaticaly typecasted to long when i multiply/divide with other long variables. So that is does not affect the precision of the other variables.
>
> Also, your code is not robust and will bomb MATLAB if things are not exactly as expected. E.g., if pSettings is missing then MATLAB will bomb. If the ro field is missing then MATLAB will bomb. Etc. You might consider putting in code to check to see that the inputs are exactly as expected before using them.

A good point. It is part of a bigger .m program, but I can put in some error messages to ease debugging in the "caller" at a later point.
>
> James Tursa

Date Subject Author
12/29/13 Håkon Seljåsen
12/29/13 Phil Goddard
12/30/13 James Tursa
12/30/13 Phil Goddard
12/30/13 Håkon Seljåsen
12/30/13 James Tursa
12/30/13 Håkon Seljåsen
12/30/13 Håkon Seljåsen