Skip to content

Commit

Permalink
fix: Rule A0-4-1
Browse files Browse the repository at this point in the history
  • Loading branch information
sbmueller committed Nov 9, 2023
1 parent b9d736d commit efbb018
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
39 changes: 39 additions & 0 deletions src/A0-4-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
> **Rule A0-4-1 (required, infrastructure / toolchain, non-automated)**
>
> Floating-point implementation shall comply with IEEE 754 standard.
## Rationale

Floating-point arithmetic has a range of problems associated with it. Some of these
can be overcome by using an implementation that conforms to IEEE 754 (IEEE
Standard for Floating-Point Arithmetic).
Note that the rule implies that toolchain, hardware, C++ Standard Library and C++
built-in types (i.e. float, double) will provide full compliance to IEEE 754 standard in
order to use floating-points in the project.
Also, see: A0-4-2.

## Example

```cpp
//% $Id: A0-4-1.cpp 271389 2017-03-21 14:41:05Z piotr.tanski $
#include <limits>

static_assert(std::numeric_limits<float>::is_iec559,
"Type float does not comply with IEEE 754 single precision format");

static_assert( std::numeric_limits<float>::digits == 24,
"Type float does not comply with IEEE 754 single precision format");

static_assert( std::numeric_limits<double>::is_iec559,
"type double does not comply with IEEE 754 double precision format");

static_assert( std::numeric_limits<double>::digits == 53,
"Type double does not comply with IEEE 754 double precision format");
```
## See also
MISRA C++ 2008 [7]: Rule 0-4-3 Floating-point implementations shall comply
with a defined floating-point standard.
JSF December 2005 [8]: AV Rule 146 Floating point implementations shall
comply with a defined floating point standard.
41 changes: 1 addition & 40 deletions src/M0-4-2.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
> **Rule M0-4-2 (required, implementation, non-automated)**
>
> Use of floating-point arithmetic shall be documented.
> See MISRA C++ 2008 [7]
> Rule A0-4-1 (required, infrastructure / toolchain, non-automated)Floating-point implementation shall comply with IEEE 754 standard.
## Rationale

Floating-point arithmetic has a range of problems associated with it. Some of these
can be overcome by using an implementation that conforms to IEEE 754 (IEEE
Standard for Floating-Point Arithmetic).
Note that the rule implies that toolchain, hardware, C++ Standard Library and C++
built-in types (i.e. float, double) will provide full compliance to IEEE 754 standard in
order to use floating-points in the project.
Also, see: A0-4-2.

## Example

```cpp
//% $Id: A0-4-1.cpp 271389 2017-03-21 14:41:05Z piotr.tanski $
#include <limits>
static_assert(
std::numeric_limits<float>::is_iec559,
"Type float does not comply with IEEE 754 single precision format");
static_assert(

std::numeric_limits<float>::digits == 24,
"Type float does not comply with IEEE 754 single precision format");

static_assert(
std::numeric_limits<double>::is_iec559,
"type double does not comply with IEEE 754 double precision format");
static_assert(
std::numeric_limits<double>::digits == 53,
"Type double does not comply with IEEE 754 double precision format");

```
## See also
MISRA C++ 2008 [7]: Rule 0-4-3 Floating-point implementations shall comply
with a defined floating-point standard.
JSF December 2005 [8]: AV Rule 146 Floating point implementations shall
comply with a defined floating point standard.
See MISRA C++ 2008 [7]
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [M0-2-1](./M0-2-1.md)
- [M0-3-2](./M0-3-2.md)
- [M0-4-1](./M0-4-1.md)
- [A0-4-1](./A0-4-1.md)
- [M0-4-2](./M0-4-2.md)
- [A0-4-2](./A0-4-2.md)
- [A0-4-3](./A0-4-3.md)
Expand Down

0 comments on commit efbb018

Please sign in to comment.