For the purposes of this question, I am not able to use printf objects (I cannot say why, unfortunately, but let me assume that now I know what I'm doing).
For the IEEE754 single precision number, you have the following bits:
SEEE EEEE EFFF FFFF FFFF FFFF FFFF FFFF
where S is the sign, E is the exponent, and F is the proportion.
Printing a character is relatively easy for all cases, as it catches all special cases, such as NaN ( E == 0xff, F != 0 ), Inf ( E == 0xff, F == 0 ) and 0 ( E == 0, F == 0 , is considered special simply because in this case the exponential offset is not used).
I have two questions.
First, what is the best way to turn denormalized numbers (where E == 0, F != 0 ) into normalized numbers (where 1 <= E <= 0xfe )? I suspect that this will be necessary to simplify the answer to the following question (but I may be wrong, so feel free to educate me).
The second question is how to print normalized numbers. I want to be able to print them in two ways: exponential, such as -3.74195E3 and -3.74195E3 , like 3741.95 . Although, just looking at these two side by side, it should be quite easy to turn the first into the last, simply by moving the decimal point around. So let's just focus on exponential form.
I have a vague recollection of an algorithm that I used a long time ago to print PI, where you used one of the ever-decreasing formulas and kept the upper and lower limit of possibilities, displaying a digit when both limits are matched, and the offset calculation is 10 times (therefore, when the upper and lower limits were 3.2364 and 3.1234 , you could output 3 and adjust for this in the calculation).
But that was a long time ago since I did this, so I donโt even know if this is the right approach. It seems, since the value of each bit is half that of the previous bit when moving along the fractional part ( 1/2 , 1/4 , 1/8 , etc.).
I would prefer that I do not have to wade through the printf source code if it is absolutely necessary, so if someone can help with this, I will be infinitely grateful.