Skip to content

Commit 3e26f94

Browse files
Final content dev changes
1 parent b143c25 commit 3e26f94

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

content/learning-paths/cross-platform/floating-point-rounding-errors/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ shared_between:
3939

4040
further_reading:
4141
- resource:
42-
title: G++ Optimisation Flags
42+
title: G++ Optimization Flags
4343
link: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
4444
type: documentation
4545
- resource:

content/learning-paths/cross-platform/floating-point-rounding-errors/how-to-1.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ layout: learningpathall
88

99
## Review of floating-point numbers
1010

11-
If you are new to floating-point numbers, for some background information, see the Learning Path [Learn about integer and floating-point conversions](/learning-paths/cross-platform/integer-vs-floats/introduction-integer-float-types/). It covers data types and conversions.
11+
{{% notice Learning tip%}}
12+
If you are new to floating-point numbers, and would like some further information, see
13+
the Learning Path [Learn about integer and floating-point conversions](/learning-paths/cross-platform/integer-vs-floats/introduction-integer-float-types/). It covers data types and conversions.
14+
{{% /notice %}}
1215

13-
Floating-point numbers represent real numbers using limited precision, enabling efficient storage and computation of decimal values with varying degrees of precision. In C/C++, floating-point variables are created with keywords such as `float` or `double`. The IEEE 754 standard, established in 1985, defines the most widely used format for floating-point arithmetic, ensuring consistency across hardware and software.
16+
Floating-point numbers represent real numbers using limited precision, enabling efficient storage and computation of decimal values. In C/C++, floating-point variables are created with keywords such as `float` or `double`. The IEEE 754 standard, established in 1985, defines the most widely used format for floating-point arithmetic, ensuring consistency across hardware and software.
1417

1518
IEEE 754 specifies two primary formats: single-precision (32-bit) and double-precision (64-bit).
1619

1720
Each floating-point number consists of three components:
1821

1922
- **Sign bit**: Determines the sign (positive or negative).
2023
- **Exponent**: Sets the scale or magnitude.
21-
- **Significand** (or mantissa): Holds the significant digits in binary.
24+
- **Significand**: Holds the significant digits in binary.
2225

2326
The standard uses a biased exponent to handle both large and small numbers efficiently, and it incorporates special values such as NaN (Not a Number), infinity, and subnormal numbers. It supports rounding modes and exception handling, which help ensure predictable results. However, floating-point arithmetic is inherently imprecise, leading to small rounding errors.
2427

25-
The graphic below shows various forms of floating-point representation supported by Arm, each with varying number of bits assigned to the exponent and mantissa.
28+
The graphic below shows various forms of floating-point representation supported by Arm, each with varying number of bits assigned to the exponent and significand.
2629

2730
![floating-point](./floating-point-numbers.png)
2831

@@ -32,7 +35,7 @@ Because computers use a finite number of bits to store a continuous range of num
3235

3336
Operations round results to the nearest representable value, introducing small discrepancies. This rounding error, often measured in ULPs, reflects how far the computed value may deviate from the exact mathematical result.
3437

35-
For example, with 3 bits for the significand (mantissa) and an exponent range of -1 to 2, only a limited set of values can be represented.The diagram below illustrates these values.
38+
For example, with 3 bits for the significand and an exponent range of -1 to 2, only a limited set of values can be represented. The diagram below illustrates these values.
3639

3740
![ulp](./ulp.png)
3841

@@ -43,7 +46,7 @@ Key takeaways:
4346
- Smaller numbers have tighter spacing (smaller ULPs), reducing quantization error.
4447
- ULP behavior impacts numerical stability and precision.
4548

46-
{{% notice Learning Tip %}}
49+
{{% notice Learning tip %}}
4750
Keep in mind that rounding and representation issues aren't bugs — they’re a consequence of how floating-point math works at the hardware level. Understanding these fundamentals is essential when porting numerical code across architectures like x86 and Arm.
4851
{{% /notice %}}
4952

content/learning-paths/cross-platform/floating-point-rounding-errors/how-to-2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ For easy comparison, the image below shows the x86 output (left) and Arm output
7979

8080
![differences](./differences.png)
8181

82-
As you can see, there are several cases where different behavior is observed. For example when trying to convert a signed number to a unsigned number or dealing with out-of-bounds numbers.
82+
As you can see, there are several cases where different behavior is observed. For example when trying to convert a signed number to an unsigned number or dealing with out-of-bounds numbers.
8383

8484
## Removing hardcoded values with macros
8585

