sj755
sj755

Reputation: 4062

power function without the use of math library

I'm working on a micro-controller that contains access to floating-point operations.

I need to make use of a power function. The problem is, there isn't enough memory to support the pow and sqrt function. This is because the microcontroller doesn't support FP operations natively, and produces a large number of instructions to use them. I can still multiply and divide floating point numbers.

Architecture: Freescale HCS12 (16-bit)

Upvotes: 4

Views: 1264

Answers (2)

Brett Hale
Brett Hale

Reputation: 22308

If you mentioned the architecture, you might get a more specific answer.

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

There are a lot of resources online for floating point routines implemented for PIC micros, and AVR libc has a floating point library - though it's in AVR assembly.

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

Upvotes: 4

TJD
TJD

Reputation: 11896

Make your own function that multiplies repeatedly in a loop.

Upvotes: -1

Related Questions