Help with sqrt (square root function): Target MCF52211, CW ver 5.7.0

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Help with sqrt (square root function): Target MCF52211, CW ver 5.7.0

4,844件の閲覧回数
jayteemo
Contributor I

I'm having problems getting the sqrt (or sqrtf) function to work properly.
My targer processor is MCF52211.  CodeWarrior version 5.7.0.
I've included the following libraries in the project: C_4i_CF_MSL.a and fp_coldfire.a
Also, <math.h> is included in the source.

When I build with the Require Function Prototypes box un-checked under Language Settings -> C/C++ Language the project builds and runs with the following results:
When I run using sqrt, the result is always 20.0 and and the exception handler is entered, resulting in the error: "Access Error: Error on operand write".
When I run using sqrtf, the result is a very large, incorrect number.
When I build with the Require Function Prototypes box un-checked under Language Settings -> C/C++ Language the project fails to build with the error (referencing the sqrt function):
Error   : function has no prototype
Is there a specific library I should be using or a setting somewhere that I am missing?

Thanks.
ラベル(1)
タグ(1)
0 件の賞賛
返信
7 返答(返信)

2,616件の閲覧回数
jayteemo
Contributor I
Yes, I have included math.h in the souce file where sqrt is used and I've tried using the various libraries referenced in the build tools PDF, but I still get the "no prototype error".

For now I have just placed the sqrt function source from the library's source file (e_sqrt.c) into my code and it works.  It is not something I wish to leave there long term, but it is working as a temporary solution so I can continue development.

Any further suggestions would be appreciated.
Thanks.
0 件の賞賛
返信

2,616件の閲覧回数
J2MEJediMaster
Specialist I
The fact that the program will link at all when function prototypes are not required indicates that some undeclared function with the same name exists somewhere. Here are my long-shot suggestions:

1) Try checking the link order in the Project Window's Link tab. Put the library first in the list.

2) Save the preprocessor output to the file. Use the editor to look for any occurance of sqrt.

---Tom

0 件の賞賛
返信

2,616件の閲覧回数
jayteemo
Contributor I
Moving the libraries to the top of the link order had no noticable impact.

How do I save the pre-processor output to a file?

Thanks!
0 件の賞賛
返信

2,616件の閲覧回数
J2MEJediMaster
Specialist I
For CW for ColdFire 6.4:

1) Choose Project > Preprocess. A preprocessor output window appears.
2) Choose File > Save As and save the window to a file.

Use the CW editor to search that file.

If there's no duplicate entry, then you might want to file a service request on the problem.

---Tom


0 件の賞賛
返信

2,616件の閲覧回数
J2MEJediMaster
Specialist I
Try looking at in the ColdFire_Build_Tools_Reference.PDF file chapter twenty on ColdFire Runtime Libraries, Table 2.0.2. That table covers the ColdFire C libraries. You may want to confirm that you're using the correct library with floating-point support.

---Tom
0 件の賞賛
返信

2,616件の閲覧回数
CrasyCat
Specialist III
Hello
 
Did you add an
    #include <math.h>
at the beginning of the source file where you use sqrt/sqrtf?
 
CrasyCat
0 件の賞賛
返信

2,616件の閲覧回数
MarcVDH
Contributor I
I have the same problem trying to use the 'exp' function. I have asked the question here too but it hasn't brought me any further...
0 件の賞賛
返信