rspec/rules/S862/cfamily/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

66 lines
3.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
The safe use of floating-point arithmetic requires a high level of numerical analysis skills and in-depth knowledge of the compiler and target hardware.
If floating-point is to be used, then the following issues need to be covered as part of the deviation process:
* A justification explaining why floating-point is the appropriate or only solution.
* Demonstrate that appropriate skills are available.
* Demonstrate that an appropriate process is being applied.
* Document the floating-point implementation.
The paper “What Every Computer Scientist Should Know about Floating-Point Arithmetic” explains the issues that need to be considered when using floating-point.
For example, when solving a quadratic equation, the value of b^2^-4.a.c is calculated. Assume that a=1.22, b=3.34, c=2.28 and that three significant digits are used during calculation. The exact value of b^2^4.a.c is 0.0292. However, b^2^ rounds to 11.2 and 4.a.c rounds to 11.1, giving a final answer of 0.1. This example demonstrates _catastrophic cancellation_. The subtraction does not cause an error, but it does expose errors introduced in the multiplications that are used when generating its operands.
== Resources
* MISRA {cpp}:2008, 0-4-2
* Goldberg D., What Every Computer Scientist Should Know about Floating-Point Arithmetic, Computing Surveys, March 1991.
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== is related to: S861
=== on 20 Oct 2014, 13:51:05 Samuel Mercier wrote:
This one cannot be implemented as a regular issue.
We could raise an issue on the project's level as soon as we detect some arithmetic using floating point exceptions, but probably not much more.
=== on 20 Oct 2014, 14:31:16 Ann Campbell wrote:
\[~fabrice.bellingard] this would make a good "Finding"
cc [~freddy.mallet]
=== on 20 Oct 2014, 14:35:55 Ann Campbell wrote:
\[~samuel.mercier] you've included an endnote reference (the "[13]") but not it's value.
=== on 6 Sep 2019, 10:57:02 Loïc Joly wrote:
Not implementable, closing this issue.
=== on 6 Sep 2019, 13:39:52 Ann Campbell wrote:
\[~loic.joly] how is this not implementable? We raise an issue on "you're adding two floats here" and it's... _tracked!_ Users can then use comments to log their justifications.
=== on 9 Sep 2019, 12:01:24 Loïc Joly wrote:
This is a MISRA rule, and the point of the MISRA rule is not to track all operations that use floating point operation. It means that, as soon as there is one floating point operation, and only once, there should be a document, probably external to the source code, that specifies :
____
this rule requires that documentation be produced to demonstrate that all the issues have been covered by the implementation.
____
This is not the kind of document than can be handled by comments in the justifications.
If instead of following MISRA, you would like to define a SonarSource rule to track all usage of floating point, then of course it would be possible, I just don't see what could be the value of such a rule...
endif::env-github,rspecator-view[]