# math.... help

**URL:** <https://forum.sierrawireless.com/t/math-help/282>\
**Category:** Development tools\
**Created:** [February 10, 2006, 8:08pm UTC](https://forum.sierrawireless.com/t/math-help/282 "2006-02-10T20:08:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piedos](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@Piedos](https://forum.sierrawireless.com/u/Piedos)\
**Post date:** [February 10, 2006, 8:08pm UTC](https://forum.sierrawireless.com/t/math-help/282/1 "2006-02-10T20:08:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Piedos](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@Piedos](https://forum.sierrawireless.com/u/Piedos)\
**Post date:** [February 10, 2006, 8:13pm UTC](https://forum.sierrawireless.com/t/math-help/282/2 "2006-02-10T20:13:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sanabiovilela](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sanabiovilela](https://forum.sierrawireless.com/u/sanabiovilela)\
**Post date:** [April 3, 2006, 5:11pm UTC](https://forum.sierrawireless.com/t/math-help/282/3 "2006-04-03T17:11:13Z")

</div>

Hi Piedos, how are you?

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

Best Regards,

Henrique

---

<div class="post-metadata">

**Author:** ![liuyanjun](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@liuyanjun](https://forum.sierrawireless.com/u/liuyanjun)\
**Post date:** [August 15, 2006, 10:23am UTC](https://forum.sierrawireless.com/t/math-help/282/4 "2006-08-15T10:23:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [August 15, 2006, 10:31am UTC](https://forum.sierrawireless.com/t/math-help/282/5 "2006-08-15T10:31:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![liuyanjun](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@liuyanjun](https://forum.sierrawireless.com/u/liuyanjun)\
**Post date:** [August 16, 2006, 4:06am UTC](https://forum.sierrawireless.com/t/math-help/282/6 "2006-08-16T04:06:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jan](https://forum.sierrawireless.com/u/jan)\
**Post date:** [August 16, 2006, 6:37am UTC](https://forum.sierrawireless.com/t/math-help/282/7 "2006-08-16T06:37:19Z")

</div>

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
