0

Assuming I have a number of the form $a * 2^b$, I want to represent it in the form $c * 10^d$. I want to do this conversion without calculating neither $a*2^b$ or $2^b$

Currently, as per this question I'm using:

$d = ⌊b * (ln(2)/ln(10))⌋$ to calculate the exponent

$c = A * 10^{-d}*2^{b}$ to calculate the significant

However, this forces us to solve the exponents which for large enough $b$ is impractical (in a computer science environment). Is there any better way to do this conversion? If not, is there a good way to approximate it?

  • In a computer science environment, any algorithm becomes impractical given large enough input numbers. Could you be a bit more specific about the kind of numbers you are concerned with and what the impracticalities were? For example, given a very large number of the form $2^b$ multiplied by a very small number of the form $10^{-d}$, my first thought would be to compute logarithms of both numbers, add, and take an antilogarithm. Although I would do the whole exercise a little bit differently in the first place; see my answer to the linked question, just posted a few minutes ago. – David K Jan 19 '22 at 04:06
  • The solution you posted on the linked question seems to elegantly solve my problem, thanks! For completeness, in my case, as a programing exercise and as a library to use in a future project, I wanted to store an efficient (if inaccurate) large number where the exponent could grow up to 2^32. I use 2 as a base here for performance reasons when operating on the numbers, but a method for converting to base 10 for display purposes is needed. As such, it didn't have to be more than an approximation and performance isn't a huge concern, but since the exponent grows fast it couldn't calculate 2^n – Fowlron Jan 19 '22 at 04:23

0 Answers0