Precision, new prices
Saaa
empty at needmail.com
Sat Jul 25 06:03:11 PDT 2009
Ok it finally hit me :(
The 24 fraction bits in a float aren't used like an integer (2^24 giving max
7 decimal digits precision)
they are used by halving the value of the previous bit: 1, 0.5, 0.25 ...
like fractions !!!
this of course has a much wider decimal range (something like 20 or so)
because not all numbers are
represented.
Thus, the formatting %.100g and downs code both just give the correct answer
.
Now, there are 2^24 different floats being represented (ignoring exponent)
so the question for me now is:
What is the minimal (decimal) representation of a float for which the
following holds:
float f; //for all possible floats
string s = format(f);
float f2 = to!(float)(s);
assert(f == f2);
Does your second code hold, downs?
More information about the Digitalmars-d-learn
mailing list