digitalmars.D.learn - Printing a floats in maximum precision
- =?UTF-8?B?Tm9yZGzDtnc=?= (1/1) Jan 17 2017 What's the easiest way to print a double in maximum precision?
- pineapple (5/6) Jan 17 2017 https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric...
- Nicholas Wilson (2/8) Jan 17 2017 Alternatively use %a to print in hex to verify exact bit patterns.
- kinke (3/5) Jan 18 2017 +1, if it doesn't have to be human-readable.
- Basile B. (11/12) Jan 17 2017 %.6g for floats and %.17g for doubles. This is for example what's
What's the easiest way to print a double in maximum precision?
Jan 17 2017
On Wednesday, 18 January 2017 at 00:09:42 UTC, Nordlöw wrote:What's the easiest way to print a double in maximum precision?https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric/floats.d#L60 You can also try the formatting directive "%.20f" but unlike the former I can't offer any guarantees of its accuracy (it's probably accurate)
Jan 17 2017
On Wednesday, 18 January 2017 at 00:23:37 UTC, pineapple wrote:On Wednesday, 18 January 2017 at 00:09:42 UTC, Nordlöw wrote:Alternatively use %a to print in hex to verify exact bit patterns.What's the easiest way to print a double in maximum precision?https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric/floats.d#L60 You can also try the formatting directive "%.20f" but unlike the former I can't offer any guarantees of its accuracy (it's probably accurate)
Jan 17 2017
On Wednesday, 18 January 2017 at 03:36:39 UTC, Nicholas Wilson wrote:Alternatively use %a to print in hex to verify exact bit patterns.+1, if it doesn't have to be human-readable.
Jan 18 2017
On Wednesday, 18 January 2017 at 00:09:42 UTC, Nordlöw wrote:What's the easiest way to print a double in maximum precision?%.6g for floats and %.17g for doubles. This is for example what's used on std.json to get a perfect conversion from string to value. the number is the maximum number of digits in the fractional part. 6 and 17 are rounded, real values can be found here (https://en.wikipedia.org/wiki/Floating_point#Internal_representation) see also: and this https://github.com/dlang/phobos/pull/4343#issuecomment-220810593
Jan 17 2017