The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"James Tursa" wrote in message <l9r887$ck9$>...
> 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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.