From Jason Turner

[istream.formatted.arithmetic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpm_64m5pc/{from.md → to.md} +66 -28
tmp/tmpm_64m5pc/{from.md → to.md} RENAMED
@@ -1,33 +1,32 @@
1
  ##### Arithmetic extractors <a id="istream.formatted.arithmetic">[[istream.formatted.arithmetic]]</a>
2
 
3
  ``` cpp
4
- operator>>(unsigned short& val);
5
- operator>>(unsigned int& val);
6
- operator>>(long& val);
7
- operator>>(unsigned long& val);
8
- operator>>(long long& val);
9
- operator>>(unsigned long long& val);
10
- operator>>(float& val);
11
- operator>>(double& val);
12
- operator>>(long double& val);
13
- operator>>(bool& val);
14
- operator>>(void*& val);
15
  ```
16
 
17
  As in the case of the inserters, these extractors depend on the locale’s
18
  `num_get<>` [[locale.num.get]] object to perform parsing the input
19
  stream data. These extractors behave as formatted input functions (as
20
- described in  [[istream.formatted.reqmts]]). After a sentry object is
21
  constructed, the conversion occurs as if performed by the following code
22
- fragment:
 
23
 
24
  ``` cpp
25
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
26
- iostate err = iostate::goodbit;
27
- use_facet<numget>(loc).get(*this, 0, *this, err, val);
28
- setstate(err);
29
  ```
30
 
31
  In the above fragment, `loc` stands for the private member of the
32
  `basic_ios` class.
33
 
@@ -38,50 +37,89 @@ directly. — *end note*]
38
 
39
  Class `locale` relies on this type as its interface to `istream`, so
40
  that it does not need to depend directly on `istream`.
41
 
42
  ``` cpp
43
- operator>>(short& val);
44
  ```
45
 
46
  The conversion occurs as if performed by the following code fragment
47
  (using the same notation as for the preceding code fragment):
48
 
49
  ``` cpp
50
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
51
- iostate err = ios_base::goodbit;
52
  long lval;
53
- use_facet<numget>(loc).get(*this, 0, *this, err, lval);
54
  if (lval < numeric_limits<short>::min()) {
55
- err |= ios_base::failbit;
56
  val = numeric_limits<short>::min();
57
  } else if (numeric_limits<short>::max() < lval) {
58
- err |= ios_base::failbit;
59
  val = numeric_limits<short>::max();
60
  } else
61
  val = static_cast<short>(lval);
62
- setstate(err);
63
  ```
64
 
65
  ``` cpp
66
- operator>>(int& val);
67
  ```
68
 
69
  The conversion occurs as if performed by the following code fragment
70
  (using the same notation as for the preceding code fragment):
71
 
72
  ``` cpp
73
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
74
- iostate err = ios_base::goodbit;
75
  long lval;
76
- use_facet<numget>(loc).get(*this, 0, *this, err, lval);
77
  if (lval < numeric_limits<int>::min()) {
78
- err |= ios_base::failbit;
79
  val = numeric_limits<int>::min();
80
  } else if (numeric_limits<int>::max() < lval) {
81
- err |= ios_base::failbit;
82
  val = numeric_limits<int>::max();
83
  } else
84
  val = static_cast<int>(lval);
85
- setstate(err);
86
  ```
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ##### Arithmetic extractors <a id="istream.formatted.arithmetic">[[istream.formatted.arithmetic]]</a>
2
 
3
  ``` cpp
4
+ basic_istream& operator>>(unsigned short& val);
5
+ basic_istream& operator>>(unsigned int& val);
6
+ basic_istream& operator>>(long& val);
7
+ basic_istream& operator>>(unsigned long& val);
8
+ basic_istream& operator>>(long long& val);
9
+ basic_istream& operator>>(unsigned long long& val);
10
+ basic_istream& operator>>(float& val);
11
+ basic_istream& operator>>(double& val);
12
+ basic_istream& operator>>(long double& val);
13
+ basic_istream& operator>>(bool& val);
14
+ basic_istream& operator>>(void*& val);
15
  ```
16
 
17
  As in the case of the inserters, these extractors depend on the locale’s
