0
$\begingroup$

Is there any generic algorithm which implements a floating point radix conversion?

Lets say we have a $p$-digit FP number

$A = \sum_{i=0}^{p-1} A_i \beta^{e-i}$

in radix $\beta$ and with $0 \leq A_i < \beta$.

How do we find the $A'_i$, $e'$ values for the $p'$-digit base $\gamma$ FP number

$A' = \sum_{i=0}^{p'-1} A'_i \gamma^{e'-i}$

closest to $A$?

There is one question which explicitly asks about radix 2 to radix 10 conversion, but unfortunately the answers seem to be specific for these radix combination. Here I ask about the general case.

Also is an intermediate arbitrary precision FP calculation really necessary? (as in the function strtod in David Gay's dtoa.c)

$\endgroup$

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • $\begingroup$ Except $A$ and $A'$, do all other variables taking integer values only? Are $p'$ and $\gamma$ given? $\endgroup$ – Apass.Jack Nov 20 '18 at 12:22
0
$\begingroup$

In the worst case, you may need very high precision intermediate results. If your problem is limited, for example p ≤ 50 and e ≤ 1,000, it will be possible to prove how much precision is needed at most - with $1000 \cdot 10^{50}$ possible values to convert, 200 bits precision are likely enough.

In practice, many values can be calculated rounded correctly (including proof) with just a bit of extra precision. So you can do the calculation with relatively few extra bits of precision, check if you have a proven correctly rounded result, and do the same calculation with more bits if needed.

$\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.