Skip to content

Commit a1d2d7e

Browse files
authored
Merge pull request MicrosoftDocs#3450 from stwish-msft/patch-2
Add old pow behavior description
2 parents 5d0e49b + 2bd16e5 commit a1d2d7e

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

docs/c-runtime-library/reference/pow-powf-powl.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ If you use the \<tgmath.h> `pow()` macro, the type of the argument determines wh
5959
6060
The `pow(int, int)` overload is no longer available. If you use this overload, the compiler may emit [C2668](../../error-messages/compiler-errors-2/compiler-error-c2668.md). To avoid this problem, cast the first parameter to **`double`**, **`float`**, or **`long double`**.
6161
62+
Originally, the `pow(T, int)` overloads would unroll the `pow` call into a sequence of inline multiplication operations. While this was faster, it was also significantly less accurate and was removed in Visual Studio 2015 Update 1. For more information, see [Conformance Improvements in Visual Studio 2015 Update 1](../../porting/visual-cpp-what-s-new-2003-through-2015.md).
63+
6264
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
6365
6466
## Requirements
@@ -94,7 +96,7 @@ int main( void )
9496
## See also
9597

9698
[Floating-Point Support](../../c-runtime-library/floating-point-support.md) <br/>
97-
[exp, expf, expl](exp-expf.md) <br/>
98-
[log, logf, log10, log10f](log-logf-log10-log10f.md) <br/>
99-
[sqrt, sqrtf, sqrtl](sqrt-sqrtf-sqrtl.md) <br/>
100-
[_CIpow](../../c-runtime-library/cipow.md)<br/>
99+
[`exp`, `expf`, `expl`](exp-expf.md) <br/>
100+
[`log`, `logf`, `log10`, `log10f`](log-logf-log10-log10f.md) <br/>
101+
[`sqrt`, `sqrtf`, `sqrtl`](sqrt-sqrtf-sqrtl.md) <br/>
102+
[`_CIpow`](../../c-runtime-library/cipow.md)<br/>

docs/porting/visual-cpp-what-s-new-2003-through-2015.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Although these differences can affect your source code or other build artifacts,
122122
}
123123
```
124124

125-
The current compiler correctly gives an error, because the template parameter type doesn't match the template argument (the parameter is a pointer to a const member, but the function f is non-const):
125+
The current compiler correctly gives an error, because the template parameter type does not match the template argument (the parameter is a pointer to a const member, but the function f is non-const):
126126

127127
```Output
128128
error C2893: Failed to specialize function template 'void S2::f(void)'note: With the following template arguments:note: 'C=S1'note: 'Function=S1::f'
@@ -581,7 +581,7 @@ Although these differences can affect your source code or other build artifacts,
581581
void * __cdecl operator new(size_t cb, const std::nothrow_t&) // removed 'static inline'
582582
```
583583

584-
Additionally, although the compiler doesn't give a specific diagnostic, inline operator new is considered ill-formed.
584+
Additionally, although the compiler does not give a specific diagnostic, inline operator new is considered ill-formed.
585585

586586
- **Calling 'operator *type*()' (user-defined conversion) on non-class types** Previous versions of the compiler allowed 'operator *type*()' to be called on non-class types while silently ignoring it. This old behavior created a risk of silent bad code generation, resulting in unpredictable runtime behavior. The compiler no longer accepts code written in this way and issues compiler error C2228 instead.
587587

@@ -1008,11 +1008,37 @@ Although these differences can affect your source code or other build artifacts,
10081008
}
10091009
```
10101010

1011+
- ** Removal of `pow(T, int)` unrolling optimization **
1012+
1013+
Previous versions of the C++ standard library defined a `pow(T, int)` function template that would unroll a `pow` function call into a series of multiplication operations. This technique would accrue a large amount of inaccuracy due to the nature of floating point operations, causing end results that could be significantly inaccurate. In Visual Studio 2015 Update 1, this behavior was removed to avoid unintentional loss of accuracy when using the `pow` function. However, this version of `pow` was much faster than the correct calculation. If this change causes a significant performance regression and your project does not require precise floating point results (for example, your project already compiles with /fp:fast), consider replacing calls to `pow` with this workaround function:
1014+
1015+
```cpp
1016+
template <class T>
1017+
inline T pow_int(T x, int y) throw() {
1018+
unsigned int n;
1019+
if (y >= 0) {
1020+
n = (unsigned int)(y);
1021+
} else {
1022+
n = (unsigned int)(-y);
1023+
}
1024+
for (T z = T(1); ; x *= x) {
1025+
if ((n & 1) != 0) {
1026+
z *= x;
1027+
}
1028+
if ((n >>= 1) == 0) {
1029+
return (y < 0 ? T(1) / z : z);
1030+
}
1031+
}
1032+
}
1033+
```
1034+
1035+
This implementation is identical to what was included in previous versions of Visual Studio.
1036+
10111037
### <a name="VS_Update2"></a> Conformance Improvements in Visual Studio 2015 Update 2
10121038
10131039
- **Additional warnings and errors might be issued as a result of partial support for expression SFINAE**
10141040
1015-
Previous versions of the compiler did not parse certain kinds of expressions inside **`decltype`** specifiers due to lack of support for expression SFINAE. This old behavior was incorrect and does not conform to the C++ standard. The compiler now parses these expressions and has partial support for expression SFINAE due to ongoing conformance improvements. As a result, the compiler now issues warnings and errors found in expressions that previous versions of the compiler did not parse.
1041+
Previous versions of the compiler did not parse certain kinds of expressions inside **`decltype`** specifiers due to lack of support for expression SFINAE. This old behavior was incorrect and does not conform to the C++ standard. The compiler now parses these expressions and has partial support for expression SFINAE due to ongoing conformance improvements. As a result, the compiler now issues warnings and errors found in expressions that previous versions of the compiler did not parse.
10161042
10171043
When this new behavior parses a **`decltype`** expression that includes a type that has not yet been declared, the compiler issues compiler error C2039 as a result.
10181044
@@ -1185,7 +1211,7 @@ Although these differences can affect your source code or other build artifacts,
11851211

11861212
- **Forward declaration of enum is not allowed in WinRT code** (affects `/ZW` only)
11871213

1188-
Code compiled for the Windows Runtime (WinRT) doesn't allow **`enum`** types to be forward declared, similarly to when managed C++ code is compiled for the .Net Framework using the `/clr` compiler switch. This behavior is ensures that the size of an enumeration is always known and can be correctly projected to the WinRT type system. The compiler rejects code written in this way and issues compiler error C2599 together with compiler error C3197.
1214+
Code compiled for the Windows Runtime (WinRT) does not allow **`enum`** types to be forward declared, similarly to when managed C++ code is compiled for the .Net Framework using the `/clr` compiler switch. This behavior is ensures that the size of an enumeration is always known and can be correctly projected to the WinRT type system. The compiler rejects code written in this way and issues compiler error C2599 together with compiler error C3197.
11891215

11901216
```Output
11911217
error C2599: 'CustomEnum': the forward declaration of a WinRT enum is not allowed

0 commit comments

Comments
 (0)