This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FPU Usage in Tiva TM4C123GX ( Clarification about speed of math instructions, use of floating number variables ... )

Hello Everyone

I read related posts about  FPU usage in Tiva C Series. I learned how to activate FPU but I am little confused and I want to clarify related issues.

1) Tiva has 32 Bit Single precision floating point unit. Thats why we should use sinf(), sqrtf()... functions instead of double sin(), sqrt(). Am I right ?

2) If we want to define floating number we should add `f` end of number. For example float var = 1.14213f. When I define as float var = 1.14213 variable will be `double` ?

3) Calculation time is much shorter with sinf(), sqrtf() than sin(),sqrt() ?

Regards

Serkan

  • Hello Serkan,

    The use of sin() over sinf() is based on what return type is desired and decides the speed of execution and accuracy.

    The questions you asked are not specific to TM4C devices, but are general C language based. You will have more success by posting on forums that specialize in answering these questions.

    Thanks,
    Sai
  • 1) Tiva has 32 Bit Single precision floating point unit. Thats why we should use sinf(), sqrtf()... functions instead of double sin(), sqrt(). Am I right ?

    That depends on your precision and performance requirements. Double precision is surely possible, but emulated, even with FPU enabled. And float has only a 24 bit mantissa.

    2) If we want to define floating number we should add `f` end of number. For example float var = 1.14213f. When I define as float var = 1.14213 variable will be `double` ?

    No. The preprocessor/compiler will generate a double constant, and then cast (convert) it before assigning it to your float variable - a superfluous step.

    3) Calculation time is much shorter with sinf(), sqrtf() than sin(),sqrt() ?

    Basically yes. Be aware that no trigonometric functions are implemented in hardware in the FPU, they are emulated even when using float (sinf(), cosf(), ...). Resorting to lookup tables might be faster.