I am trying to build a class where user can compute floating operations with a particular accuracy. For example, if the user wants to have up to 4 digit accuracy, everything less than 0.0001 is zero and everything bigger than 9999 is inf.
I think the best way is to create a bit (or maybe byte) array to store sign, mantissa and exponent. For istance, with 4 (decimal) digits accuracy I could calculate how many bits I would need to store smallest and biggest value and then create array of that size.
This leads me to two of my questions :
- Why does single precision use exactly 8 bits for the exponent and 24 for the mantissa (IEEE 754) rather than 10 and 53, or 12 and 51? Is it somehow relevant or is it just a standard?
- Assuming I need 4 digit precision for 9999, I would need 14 bits but how much space do I need to keep 0.0001 in 4 (decimal) digit accuracy?
If the answer for the 1st question is "it is just a standard" I have yet another question :
- How do I choose the best exponent and mantissa for my problem?
Please disregard the fact numbers bigger and smaller might be calculated here as I will just 'if' them out. I do not want to use double/float/etc for this I need as I expect to use more memory than a double would need but I do not want to use too much space.