@@ -93,7 +93,7 @@ For example, the function below checks if the casted result is `0`. This can be
9393
void checkFloatToUint32(float num) {
9494
uint32_t castedNum = static_cast<uint32_t>(num);
9595
if (castedNum == 0) {
96-
std::cout << "The casted number is 0, indicating the float could out of bounds for uint32_t." << std::endl;
96+
std::cout << "The casted number is 0, indicating that the float is out of bounds for uint32_t." << std::endl;
9797
} else {
9898
std::cout << "The casted number is: " << castedNum << std::endl;
9999
}

content/learning-paths/cross-platform/floating-point-rounding-errors/how-to-3.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ layout: learningpathall
1010

1111
One cause of different outputs between x86 and Arm stems from the order of instructions and how errors are propagated. As a hypothetical example, an Arm system may decide to reorder the instructions that each have a different rounding error so that subtle changes are observed.
1212

13-
It is possible that 2 functions that are mathematically equivalent will propagate errors differently on a computer.
13+
It is possible that two functions that are mathematically equivalent will propagate errors differently on a computer.
1414

1515
Functions `f1` and `f2` are mathematically equivalent. You would expect them to return the same value given the same input.
1616

17-
If the input is a very small number, `1e-8`, the error is different due to the loss in precision caused by different operations. Specifically, `f2` avoids the subtraction of nearly equal number. For a full description look into the topic of [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability).
17+
If the input is a very small number, `1e-8`, the error is different due to the loss in precision caused by different operations. Specifically, `f2` avoids subtracting nearly equal numbers for clarity. For a full description look into the topic of [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability).
1818

19-
Use an editor to copy and paste the C++ code below into a file named `error-propagation.cpp`.
19+
Use an editor to copy and paste the C++ code below into a file named `error-propagation.cpp`:
2020

2121
```cpp
2222
#include <stdio.h>
@@ -53,13 +53,13 @@ int main() {
5353
}
5454
```
5555
56-
Compile the code on both x86 and Arm with the following command.
56+
Compile the code on both x86 and Arm with the following command:
5757
5858
```bash
5959
g++ -g error-propagation.cpp -o error-propagation
6060
```
6161

62-
Running the 2 binaries shows that the second function, `f2`, has a small rounding error on both architectures. Additionally, there is a further rounding difference when run on x86 compared to Arm.
62+
Running the two binaries shows that the second function, `f2`, has a small rounding error on both architectures. Additionally, there is a further rounding difference when run on x86 compared to Arm.
6363

6464
Running on x86:
6565

content/learning-paths/cross-platform/floating-point-rounding-errors/how-to-4.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ layout: learningpathall
88

99
## How can I minimize floating-point variability across x86 and Arm?
1010

11-
The line `#pragma STDC FENV_ACCESS ON` is a directive that informs the compiler to enable access to the floating-point environment.
11+
The line `#pragma STDC FENV_ACCESS ON` is a directive that informs the compiler to enable access to the floating-point environment. This is part of the C++11 standard and ensures that the program can properly handle floating-point exceptions and rounding modes, enabling your program to continue running if an exception is thrown.
1212

13-
This is part of the C++11 standard and is used to ensure that the program can properly handle floating-point exceptions and rounding modes enabling your program to continue running if an exception is thrown.
14-
15-
In the context below, enabling floating-point environment access is crucial because the functions you are working with involve floating-point arithmetic, which can be prone to precision errors and exceptions such as overflow, underflow, division by zero, and invalid operations. This is not necessary for this example, but is included because it may be relevant for your own application.
13+
In the context below, enabling floating-point environment access is crucial because the functions in this example involve floating-point arithmetic, which can be prone to precision errors and exceptions such as overflow, underflow, division by zero, and invalid operations. Although not strictly necessary for this example, the directive is included because it may be relevant for your own applications.
1614

1715
This directive is particularly important when performing operations that require high numerical stability and precision, such as the square root calculations in functions below. It allows the program to manage the floating-point state and handle any anomalies that might occur during these calculations, thereby improving the robustness and reliability of your numerical computations.
1816

19-
Use an editor to copy and paste the C++ file below into a file named `error-propagation-min.cpp`.
17+
Use an editor to copy and paste the C++ file below into a file named `error-propagation-min.cpp`:
2018

2119
```cpp
2220
#include <cstdio>
@@ -63,13 +61,13 @@ int main() {
6361
6462
Compile on both computers, using the C++ flag, `-frounding-math`.
6563
66-
You should use this flat when your program dynamically changes the floating-point rounding mode or needs to run correctly under different rounding modes. In this example, it results in a predictable rounding mode on function `f1` across x86 and Arm.
64+
You should use this flag when your program dynamically changes the floating-point rounding mode or needs to run correctly under different rounding modes. In this example, it ensures that `f1` uses a predictable rounding mode across both x86 and Arm.
6765
6866
```bash
6967
g++ -o error-propagation-min error-propagation-min.cpp -frounding-math
7068
```
7169

72-
Running the new binary on both systems leads to function, `f1` having a similar value to `f2`. Further the difference is now identical across both Arm64 and x86.
70+
Running the new binary on both systems shows that function `f1` produces a value nearly identical to `f2`, and the difference between them is now identical across both Arm64 and x86.
7371

7472
Here is the output on both systems:
7573

@@ -81,9 +79,9 @@ Difference (f1 - f2) = -1.7887354748e-17
8179
Final result after magnification: 0.0000999982
8280
```
8381

84-
G++ provides several compiler flags to help balance accuracy and performance such as`-ffp-contract` which is useful when lossy, fused operations are used, such as fused-multiple.
82+
G++ provides several compiler flags to help balance accuracy and performance. For example, `-ffp-contract` is useful when lossy, fused operations are used, such as fused-multiple.
8583

8684
Another example is `-ffloat-store` which prevents floating-point variables from being stored in registers which can have different levels of precision and rounding.
8785

88-
You can refer to compiler documentation for more information about the available flags.
86+
You can refer to compiler documentation for more information on the flags available.
8987

0 commit comments

Comments
 (0)