18
  `num_get<>` [[locale.num.get]] object to perform parsing the input
19
  stream data. These extractors behave as formatted input functions (as
20
+ described in  [[istream.formatted.reqmts]]). After a `sentry` object is
21
  constructed, the conversion occurs as if performed by the following code
22
+ fragment, where `state` represents the input function’s local error
23
+ state:
24
 
25
  ``` cpp
26
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
27
+ use_facet<numget>(loc).get(*this, 0, *this, state, val);
 
 
28
  ```
29
 
30
  In the above fragment, `loc` stands for the private member of the
31
  `basic_ios` class.
32
 
 
37
 
38
  Class `locale` relies on this type as its interface to `istream`, so
39
  that it does not need to depend directly on `istream`.
40
 
41
  ``` cpp
42
+ basic_istream& operator>>(short& val);
43
  ```
44
 
45
  The conversion occurs as if performed by the following code fragment
46
  (using the same notation as for the preceding code fragment):
47
 
48
  ``` cpp
49
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
 
50
  long lval;
51
+ use_facet<numget>(loc).get(*this, 0, *this, state, lval);
52
  if (lval < numeric_limits<short>::min()) {
53
+ state |= ios_base::failbit;
54
  val = numeric_limits<short>::min();
55
  } else if (numeric_limits<short>::max() < lval) {
56
+ state |= ios_base::failbit;
57
  val = numeric_limits<short>::max();
58
  } else
59
  val = static_cast<short>(lval);
 
60
  ```
61
 
62
  ``` cpp
63
+ basic_istream& operator>>(int& val);
64
  ```
65
 
66
  The conversion occurs as if performed by the following code fragment
67
  (using the same notation as for the preceding code fragment):
68
 
69
  ``` cpp
70
  using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
 
71
  long lval;
72
+ use_facet<numget>(loc).get(*this, 0, *this, state, lval);
73
  if (lval < numeric_limits<int>::min()) {
74
+ state |= ios_base::failbit;
75
  val = numeric_limits<int>::min();
76
  } else if (numeric_limits<int>::max() < lval) {
77
+ state |= ios_base::failbit;
78
  val = numeric_limits<int>::max();
79
  } else
80
  val = static_cast<int>(lval);
 
81
  ```
82
 
83
+ ``` cpp
84
+ basic_istream& operator>>(extended-floating-point-type& val);
85
+ ```
86
+
87
+ If the floating-point conversion rank of
88
+ *`extended-floating-point-type`* is not less than or equal to that of
89
+ `long double`, then an invocation of the operator function is
90
+ conditionally supported with *implementation-defined* semantics.
91
+
92
+ Otherwise, let `FP` be a standard floating-point type:
93
+
94
+ - if the floating-point conversion rank of
95
+ *`extended-floating-point-type`* is less than or equal to that of
96
+ `float`, then `FP` is `float`,
97
+ - otherwise, if the floating-point conversion rank of
98
+ *`extended-floating-point-type`* is less than or equal to that of
99
+ `double`, then `FP` is `double`,
100
+ - otherwise, `FP` is `long double`.
101
+
102
+ The conversion occurs as if performed by the following code fragment
103
+ (using the same notation as for the preceding code fragment):
104
+
105
+ ``` cpp
106
+ using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
107
+ FP fval;
108
+ use_facet<numget>(loc).get(*this, 0, *this, state, fval);
109
+ if (fval < -numeric_limits<extended-floating-point-type>::max()) {
110
+ state |= ios_base::failbit;
111
+ val = -numeric_limits<extended-floating-point-type>::max();
112
+ } else if (numeric_limits<extended-floating-point-type>::max() < fval) {
113
+ state |= ios_base::failbit;
114
+ val = numeric_limits<extended-floating-point-type>::max();
115
+ } else {
116
+ val = static_cast<extended-floating-point-type>(fval);
117
+ }
118
+ ```
119
+
120
+ [*Note 2*: When the extended floating-point type has a floating-point
121
+ conversion rank that is not equal to the rank of any standard
122
+ floating-point type, then double rounding during the conversion can
123
+ result in inaccurate results. `from_chars` can be used in situations
124
+ where maximum accuracy is important. — *end note*]
125
+