"Jarrett Billingsley" <jarrett.billings...@gmail.com> wrote in message news:mailman.51.1247352795.14071.digitalmars-d-le...@puremagic.com... > On Sat, Jul 11, 2009 at 6:44 PM, Saaa<em...@needmail.com> wrote: >>> double d[2] = [ 0, 1, double.max]; >>> char[] c = format(d); >>> >>> How do I get c to represent full precision? >>> >>> "[0,1,1.7976931348623157e+308]" // but then with double.max being >>> represented fully >> >>> You want a 309-digit number consisting mostly of 0s? >> >> Yes, but only if they are necessary. >> 0 doesn't need all hose digits for instance. > > Um, doubles don't have infinite precision. See those digits that it > output? That's all you get. Those are the only digits that are > necessary because those are the only digits that are *stored*. Just > because it's followed by almost 300 0s doesn't mean that 300 0s are > actually stored in the number; it just means the exponent is that > large.
I now see what you mean by 309 digits.. No I don't want that !! :D string.format does only 6 digits by default, I added the extra double.max digits in myself from wikipedia :) I overestimated the precision of a double, my bad. (53bits != 309 digits !) How can I format to the full number of digits, like I did for c? > >> What else is the point in saving doubles. > > If you're saving doubles in a textual format, try using the %a format > specifier. It outputs a float in hexadecimal notation, which is a bit > more precise than decimal (since no rounding has to be performed). I > don't know if Phobos' unformatting can actually _read_ hex floats, > though. I could add the option, but for now I'm going for human readability