Skip to content

Commit bdd18e2

Browse files
author
Colin Robertson
committed
MEr'gerize 'em
2 parents f73f628 + 8c524fd commit bdd18e2

File tree

905 files changed

+9865
-10429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

905 files changed

+9865
-10429
lines changed

docs/build/reference/ieee-floating-point-representation.md

Lines changed: 120 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -12,97 +12,123 @@ ms.author: "corob"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# IEEE Floating-Point Representation
15-
Microsoft Visual C++ is consistent with the IEEE numeric standards. There are three internal varieties of real numbers. Real\*4 and real\*8 are used in Visual C++. Real\*4 is declared using the word **float**. Real\*8 is declared using the word **double**. In Windows 32-bit programming, the `long double` data type maps to **double**. There is, however, assembly language support for computations using the real*10 data type.
16-
17-
The values are stored as follows:
18-
19-
|Value|Stored as|
20-
|-----------|---------------|
21-
|real*4|sign bit, 8-bit exponent, 23-bit mantissa|
22-
|real*8|sign bit, 11-bit exponent, 52-bit mantissa|
23-
|real*10|sign bit, 15-bit exponent, 64-bit mantissa|
24-
25-
In real*4 and real\*8 formats, there is an assumed leading 1 in the mantissa that is not stored in memory, so the mantissas are actually 24 or 53 bits, even though only 23 or 52 bits are stored. The real\*10 format actually stores this bit.
26-
27-
The exponents are biased by half of their possible value. This means you subtract this bias from the stored exponent to get the actual exponent. If the stored exponent is less than the bias, it is actually a negative exponent.
28-
29-
The exponents are biased as follows:
30-
31-
|Exponent|Biased by|
32-
|--------------|---------------|
33-
|8-bit (real*4)|127|
34-
|11-bit (real*8)|1023|
35-
|15-bit (real*10)|16383|
36-
37-
These exponents are not powers of ten; they are powers of two. That is, 8-bit stored exponents can be up to 127. The value 2**127 is roughly equivalent to 10\*\*38, which is the actual limit of real\*4.
38-
39-
The mantissa is stored as a binary fraction of the form 1.XXX... . This fraction has a value greater than or equal to 1 and less than 2. Note that real numbers are always stored in normalized form; that is, the mantissa is left-shifted such that the high-order bit of the mantissa is always 1. Because this bit is always 1, it is assumed (not stored) in the real*4 and real\*8 formats. The binary (not decimal) point is assumed to be just to the right of the leading 1.
40-
41-
The format, then, for the various sizes is as follows:
42-
43-
|Format|BYTE 1|BYTE 2|BYTE 3|BYTE 4|...|BYTE n|
44-
|------------|------------|------------|------------|------------|---------|------------|
45-
|real*4|`SXXX XXXX`|`XMMM MMMM`|`MMMM MMMM`|`MMMM MMMM`|||
46-
|real*8|`SXXX XXXX`|`XXXX MMMM`|`MMMM MMMM`|`MMMM MMMM`|...|`MMMM MMMM`|
47-
|real*10|`SXXX XXXX`|`XXXX XXXX`|`1MMM MMMM`|`MMMM MMMM`|...|`MMMM MMMM`|
48-
49-
`S` represents the sign bit, the `X`'s are the exponent bits, and the `M`'s are the mantissa bits. Note that the leftmost bit is assumed in real*4 and real\*8 formats, but is present as "1" in BYTE 3 of the real\*10 format.
50-
51-
To shift the binary point properly, you first unbias the exponent and then move the binary point to the right or left the appropriate number of bits.
52-
53-
## Examples
54-
The following are some examples in real*4 format:
55-
56-
- In the following example, the sign bit is zero, and the stored exponent is 128, or 100 0000 0 in binary, which is 127 plus 1. The stored mantissa is (1.) 000 0000 ... 0000 0000, which has an implied leading 1 and binary point, so the actual mantissa is one.
57-
58-
```
59-
SXXX XXXX XMMM MMMM ... MMMM MMMM
60-
2 = 1 * 2**1 = 0100 0000 0000 0000 ... 0000 0000 = 4000 0000
61-
```
62-
63-
- Same as +2 except that the sign bit is set. This is true for all IEEE format floating-point numbers.
64-
65-
```
66-
-2 = -1 * 2**1 = 1100 0000 0000 0000 ... 0000 0000 = C000 0000
67-
```
68-
69-
- Same mantissa, exponent increases by one (biased value is 129, or 100 0000 1 in binary.
70-
71-
```
72-
4 = 1 * 2**2 = 0100 0000 1000 0000 ... 0000 0000 = 4080 0000
73-
```
74-
75-
- Same exponent, mantissa is larger by half — it's (1.) 100 0000 ...0000 0000, which, since this is a binary fraction, is 1 1/2 (the values of the fractional digits are 1/2, 1/4, 1/8, and so forth).
76-
77-
```
78-
6 = 1.5 * 2**2 = 0100 0000 1100 0000 ... 0000 0000 = 40C0 0000
79-
```
80-
81-
- Same exponent as other powers of two, mantissa is one less than two at 127, or 011 1111 1 in binary.
82-
83-
```
84-
1 = 1 * 2**0 = 0011 1111 1000 0000 ... 0000 0000 = 3F80 0000
85-
```
86-
87-
- The biased exponent is 126, 011 1111 0 in binary, and the mantissa is (1.) 100 0000 ... 0000 0000, which is 1 1/2.
88-
89-
```
90-
.75 = 1.5 * 2**-1 = 0011 1111 0100 0000 ... 0000 0000 = 3F40 0000
91-
```
92-
93-
- Exactly the same as two except that the bit that represents 1/4 is set in the mantissa.
94-
95-
```
96-
2.5 = 1.25 * 2**1 = 0100 0000 0010 0000 ... 0000 0000 = 4020 0000
97-
```
98-
99-
- 1/10 is a repeating fraction in binary. The mantissa is just shy of 1.6, and the biased exponent says that 1.6 is to be divided by 16 (it is 011 1101 1 in binary, which is 123 in decimal). The true exponent is 123 - 127 = -4, which means that the factor by which to multiply is 2**-4 = 1/16. Note that the stored mantissa is rounded up in the last bit — an attempt to represent the unrepresentable number as accurately as possible. (The reason that 1/10 and 1/100 are not exactly representable in binary is similar to the reason that 1/3 is not exactly representable in decimal.)
100-
101-
```
102-
0.1 = 1.6 * 2**-4 = 0011 1101 1100 1100 ... 1100 1101 = 3DCC CCCD
103-
```
104-
105-
- `0 = 1.0 * 2**-128 = all zeros--a special case.`
106-
107-
## See Also
108-
[Why Floating-Point Numbers May Lose Precision](../../build/reference/why-floating-point-numbers-may-lose-precision.md)
15+
16+
Microsoft Visual C++ is consistent with the IEEE numeric standards. The IEEE-754 standard describes floating-point formats, a way to represent real numbers in hardware. There are at least five internal formats for floating-point numbers that are representable in hardware targeted by the MSVC compiler, but the compiler only uses two of them. The *single-precision* (4-byte) and *double-precision* (8-byte) formats are used in Visual C++. Single-precision is declared using the keyword **float**. Double-precision is declared using the keyword **double**. The IEEE standard also specifies *half-precision* (2-byte) and *quadruple-precision* (16-byte) formats, as well as an *double-extended-precision* (10-byte) format, which some C and C++ compilers implement as the **long double** data type. In the Visual C++ compiler, the **long double** data type is treated as a distinct type, but the storage type maps to **double**. There is, however, intrinsic and assembly language support for computations using the other formats, including the double-extended-precision (10-byte) format, where supported by hardware.
17+
18+
The values are stored as follows:
19+
20+
|Value|Stored as|
21+
|-----------|---------------|
22+
|single-precision|sign bit, 8-bit exponent, 23-bit significand|
23+
|double-precision|sign bit, 11-bit exponent, 52-bit significand|
24+
|double-extended-precision|sign bit, 15-bit exponent, 64-bit significand|
25+
26+
In single-precision and double-precision formats, there is an assumed leading 1 in the fractional part, called the *significand* (and sometimes referred to as the *mantissa*), that is not stored in memory, so the significands are actually 24 or 53 bits, even though only 23 or 52 bits are stored. The double-extended-precision format actually stores this bit.
27+
28+
The exponents are biased by half of their possible value. This means you subtract this bias from the stored exponent to get the actual exponent. If the stored exponent is less than the bias, it is actually a negative exponent.
29+
30+
The exponents are biased as follows:
31+
32+
|Exponent|Biased by|
33+
|--------------|---------------|
34+
|8-bit (single-precision)|127|
35+
|11-bit (double-precision)|1023|
36+
|15-bit (double-extended-precision)|16383|
37+
38+
These exponents are not powers of ten; they are powers of two. That is, 8-bit stored exponents can range from -127 to 127, stored as 0 to 254. The value 2<sup>127</sup> is roughly equivalent to 10<sup>38</sup>, which is the actual limit of single-precision.
39+
40+
The significand is stored as a binary fraction of the form 1.XXX... . This fraction has a value greater than or equal to 1 and less than 2. Note that real numbers are always stored in *normalized form*; that is, the significand is left-shifted such that the high-order bit of the significand is always 1. Because this bit is always 1, it is assumed (not stored) in the single-precision and double-precision formats. The binary (not decimal) point is assumed to be just to the right of the leading 1.
41+
42+
The format, then, for the various sizes is as follows:
43+
44+
|Format|byte 1|byte 2|byte 3|byte 4|...|byte n|
45+
|------------|------------|------------|------------|------------|---------|------------|
46+
|single-precision| `SXXXXXXX`|`XMMMMMMM`|`MMMMMMMM`|`MMMMMMMM`|||
47+
|double-precision|`SXXXXXXX`|`XXXXMMMM`|`MMMMMMMM`|`MMMMMMMM`|...|`MMMMMMMM`|
48+
|double-extended-precision|`SXXXXXXX`|`XXXXXXXX`|`1MMMMMMM`|`MMMMMMMM`|...|`MMMMMMMM`|
49+
50+
`S` represents the sign bit, the `X`'s are the biased exponent bits, and the `M`'s are the significand bits. Note that the leftmost bit is assumed in single-precision and double-precision formats, but is present as "1" in byte 3 of the double-extended-precision format.
51+
52+
To shift the binary point properly, you first unbias the exponent and then move the binary point to the right or left the appropriate number of bits.
53+
54+
## Special values
55+
56+
The floating-point formats include some values that are treated specially.
57+
58+
### Zero
59+
60+
Zero cannot be normalized, which makes it unrepresentable in the normalized form of a single-precision or double-precision value. A special bit pattern of all zeroes represents 0. It's also possible to represent -0 as zero with the sign bit set, but -0 and 0 always compare as equal.
61+
62+
### Infinities
63+
64+
The +∞ and −∞ values are represented by an exponent of all ones and a significand of all zeroes. Both positive and negative infinities can be represented by using the sign bit.
65+
66+
### Subnormals
67+
68+
It's possible to represent numbers of smaller magnitude than the smallest normalized number. These numbers are known as *subnormal* or *denormal* numbers. If the exponent is all zeroes and the significand is non-zero, then implicit leading bit of the significand is considered to be zero, not one. The precision of subnormal numbers goes down as the number of leading zeroes in the significand goes up.
69+
70+
### NaN - Not a Number
71+
72+
It's possible to represent values that are not a real number, such as 0 / 0, in the IEEE floating-point format. A value of this kind is called a *NaN*. A NaN is represented by an exponent of all ones and a non-zero significand. There are two kinds of NaNs, *quiet* NaNs, or QNaNs, and *signalling* NaNs, or SNaNs. Quiet NaNs have a leading one in the significand, and are generally propagated through an expression. They represent an indeterminate value, such as the result of dividing by infinity, or multiplying an infinity by zero. Signalling NaNs have a leading zero in the significand. These are used for operations that are not valid, to signal a floating-point hardware exception.
73+
74+
## Examples
75+
76+
The following are some examples in single-precision format:
77+
78+
- For the value 2, the sign bit is zero, and the stored exponent is 128, or 1000 0000 in binary, which is 127 plus 1. The stored binary significand is (1.) 000 0000 0000 0000 0000 0000, which has an implied leading 1 and binary point, so the actual significand is one.
79+
80+
|Value|Formula|Binary representation|Hexadecimal|
81+
|-|-|-|-|
82+
|2|1 * 2<sup>1</sup>|0100 0000 0000 0000 0000 0000 0000 0000|0x40000000|
83+
84+
- The value -2. Same as +2 except that the sign bit is set. This is true for the negative of all IEEE format floating-point numbers.
85+
86+
|Value|Formula|Binary representation|Hexadecimal|
87+
|-|-|-|-|
88+
|-2|-1 * 2<sup>1</sup>|1100 0000 0000 0000 0000 0000 0000 0000|0xC0000000|
89+
90+
- The value 4. Same significand, exponent increases by one (biased value is 129, or 100 0000 1 in binary.
91+
92+
|Value|Formula|Binary representation|Hexadecimal|
93+
|-|-|-|-|
94+
|4|1 * 2<sup>2</sup>|0100 0000 1000 0000 0000 0000 0000 0000|0x40800000|
95+
96+
- The value 6. Same exponent, significand is larger by half — it's (1.) 100 0000 ... 0000 0000, which, since this is a binary fraction, is 1 1/2 because the values of the fractional digits are 1/2, 1/4, 1/8, and so forth.
97+
98+
|Value|Formula|Binary representation|Hexadecimal|
99+
|-|-|-|-|
100+
|6|1.5 * 2<sup>2</sup>|0100 0000 1100 0000 0000 0000 0000 0000|0x40C00000|
101+
102+
- The value 1. Same significand as other powers of two, the biased exponent is one less than two at 127, or 011 1111 1 in binary.
103+
104+
|Value|Formula|Binary representation|Hexadecimal|
105+
|-|-|-|-|
106+
|1|1 * 2<sup>0</sup>|0011 1111 1000 0000 0000 0000 0000 0000|0x3F800000|
107+
108+
- The value 0.75. The biased exponent is 126, 011 1111 0 in binary, and the significand is (1.) 100 0000 ... 0000 0000, which is 1 1/2.
109+
110+
|Value|Formula|Binary representation|Hexadecimal|
111+
|-|-|-|-|
112+
|0.75|1.5 * 2<sup>-1</sup>|0011 1111 0100 0000 0000 0000 0000 0000|0x3F400000|
113+
114+
- The value 2.5. Exactly the same as two except that the bit that represents 1/4 is set in the significand.
115+
116+
|Value|Formula|Binary representation|Hexadecimal|
117+
|-|-|-|-|
118+
|2.5|1.25 * 2<sup>1</sup>|0100 0000 0010 0000 0000 0000 0000 0000|0x40200000|
119+
120+
- 1/10 is a repeating fraction in binary. The significand is just shy of 1.6, and the biased exponent says that 1.6 is to be divided by 16 (it is 011 1101 1 in binary, which is 123 in decimal). The true exponent is 123 - 127 = -4, which means that the factor by which to multiply is 2<sup>-4</sup> = 1/16. Note that the stored significand is rounded up in the last bit — an attempt to represent the unrepresentable number as accurately as possible. (The reason that 1/10 and 1/100 are not exactly representable in binary is similar to the reason that 1/3 is not exactly representable in decimal.)
121+
122+
|Value|Formula|Binary representation|Hexadecimal|
123+
|-|-|-|-|
124+
|0.1|1.6 * 2<sup>-4</sup>|0011 1101 1100 1100 1100 1100 1100 1101|0x3DCCCCCD|
125+
126+
- Zero is a special case that uses the formula for the minimum possible representable positive value, which is all zeroes.
127+
128+
|Value|Formula|Binary representation|Hexadecimal|
129+
|-|-|-|-|
130+
|0|1 * 2<sup>-128</sup>|0000 0000 0000 0000 0000 0000 0000 0000|0x00000000|
131+
132+
## See also
133+
134+
[Why Floating-Point Numbers May Lose Precision](../../build/reference/why-floating-point-numbers-may-lose-precision.md)

docs/c-runtime-library/country-region-strings.md

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,42 @@ ms.author: "corob"
1313
ms.workload: ["cplusplus"]
1414
---
1515
# Country/Region Strings
16-
Country and region strings can be combined with a language string to create a locale specification for the `setlocale`, `_wsetlocale`, `_create_locale`, and `_wcreate_locale` functions. For lists of country/region names that are supported by various Windows operating system versions, see [National Language Support (NLS) API Reference](https://www.microsoft.com/resources/msdn/goglobal/default.mspx). In the lists, the country/region string can be any of the country values in the **Locale - Language Country/Region** column, or any of the abbreviations in the **Country or Region name abbreviation** column. For additional language support information in Windows operating systems by version, see [Appendix A: Product Behavior](http://msdn.microsoft.com/goglobal/bb896001.aspx) in [MS-LCID]: Windows Language Code Identifier (LCID) Reference.
17-
18-
The C run-time library implementation also supports the following additional country/region strings and abbreviations:
19-
20-
|Country/region string|Abbreviation|Equivalent locale name|
21-
|----------------------------|------------------|----------------------------|
22-
|america|USA|en-US|
23-
|britain|GBR|en-GB|
24-
|china|CHN|zh-CN|
25-
|czech|CZE|cs-CZ|
26-
|england|GBR|en-GB|
27-
|great britain|GBR|en-GB|
28-
|holland|NLD|nl-NL|
29-
|hong-kong|HKG|zh-HK|
30-
|new-zealand|NZL|en-NZ|
31-
|nz|NZL|en-NZ|
32-
|pr china|CHN|zh-CN|
33-
|pr-china|CHN|zh-CN|
34-
|puerto-rico|PRI|es-PR|
35-
|slovak|SVK|sk-SK|
36-
|south africa|ZAF|af-ZA|
37-
|south korea|KOR|ko-KR|
38-
|south-africa|ZAF|af-ZA|
39-
|south-korea|KOR|ko-KR|
40-
|trinidad & tobago|TTO|en-TT|
41-
|uk|GBR|en-GB|
42-
|united-kingdom|GBR|en-GB|
43-
|united-states|USA|en-US|
44-
|us|USA|en-US|
45-
46-
## See Also
47-
[Locale Names, Languages, and Country/Region Strings](../c-runtime-library/locale-names-languages-and-country-region-strings.md)
48-
[Language Strings](../c-runtime-library/language-strings.md)
49-
[setlocale, _wsetlocale](../c-runtime-library/reference/setlocale-wsetlocale.md)
50-
[_create_locale, _wcreate_locale](../c-runtime-library/reference/create-locale-wcreate-locale.md)
16+
17+
Country and region strings can be combined with a language string to create a locale specification for the `setlocale`, `_wsetlocale`, `_create_locale`, and `_wcreate_locale` functions. For lists of country and region names that are supported by various Windows operating system versions, see the **Language**, **Location**, and **Language tag** columns of the table in [Appendix A: Product Behavior](https://msdn.microsoft.com/library/cc233982.aspx) in [MS-LCID]: Windows Language Code Identifier (LCID) Reference. For an example of code that enumerates available locale names and related values, see [NLS: Name-based APIs Sample](/windows/desktop/intl/nls--name-based-apis-sample).
18+
19+
## Additional supported country and region strings
20+
21+
The Microsoft C run-time library implementation also supports the following additional country/region strings and abbreviations:
22+
23+
|Country/region string|Abbreviation|Equivalent locale name|
24+
|----------------------------|------------------|----------------------------|
25+
|america|USA|en-US|
26+
|britain|GBR|en-GB|
27+
|china|CHN|zh-CN|
28+
|czech|CZE|cs-CZ|
29+
|england|GBR|en-GB|
30+
|great britain|GBR|en-GB|
31+
|holland|NLD|nl-NL|
32+
|hong-kong|HKG|zh-HK|
33+
|new-zealand|NZL|en-NZ|
34+
|nz|NZL|en-NZ|
35+
|pr china|CHN|zh-CN|
36+
|pr-china|CHN|zh-CN|
37+
|puerto-rico|PRI|es-PR|
38+
|slovak|SVK|sk-SK|
39+
|south africa|ZAF|af-ZA|
40+
|south korea|KOR|ko-KR|
41+
|south-africa|ZAF|af-ZA|
42+
|south-korea|KOR|ko-KR|
43+
|trinidad & tobago|TTO|en-TT|
44+
|uk|GBR|en-GB|
45+
|united-kingdom|GBR|en-GB|
46+
|united-states|USA|en-US|
47+
|us|USA|en-US|
48+
49+
## See also
50+
51+
[Locale Names, Languages, and Country/Region Strings](../c-runtime-library/locale-names-languages-and-country-region-strings.md)
52+
[Language Strings](../c-runtime-library/language-strings.md)
53+
[setlocale, _wsetlocale](../c-runtime-library/reference/setlocale-wsetlocale.md)
54+
[_create_locale, _wcreate_locale](../c-runtime-library/reference/create-locale-wcreate-locale.md)

0 commit comments

Comments
 (0)