I'm implementing floating-point arithmetic, for a micro-controller which does not support floating point numbers, in either hardware or software.
(Software being "written" in a sort of electrical diagram program.)
I've finished encoding/decoding from/to integers, adding, subtracting, and multiplication.
My "floats" are represented as C * 10^E
, where:
- C, the coefficient, is a 32-bit signed integer in the range 100000000-999999999, or 0.
- (Nine digits of precision, plus the special case of zero.)
- E, the exponent, is a 32-bit signed integer covering the whole 32-bit range.
- (Yes, it's overkill.)
I chose round base-10 numbers to make the verification of the math easy.
My strategy for the multiplication was to split up the two numbers AaaBbbCcc
and DddEeeFff
into three pieces each (millions, thousands, and ones) and compute the multiplication as
(ABC * 10^Y) * (DEF * 10^Z) =
((AD * 10^12) +
((AE + BD) * 10^9) +
((AF + BE + CD) * 10^6) +
((BF + CE) * 10^3) +
(CF * 10^0))
* 10^Y+Z
Each *
and +
representing a normal multiplication or addition, and 10^N being faked with me hard-coding in a 1000, 1000000, etc.
Also note that this neither recurses or loops, and any answer cannot recurse or loop.
I've got access to integer addition, subtraction, division, multiplication, modulo, cos/sin/tan/arccos/arcsin/arctan, absolute value, and square root.
Main Question:
I can/will eventually figure out how to do division with a similar approach of splitting the coefficients into smaller numbers which will be better for 32-bit division. I haven't done my algebra in a long time, so multiplication took me about a day and a half. Since I presume division to be more complicated conceptually, it would be super handy if somebody on SE could do the hard math for me. So, how do I do this?