最近在TI DSP 6701平臺上寫了個大地坐標系高度角計算的函式,其中用到了三角函式atan,發現前面幾次呼叫時程式執行正常,但是執行兩輪后,后續呼叫時,回傳結果均不符合預期。經過初步排查出錯時程式正常,堆疊未溢位。尚不知問題出在哪,懇請各位大拿指點!
uj5u.com熱心網友回復:
標準庫還是有這種問題我是不信的建議加列印貼出除錯結果
uj5u.com熱心網友回復:
謝謝邀請,這種結果不符合預期,僅憑上面說的這些很難推斷出問題所在
首先得排除掉標準函式出錯的可能
那就從給的引數入手了,對這個平臺不太了解,幫不上你什么
uj5u.com熱心網友回復:
通過比對出錯時程式區代碼正常未被改寫。另外程式結構有些復雜,感覺是呼叫環節出了問題,但是又不知道該怎么排查uj5u.com熱心網友回復:
加除錯手段啊,呼叫atan的輸入輸出都列印出來不就能確定是atan的問題還是其他的問題了么?uj5u.com熱心網友回復:
角度需要轉換為弧度uj5u.com熱心網友回復:
單位沒問題的,是弧度的。關鍵是前面兩次呼叫atan函式回傳值是正確的。執行兩次以后就不按照輸入來了,即使是同樣的輸入。uj5u.com熱心網友回復:
atan, atan2Calculates the arctangent of x (atan) or the arctangent of y/x (atan2).
double atan( double x );
double atan2( double y, double x );
Routine Required Header Compatibility
atan <math.h> ANSI, Win 95, Win NT
atan2 <math.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
atan returns the arctangent of x. atan2 returns the arctangent of y/x. If x is 0, atan returns 0. If both parameters of atan2 are 0, the function returns 0. You can modify error handling by using the _matherr routine. atan returns a value in the range –π/2 to π/2 radians; atan2 returns a value in the range –π to π radians, using the signs of both parameters to determine the quadrant of the return value.
Parameters
x, y
Any numbers
Remarks
The atan function calculates the arctangent of x. atan2 calculates the arctangent of y/x. atan2 is well defined for every point other than the origin, even if x equals 0 and y does not equal 0.
Example
/* ATAN.C: This program calculates
* the arctangent of 1 and -1.
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
void main( void )
{
double x1, x2, y;
printf( "Enter a real number: " );
scanf( "%lf", &x1 );
y = atan( x1 );
printf( "Arctangent of %f: %f\n", x1, y );
printf( "Enter a second real number: " );
scanf( "%lf", &x2 );
y = atan2( x1, x2 );
printf( "Arctangent of %f / %f: %f\n", x1, x2, y );
}
Output
Enter a real number: -862.42
Arctangent of -862.420000: -1.569637
Enter a second real number: 78.5149
Arctangent of -862.420000 / 78.514900: -1.480006
Floating-Point Support Routines
See Also acos, asin, cos, _matherr, sin, tan
uj5u.com熱心網友回復:
我覺著樓主還是把代碼和結果貼出來看看比較好uj5u.com熱心網友回復:
樓主解決問題了嘛,我好像也遇到類似的問題了。求教uj5u.com熱心網友回復:
很看不上這種過于高估自己語文水平的提問。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/249144.html
標籤:C語言
