Skip to content

Commit f68bb3c

Browse files
Address /fp sample code issue cpp-docs 3369
1 parent e89e29d commit f68bb3c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/build/reference/fp-specify-floating-point-behavior.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@ int main()
179179
b = (f2 == f2);
180180
c = (f1 - f1);
181181
d = (f2 - f2);
182+
e = (gf0 / f3);
182183
printf("INFINITY == INFINITY : %d\n", a);
183184
printf("NAN == NAN : %d\n", b);
184185
printf("INFINITY - INFINITY : %f\n", c);
185186
printf("NAN - NAN : %f\n", d);
186-
187-
e = gf0 / abs(f3);
188-
printf("std::signbit(-0.0/-INFINITY): %d\n", std::signbit(c));
187+
printf("std::signbit(-0.0/-INFINITY): %d\n", std::signbit(e));
189188
return 0;
190189
}
191190
```
@@ -196,8 +195,8 @@ When compiled by using `/O2 /fp:precise` or `/O2 /fp:strict` for x86 architectur
196195
INFINITY == INFINITY : 1
197196
NAN == NAN : 0
198197
INFINITY - INFINITY : -nan(ind)
199-
NAN - NAN : -nan(ind)
200-
std::signbit(-0.0/-INFINITY): 1
198+
NAN - NAN : nan
199+
std::signbit(-0.0/-INFINITY): 0
201200
```
202201

203202
When compiled by using `/O2 /fp:fast`** for x86 architecture, the outputs aren't consistent with IEEE-754:
@@ -212,7 +211,7 @@ std::signbit(-0.0/-INFINITY): 0
212211

213212
### Floating-point algebraic transformations
214213

215-
Under **`/fp:precise`** and **`/fp:strict`**, the compiler doesn't perform mathematical transformations unless the transformation is guaranteed to produce a bitwise identical result. The compiler may make such transformations under **`/fp:fast`**. For example, the expression `a * b + a * c` in the sample function `algebraic_transformation` may be compiled into `a * (b + c)` under **`/fp:fast`**. Such transformations aren't done under **`/fp:precise`** or **`/fp:strict`**, and the compiler generates `a * b + a * c`.
214+
Under **`/fp:precise`** and **`/fp:strict`**, the compiler doesn't do any mathematical transformation unless the transformation is guaranteed to produce a bitwise identical result. The compiler may make such transformations under **`/fp:fast`**. For example, the expression `a * b + a * c` in the sample function `algebraic_transformation` may be compiled into `a * (b + c)` under **`/fp:fast`**. Such transformations aren't done under **`/fp:precise`** or **`/fp:strict`**, and the compiler generates `a * b + a * c`.
216215

217216
```cpp
218217
float algebraic_transformation (float a, float b, float c)

0 commit comments

Comments
 (0)