From Jason Turner

[limits]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpscnq4zx1/{from.md → to.md} +0 -553
tmp/tmpscnq4zx1/{from.md → to.md} RENAMED
@@ -1,553 +0,0 @@
1
- ### Numeric limits <a id="limits">[[limits]]</a>
2
-
3
- #### Class template `numeric_limits` <a id="limits.numeric">[[limits.numeric]]</a>
4
-
5
- The `numeric_limits` class template provides a C++program with
6
- information about various properties of the implementation’s
7
- representation of the arithmetic types.
8
-
9
- Specializations shall be provided for each arithmetic type, both
10
- floating point and integer, including `bool`. The member
11
- `is_specialized` shall be `true` for all such specializations of
12
- `numeric_limits`.
13
-
14
- For all members declared `static` `constexpr` in the `numeric_limits`
15
- template, specializations shall define these values in such a way that
16
- they are usable as constant expressions.
17
-
18
- Non-arithmetic standard types, such as `complex<T>` ([[complex]]),
19
- shall not have specializations.
20
-
21
- #### Header `<limits>` synopsis <a id="limits.syn">[[limits.syn]]</a>
22
-
23
- ``` cpp
24
- namespace std {
25
- template<class T> class numeric_limits;
26
- enum float_round_style;
27
- enum float_denorm_style;
28
-
29
- template<> class numeric_limits<bool>;
30
-
31
- template<> class numeric_limits<char>;
32
- template<> class numeric_limits<signed char>;
33
- template<> class numeric_limits<unsigned char>;
34
- template<> class numeric_limits<char16_t>;
35
- template<> class numeric_limits<char32_t>;
36
- template<> class numeric_limits<wchar_t>;
37
-
38
- template<> class numeric_limits<short>;
39
- template<> class numeric_limits<int>;
40
- template<> class numeric_limits<long>;
41
- template<> class numeric_limits<long long>;
42
- template<> class numeric_limits<unsigned short>;
43
- template<> class numeric_limits<unsigned int>;
44
- template<> class numeric_limits<unsigned long>;
45
- template<> class numeric_limits<unsigned long long>;
46
-
47
- template<> class numeric_limits<float>;
48
- template<> class numeric_limits<double>;
49
- template<> class numeric_limits<long double>;
50
- }
51
- ```
52
-
53
- #### Class template `numeric_limits` <a id="numeric.limits">[[numeric.limits]]</a>
54
-
55
- ``` cpp
56
- namespace std {
57
- template<class T> class numeric_limits {
58
- public:
59
- static constexpr bool is_specialized = false;
60
- static constexpr T min() noexcept { return T(); }
61
- static constexpr T max() noexcept { return T(); }
62
- static constexpr T lowest() noexcept { return T(); }
63
-
64
- static constexpr int digits = 0;
65
- static constexpr int digits10 = 0;
66
- static constexpr int max_digits10 = 0;
67
- static constexpr bool is_signed = false;
68
- static constexpr bool is_integer = false;
69
- static constexpr bool is_exact = false;
70
- static constexpr int radix = 0;
71
- static constexpr T epsilon() noexcept { return T(); }
72
- static constexpr T round_error() noexcept { return T(); }
73
-
74
- static constexpr int min_exponent = 0;
75
- static constexpr int min_exponent10 = 0;
76
- static constexpr int max_exponent = 0;
77
- static constexpr int max_exponent10 = 0;
78
-
79
- static constexpr bool has_infinity = false;
80
- static constexpr bool has_quiet_NaN = false;
81
- static constexpr bool has_signaling_NaN = false;
82
- static constexpr float_denorm_style has_denorm = denorm_absent;
83
- static constexpr bool has_denorm_loss = false;
84
- static constexpr T infinity() noexcept { return T(); }
85
- static constexpr T quiet_NaN() noexcept { return T(); }
86
- static constexpr T signaling_NaN() noexcept { return T(); }
87
- static constexpr T denorm_min() noexcept { return T(); }
88
-
89
- static constexpr bool is_iec559 = false;
90
- static constexpr bool is_bounded = false;
91
- static constexpr bool is_modulo = false;
92
-
93
- static constexpr bool traps = false;
94
- static constexpr bool tinyness_before = false;
95
- static constexpr float_round_style round_style = round_toward_zero;
96
- };
97
-
98
- template<class T> class numeric_limits<const T>;
99
- template<class T> class numeric_limits<volatile T>;
100
- template<class T> class numeric_limits<const volatile T>;
101
- }
102
- ```
103
-
104
- The default `numeric_limits<T>` template shall have all members, but
105
- with 0 or `false` values.
106
-
107
- The value of each member of a specialization of `numeric_limits` on a
108
- *cv*-qualified type `cv T` shall be equal to the value of the
109
- corresponding member of the specialization on the unqualified type `T`.
110
-
111
- #### `numeric_limits` members <a id="numeric.limits.members">[[numeric.limits.members]]</a>
112
-
113
- ``` cpp
114
- static constexpr T min() noexcept;
115
- ```
116
-
117
- Minimum finite value.[^3]
118
-
119
- For floating types with denormalization, returns the minimum positive
120
- normalized value.
121
-
122
- Meaningful for all specializations in which `is_bounded != false`, or
123
- `is_bounded == false && is_signed == false`.
124
-
125
- ``` cpp
126
- static constexpr T max() noexcept;
127
- ```
128
-
129
- Maximum finite value.[^4]
130
-
131
- Meaningful for all specializations in which `is_bounded != false`.
132
-
133
- ``` cpp
134
- static constexpr T lowest() noexcept;
135
- ```
136
-
137
- A finite value `x` such that there is no other finite value `y` where
138
- `y < x`.[^5]
139
-
140
- Meaningful for all specializations in which `is_bounded != false`.
141
-
142
- ``` cpp
143
- static constexpr int digits;
144
- ```
145
-
146
- Number of `radix` digits that can be represented without change.
147
-
148
- For integer types, the number of non-sign bits in the representation.
149
-
150
- For floating point types, the number of `radix` digits in the
151
- mantissa.[^6]
152
-
153
- ``` cpp
154
- static constexpr int digits10;
155
- ```
156
-
157
- Number of base 10 digits that can be represented without change.[^7]
158
-
159
- Meaningful for all specializations in which `is_bounded != false`.
160
-
161
- ``` cpp
162
- static constexpr int max_digits10;
163
- ```
164
-
165
- Number of base 10 digits required to ensure that values which differ are
166
- always differentiated.
167
-
168
- Meaningful for all floating point types.
169
-
170
- ``` cpp
171
- static constexpr bool is_signed;
172
- ```
173
-
174
- True if the type is signed.
175
-
176
- Meaningful for all specializations.
177
-
178
- ``` cpp
179
- static constexpr bool is_integer;
180
- ```
181
-
182
- True if the type is integer.
183
-
184
- Meaningful for all specializations.
185
-
186
- ``` cpp
187
- static constexpr bool is_exact;
188
- ```
189
-
190
- True if the type uses an exact representation. All integer types are
191
- exact, but not all exact types are integer. For example, rational and
192
- fixed-exponent representations are exact but not integer.
193
-
194
- Meaningful for all specializations.
195
-
196
- ``` cpp
197
- static constexpr int radix;
198
- ```
199
-
200
- For floating types, specifies the base or radix of the exponent
201
- representation (often 2).[^8]
202
-
203
- For integer types, specifies the base of the representation.[^9]
204
-
205
- Meaningful for all specializations.
206
-
207
- ``` cpp
208
- static constexpr T epsilon() noexcept;
209
- ```
210
-
211
- Machine epsilon: the difference between 1 and the least value greater
212
- than 1 that is representable.[^10]
213
-
214
- Meaningful for all floating point types.
215
-
216
- ``` cpp
217
- static constexpr T round_error() noexcept;
218
- ```
219
-
220
- Measure of the maximum rounding error.[^11]
221
-
222
- ``` cpp
223
- static constexpr int min_exponent;
224
- ```
225
-
226
- Minimum negative integer such that `radix` raised to the power of one
227
- less than that integer is a normalized floating point number.[^12]
228
-
229
- Meaningful for all floating point types.
230
-
231
- ``` cpp
232
- static constexpr int min_exponent10;
233
- ```
234
-
235
- Minimum negative integer such that 10 raised to that power is in the
236
- range of normalized floating point numbers.[^13]
237
-
238
- Meaningful for all floating point types.
239
-
240
- ``` cpp
241
- static constexpr int max_exponent;
242
- ```
243
-
244
- Maximum positive integer such that `radix` raised to the power one less
245
- than that integer is a representable finite floating point number.[^14]
246
-
247
- Meaningful for all floating point types.
248
-
249
- ``` cpp
250
- static constexpr int max_exponent10;
251
- ```
252
-
253
- Maximum positive integer such that 10 raised to that power is in the
254
- range of representable finite floating point numbers.[^15]
255
-
256
- Meaningful for all floating point types.
257
-
258
- ``` cpp
259
- static constexpr bool has_infinity;
260
- ```
261
-
262
- True if the type has a representation for positive infinity.
263
-
264
- Meaningful for all floating point types.
265
-
266
- Shall be `true` for all specializations in which `is_iec559 != false`.
267
-
268
- ``` cpp
269
- static constexpr bool has_quiet_NaN;
270
- ```
271
-
272
- True if the type has a representation for a quiet (non-signaling) “Not a
273
- Number.”[^16]
274
-
275
- Meaningful for all floating point types.
276
-
277
- Shall be `true` for all specializations in which `is_iec559 != false`.
278
-
279
- ``` cpp
280
- static constexpr bool has_signaling_NaN;
281
- ```
282
-
283
- True if the type has a representation for a signaling “Not a
284
- Number.”[^17]
285
-
286
- Meaningful for all floating point types.
287
-
288
- Shall be `true` for all specializations in which `is_iec559 != false`.
289
-
290
- ``` cpp
291
- static constexpr float_denorm_style has_denorm;
292
- ```
293
-
294
- `denorm_present` if the type allows denormalized values (variable number
295
- of exponent bits)[^18], `denorm_absent` if the type does not allow
296
- denormalized values, and `denorm_indeterminate` if it is indeterminate
297
- at compile time whether the type allows denormalized values.
298
-
299
- Meaningful for all floating point types.
300
-
301
- ``` cpp
302
- static constexpr bool has_denorm_loss;
303
- ```
304
-
305
- True if loss of accuracy is detected as a denormalization loss, rather
306
- than as an inexact result.[^19]
307
-
308
- ``` cpp
309
- static constexpr T infinity() noexcept;
310
- ```
311
-
312
- Representation of positive infinity, if available.[^20]
313
-
314
- Meaningful for all specializations for which `has_infinity != false`.
315
- Required in specializations for which `is_iec559 != false`.
316
-
317
- ``` cpp
318
- static constexpr T quiet_NaN() noexcept;
319
- ```
320
-
321
- Representation of a quiet “Not a Number,” if available.[^21]
322
-
323
- Meaningful for all specializations for which `has_quiet_NaN != false`.
324
- Required in specializations for which `is_iec559 != false`.
325
-
326
- ``` cpp
327
- static constexpr T signaling_NaN() noexcept;
328
- ```
329
-
330
- Representation of a signaling “Not a Number,” if available.[^22]
331
-
332
- Meaningful for all specializations for which
333
- `has_signaling_NaN != false`. Required in specializations for which
334
- `is_iec559 != false`.
335
-
336
- ``` cpp
337
- static constexpr T denorm_min() noexcept;
338
- ```
339
-
340
- Minimum positive denormalized value.[^23]
341
-
342
- Meaningful for all floating point types.
343
-
344
- In specializations for which `has_denorm == false`, returns the minimum
345
- positive normalized value.
346
-
347
- ``` cpp
348
- static constexpr bool is_iec559;
349
- ```
350
-
351
- True if and only if the type adheres to IEC 559 standard.[^24]
352
-
353
- Meaningful for all floating point types.
354
-
355
- ``` cpp
356
- static constexpr bool is_bounded;
357
- ```
358
-
359
- True if the set of values representable by the type is finite.[^25] All
360
- fundamental types ([[basic.fundamental]]) are bounded. This member
361
- would be false for arbitrary precision types.
362
-
363
- Meaningful for all specializations.
364
-
365
- ``` cpp
366
- static constexpr bool is_modulo;
367
- ```
368
-
369
- True if the type is modulo.[^26] A type is modulo if, for any operation
370
- involving `+`, `-`, or `*` on values of that type whose result would
371
- fall outside the range \[`min()`, `max()`\], the value returned differs
372
- from the true value by an integer multiple of `max() - min() + 1`.
373
-
374
- On most machines, this is `false` for floating types, `true` for
375
- unsigned integers, and `true` for signed integers.
376
-
377
- Meaningful for all specializations.
378
-
379
- ``` cpp
380
- static constexpr bool traps;
381
- ```
382
-
383
- `true` if, at program startup, there exists a value of the type that
384
- would cause an arithmetic operation using that value to trap.[^27]
385
-
386
- Meaningful for all specializations.
387
-
388
- ``` cpp
389
- static constexpr bool tinyness_before;
390
- ```
391
-
392
- `true` if tinyness is detected before rounding.[^28]
393
-
394
- Meaningful for all floating point types.
395
-
396
- ``` cpp
397
- static constexpr float_round_style round_style;
398
- ```
399
-
400
- The rounding style for the type.[^29]
401
-
402
- Meaningful for all floating point types. Specializations for integer
403
- types shall return `round_toward_zero`.
404
-
405
- #### Type `float_round_style` <a id="round.style">[[round.style]]</a>
406
-
407
- ``` cpp
408
- namespace std {
409
- enum float_round_style {
410
- round_indeterminate = -1,
411
- round_toward_zero = 0,
412
- round_to_nearest = 1,
413
- round_toward_infinity = 2,
414
- round_toward_neg_infinity = 3
415
- };
416
- }
417
- ```
418
-
419
- The rounding mode for floating point arithmetic is characterized by the
420
- values:
421
-
422
- - `round_indeterminate` if the rounding style is indeterminable
423
- - `round_toward_zero` if the rounding style is toward zero
424
- - `round_to_nearest` if the rounding style is to the nearest
425
- representable value
426
- - `round_toward_infinity` if the rounding style is toward infinity
427
- - `round_toward_neg_infinity` if the rounding style is toward negative
428
- infinity
429
-
430
- #### Type `float_denorm_style` <a id="denorm.style">[[denorm.style]]</a>
431
-
432
- ``` cpp
433
- namespace std {
434
- enum float_denorm_style {
435
- denorm_indeterminate = -1,
436
- denorm_absent = 0,
437
- denorm_present = 1
438
- };
439
- }
440
- ```
441
-
442
- The presence or absence of denormalization (variable number of exponent
443
- bits) is characterized by the values:
444
-
445
- - `denorm_indeterminate` if it cannot be determined whether or not the
446
- type allows denormalized values
447
- - `denorm_absent` if the type does not allow denormalized values
448
- - `denorm_present` if the type does allow denormalized values
449
-
450
- #### `numeric_limits` specializations <a id="numeric.special">[[numeric.special]]</a>
451
-
452
- All members shall be provided for all specializations. However, many
453
- values are only required to be meaningful under certain conditions (for
454
- example, `epsilon()` is only meaningful if `is_integer` is `false`). Any
455
- value that is not “meaningful” shall be set to 0 or `false`.
456
-
457
- ``` cpp
458
- namespace std {
459
- template<> class numeric_limits<float> {
460
- public:
461
- static constexpr bool is_specialized = true;
462
-
463
- inline static constexpr float min() noexcept { return 1.17549435E-38F; }
464
- inline static constexpr float max() noexcept { return 3.40282347E+38F; }
465
- inline static constexpr float lowest() noexcept { return -3.40282347E+38F; }
466
-
467
- static constexpr int digits = 24;
468
- static constexpr int digits10 = 6;
469
- static constexpr int max_digits10 = 9;
470
-
471
- static constexpr bool is_signed = true;
472
- static constexpr bool is_integer = false;
473
- static constexpr bool is_exact = false;
474
-
475
- static constexpr int radix = 2;
476
- inline static constexpr float epsilon() noexcept { return 1.19209290E-07F; }
477
- inline static constexpr float round_error() noexcept { return 0.5F; }
478
-
479
- static constexpr int min_exponent = -125;
480
- static constexpr int min_exponent10 = - 37;
481
- static constexpr int max_exponent = +128;
482
- static constexpr int max_exponent10 = + 38;
483
-
484
- static constexpr bool has_infinity = true;
485
- static constexpr bool has_quiet_NaN = true;
486
- static constexpr bool has_signaling_NaN = true;
487
- static constexpr float_denorm_style has_denorm = denorm_absent;
488
- static constexpr bool has_denorm_loss = false;
489
-
490
- inline static constexpr float infinity() noexcept { return value; }
491
- inline static constexpr float quiet_NaN() noexcept { return value; }
492
- inline static constexpr float signaling_NaN() noexcept { return value; }
493
- inline static constexpr float denorm_min() noexcept { return min(); }
494
-
495
- static constexpr bool is_iec559 = true;
496
- static constexpr bool is_bounded = true;
497
- static constexpr bool is_modulo = false;
498
- static constexpr bool traps = true;
499
- static constexpr bool tinyness_before = true;
500
-
501
- static constexpr float_round_style round_style = round_to_nearest;
502
- };
503
- }
504
- ```
505
-
506
- The specialization for `bool` shall be provided as follows:
507
-
508
- ``` cpp
509
- namespace std {
510
- template<> class numeric_limits<bool> {
511
- public:
512
- static constexpr bool is_specialized = true;
513
- static constexpr bool min() noexcept { return false; }
514
- static constexpr bool max() noexcept { return true; }
515
- static constexpr bool lowest() noexcept { return false; }
516
-
517
- static constexpr int digits = 1;
518
- static constexpr int digits10 = 0;
519
- static constexpr int max_digits10 = 0;
520
-
521
- static constexpr bool is_signed = false;
522
- static constexpr bool is_integer = true;
523
- static constexpr bool is_exact = true;
524
- static constexpr int radix = 2;
525
- static constexpr bool epsilon() noexcept { return 0; }
526
- static constexpr bool round_error() noexcept { return 0; }
527
-
528
- static constexpr int min_exponent = 0;
529
- static constexpr int min_exponent10 = 0;
530
- static constexpr int max_exponent = 0;
531
- static constexpr int max_exponent10 = 0;
532
-
533
- static constexpr bool has_infinity = false;
534
- static constexpr bool has_quiet_NaN = false;
535
- static constexpr bool has_signaling_NaN = false;
536
- static constexpr float_denorm_style has_denorm = denorm_absent;
537
- static constexpr bool has_denorm_loss = false;
538
- static constexpr bool infinity() noexcept { return 0; }
539
- static constexpr bool quiet_NaN() noexcept { return 0; }
540
- static constexpr bool signaling_NaN() noexcept { return 0; }
541
- static constexpr bool denorm_min() noexcept { return 0; }
542
-
543
- static constexpr bool is_iec559 = false;
544
- static constexpr bool is_bounded = true;
545
- static constexpr bool is_modulo = false;
546
-
547
- static constexpr bool traps = false;
548
- static constexpr bool tinyness_before = false;
549
- static constexpr float_round_style round_style = round_toward_zero;
550
- };
551
- }
552
- ```
553
-