math.... help

hi, I am at he edge of madness with GCC!

I must calculate some sines and cosines integrated with arc cosines.

I get parameters of these functions from serial port as strings. First I convert them to integers. Then cast them to float to use in trigonometric functions.

The problem is sine or cosine results are in the range of billions!!!
Where sine function oscillates between -1 and +1.

example:

u32 a=123456,b=78901,c;

float f,g,h;

f=(float)a;
g=(float)b;

h = acos( sin(f) * cos(g) );

c = (u32)h;

and c gives in wm_printf function as 100890309 !!! what is this?

don’t mind the syntax it is just sample.

I wonder if anyone can help me calculating trigonometric functions, which types I must use?
What is the max range of double and float?

do you have any sample code?

platform:
MS Visual C++ 6.0
openAT 3.02
GCC

Thanks in advance

I found that there is an option of GCC ARM compiler for Float numbers as hard float (hardware controlled) and soft float (software controlled). Can it be a solution?

Have u met a problem like that?

Hi Piedos, how are you?

It´s been a while since you have posted this topic… did you solve it? How!?

Best Regards,

Henrique

I have the same problem. Is anyone knows solution to problem?

Hi,

I don’t think you can convert a float to int by just typecasting it! It will just change the type but will not convert the value! It will just use the same bits that were used to encode the float value in an u32!!! That does not really make any sense to do… I think you have a problem with C and it has nothing to do with the Wavecom libraries and operating system! Read some books…

Best Regards,
Jan

I add the following link:
#include “math.h”
sin, cos function work correctly now.

So you didn’t actually have the same problem? The problem was that printing c with wm_printf() after the “conversion” c = (u32)h with h beeing a float returns some random number…

Can you do a conversion like this and it does print a value that is useful???

Best Regards,
Jan