cancel
Showing results for 
Search instead for 
Did you mean: 

Computation with floats

matic
Associate III
Posted on December 04, 2015 at 15:33

Hi. I have to do some calculation, where I need to be precise and have to use sine function. I do that calculation only once and speed of execution here is not so critical. So I dccided to use floats (before I had a LUT for sine function and used integers, but was not good enough).

Now, my question is, should I simply include ''math.h'' library and use a sine function from there, or is there any quicker way to calculate sine with floats. I have STM32F303 uC. Do I have to enable FPU somehow?

Thanks 
1 REPLY 1
Posted on December 04, 2015 at 23:01

Not sure I'd use 32-bit float for precision.

The FPU doesn't natively support transcendental functions, it's not at all like the 80x87/6888x parts. The FPU also doesn't hold intermediate values at higher precision, so be conscious of the order in which you do the math so you don't overwhelm the bits you have to work with. Enabling requires a couple of co-processor bits, usually code in SystemInit(), and a check box in the tool chain to ''Use FPU''

void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
..

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..