Closed burrimi closed 10 years ago
Normally (1 - cos(alpha))
cannot be negative in a mathematical sense. Have you observed NaN values with a debugger and are you sure that this line causes the problem? Which OS/compiler are you using?
In a mathematical sense yes, but doubles are not exact numbers. I was also surprised at the beginning, but it actually makes sense in my opinion. I'm using gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3.
A simple example can be found here: http://stackoverflow.com/questions/4453372/sqrt1-0-pow1-0-2-returns-nan
Same on OSX 10.9, Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn).
(1 - cos_alpha) can be a negative value and leads to NaN in the attitude because of the square root