From Jason Turner

[charconv.to.chars]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpifjjhw5c/{from.md → to.md} +95 -0
tmp/tmpifjjhw5c/{from.md → to.md} RENAMED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Primitive numeric output conversion <a id="charconv.to.chars">[[charconv.to.chars]]</a>
2
+
3
+ All functions named `to_chars` convert `value` into a character string
4
+ by successively filling the range \[`first`, `last`), where \[`first`,
5
+ `last`) is required to be a valid range. If the member `ec` of the
6
+ return value is such that the value is equal to the value of a
7
+ value-initialized `errc`, the conversion was successful and the member
8
+ `ptr` is the one-past-the-end pointer of the characters written.
9
+ Otherwise, the member `ec` has the value `errc::value_too_large`, the
10
+ member `ptr` has the value `last`, and the contents of the range
11
+ \[`first`, `last`) are unspecified.
12
+
13
+ The functions that take a floating-point `value` but not a `precision`
14
+ parameter ensure that the string representation consists of the smallest
15
+ number of characters such that there is at least one digit before the
16
+ radix point (if present) and parsing the representation using the
17
+ corresponding `from_chars` function recovers `value` exactly.
18
+
19
+ [*Note 1*: This guarantee applies only if `to_chars` and `from_chars`
20
+ are executed on the same implementation. — *end note*]
21
+
22
+ If there are several such representations, the representation with the
23
+ smallest difference from the floating-point argument value is chosen,
24
+ resolving any remaining ties using rounding according to
25
+ `round_to_nearest` [[round.style]].
26
+
27
+ The functions taking a `chars_format` parameter determine the conversion
28
+ specifier for `printf` as follows: The conversion specifier is `f` if
29
+ `fmt` is `chars_format::fixed`, `e` if `fmt` is
30
+ `chars_format::scientific`, `a` (without leading `"0x"` in the result)
31
+ if `fmt` is `chars_format::hex`, and `g` if `fmt` is
32
+ `chars_format::general`.
33
+
34
+ ``` cpp
35
+ to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
36
+ ```
37
+
38
+ *Preconditions:* `base` has a value between 2 and 36 (inclusive).
39
+
40
+ *Effects:* The value of `value` is converted to a string of digits in
41
+ the given base (with no redundant leading zeroes). Digits in the range
42
+ 10..35 (inclusive) are represented as lowercase characters `a`..`z`. If
43
+ `value` is less than zero, the representation starts with `’-’`.
44
+
45
+ *Throws:* Nothing.
46
+
47
+ *Remarks:* The implementation shall provide overloads for all signed and
48
+ unsigned integer types and `char` as the type of the parameter `value`.
49
+
50
+ ``` cpp
51
+ to_chars_result to_chars(char* first, char* last, float value);
52
+ to_chars_result to_chars(char* first, char* last, double value);
53
+ to_chars_result to_chars(char* first, char* last, long double value);
54
+ ```
55
+
56
+ *Effects:* `value` is converted to a string in the style of `printf` in
57
+ the `"C"` locale. The conversion specifier is `f` or `e`, chosen
58
+ according to the requirement for a shortest representation (see above);
59
+ a tie is resolved in favor of `f`.
60
+
61
+ *Throws:* Nothing.
62
+
63
+ ``` cpp
64
+ to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
65
+ to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
66
+ to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
67
+ ```
68
+
69
+ *Preconditions:* `fmt` has the value of one of the enumerators of
70
+ `chars_format`.
71
+
72
+ *Effects:* `value` is converted to a string in the style of `printf` in
73
+ the `"C"` locale.
74
+
75
+ *Throws:* Nothing.
76
+
77
+ ``` cpp
78
+ to_chars_result to_chars(char* first, char* last, float value,
79
+ chars_format fmt, int precision);
80
+ to_chars_result to_chars(char* first, char* last, double value,
81
+ chars_format fmt, int precision);
82
+ to_chars_result to_chars(char* first, char* last, long double value,
83
+ chars_format fmt, int precision);
84
+ ```
85
+
86
+ *Preconditions:* `fmt` has the value of one of the enumerators of
87
+ `chars_format`.
88
+
89
+ *Effects:* `value` is converted to a string in the style of `printf` in
90
+ the `"C"` locale with the given precision.
91
+
92
+ *Throws:* Nothing.
93
+
94
+ See also: ISO C 7.21.6.1
95
+