Power function without using a math library

I am working on a microcontroller that contains access to floating point operations.

I need to use the power function. The problem is that there is not enough memory to support the pow and sqrt functions. This is due to the fact that the microcontroller does not support FP operations initially and creates a large number of instructions for their use. I can still multiply and divide floating point numbers.

Architecture : Freescale HCS12 (16 bit)

+4
source share
2 answers

If you mentioned architecture, you can get a more specific answer.

The Linux kernel still has the old IEEE-754 x87 math emulation library for i386 and i486 processors without a floating point hardware module, under arch/x86/math-emu/

There are many resources on the Internet for floating point routines implemented for PIC microcontrollers, and AVR libc has a floating point library - although it is AVR.

glibc has implementations for pow functions in sysdeps/ieee754 . Obviously, the compiler must handle elementary floating point operators using hardware instructions or emulation / function calls.

+4
source

Make your own function that multiplies many times in a loop.

-1
source

Source: https://habr.com/ru/post/1385362/


All Articles