当前位置: 动力学知识库 > 问答 > 编程问答 >

c - 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)

网友答案:

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.

网友答案:

Make your own function that multiplies repeatedly in a loop.

分享给朋友:
您可能感兴趣的文章:
随机阅读: