8
\$\begingroup\$

I'm working on a little personal project (targeting a Parallax Propeller, but this should be pretty generalizable) that needs floating point math.

The micro-controller I am working with does not have native floating point, or a stock floating-point library.

Are there any good resources or tutorials on implementing software floating-point math? Preferably on really limited resources (I don't even have a stack!).


I'd like to support double sized floats. The propeller is a 32 bit MCU, so I'll have to use multiple variables for each float.

I know there is one software-floating-point library for the propeller out there, but it only supports single sized floats.

No, I probably don't really need double sized floats, but this sounds like a really interesting project. Half the reason I want to do this is because I'll learn a lot along the way.

\$\endgroup\$
  • \$\begingroup\$ what compiler? I may have missed it, but I do not see what language you are using. \$\endgroup\$ – Kortuk Jan 4 '12 at 8:53
  • \$\begingroup\$ @Kortuk - I'm personally targeting a Parallax Propeller, so it'll either be Spin or asm. However, I think this shouldn't be too language specific. Assume I have the common operations (+-/* bit-shifting, bitwise and/or/etc..) . \$\endgroup\$ – Connor Wolf Jan 4 '12 at 9:27
  • \$\begingroup\$ What operations do you need to implement ? If you just want add, subtract and multiply, and you're not too worried about edge cases, NaNs, etc, then it should be pretty trivial to implement this. I've done it for 8 bit micro-controllers in the past and it's not a mammoth task, even if you do it all in asm. \$\endgroup\$ – Paul R Jan 4 '12 at 11:47
  • 1
    \$\begingroup\$ Well as you say, you'll learn a lot about implementing floating point operations along the way. \$\endgroup\$ – Paul R Jan 4 '12 at 11:53
  • 3
    \$\begingroup\$ Maybe you don't need floating point. If you just need fractional numbers also fixed point arithmetic with decimal (actual binary) point shifted some places to the left can do. Can you tell more about your application? \$\endgroup\$ – Curd Jan 4 '12 at 13:16
4
\$\begingroup\$

If you want to do it yourself, I'd say just do it.

I guess you wont find too many resources or tutorial because there is not much to it.

Here is an outline:

  • adding/subtracting:
    if exponents differ too much (more than the mantissa has bits):
    just return the value with larger exponent (if this is the subtrahend: negate)

    if exponents are similar:
    shift the mantissa of smaller value by difference of exponents and add to/subtract from other mantissa (using fixed point arithmetic)
    if result is not 0: shift mantissa up until MSBit of result is 1 and decrement exponent the same amount

  • multiplication/division:
    multiply/divide mantissas (using fixed point arithmetic) and add/subtract exponents

\$\endgroup\$
2
\$\begingroup\$

You should be able to use this multiple-precision floating-point library on the Propeller, with either Catalina C or gcc. It might be too slow for many applications, however.

\$\endgroup\$
  • \$\begingroup\$ Can C code on the propeller interoperate with Spin or prop-asm? If not, I might have a go at translating it to spin. Fortunately, I don't need much speed. Realistically, I need to do 7 operations, at 2 hz. \$\endgroup\$ – Connor Wolf Jan 4 '12 at 11:40
  • 2
    \$\begingroup\$ Oh boy, the source alone is 1.1 MB, zipped. I think it's a bit overkill. Are there any simpler options? \$\endgroup\$ – Connor Wolf Jan 4 '12 at 11:42
  • 2
    \$\begingroup\$ More importantly, this library (1) is about arbitrary-precision floating point (not native size like 32-bit and 64-bit) and (2) it targets Linux compilers on i386 and x64 Intel, AMD, and MIPS processors. There is a mention of 'arm' and 'generic' in the source folders, but I would not start here. \$\endgroup\$ – Kevin Vermeer Jan 4 '12 at 14:35
2
\$\begingroup\$

It looks like this question has taken on the slant of seeking understanding more than solving the problem, so this may not be the most useful answer, but just for sake of completeness

http://code.google.com/p/propgcc/wiki/PropGccCompileOptions

Implies that the propeller version of GCC has floating point support, including doubles.

GCC and its compiler libraries are of course open source, though there may be a real learning curve before you could start to see what the code is doing.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.