|
|
Recursive Formulas for B/A
Explicit form:
Find B/A where B and A are real numbers and B > 0
Recursive form:
Convert B and A to scientific notation base 2 (C++ has function
"frexp" for this). Note: mantissa is ³ .5
and < 1.
Let
a = mantissa of A
b = mantissa of B
exp = exponent of b - exponent of a
x0 = 1
xn+1 = xn(2 - a xn)
Reiterate x until desired precision reached. Result only has to be close,
not perfect. I suggest about 5 times.
y0 = b xn
yi+1 = yi + xn(b - a yi)
Reiterate y until desired precision reached.
B / A = yi * 2exp
Example: 314.51 / 5.6789
Written in base-2 scientific notation:
B = 0.61357421875 * 29
A = 0.7098625 * 23
exp = 9 - 3 = 6
iteration |
value |
x0 |
1 |
x1 |
1.2901375 |
x2 |
1.398740976607287 |
x3 |
1.408652781763906 |
x4 |
1.408723516847958
(will use this value for x) |
iteration |
value |
y0 |
0.864356431284738 |
y1 |
0.864356433463227 |
y2 |
0.864356433463227 |
y3 |
0.864356433463227 |
y4 |
0.864356433463227 |
y5 |
0.864356433463227 |
B / A = 0.864356433463227 * 26 =
55.318811741710538
55.318811741710538 (true value)
Source: Jeff Yates, et al.
|
|
|