
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.
42 lines
715 B
Plaintext
42 lines
715 B
Plaintext
== Why is this an issue?
|
|
|
|
Starting from {cpp}20, mathematical constants are defined in the header ``++<numbers>++``.
|
|
|
|
You should prefer using them instead of hardcoding your own constants.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
const double pi = 3.14159265358979323846; // Noncompliant
|
|
|
|
auto computeCirclePerimeter(double radius) {
|
|
return 2 * pi * radius;
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
#include <numbers>
|
|
|
|
auto computeCirclePerimeter(double radius) {
|
|
return 2 * std::numbers::pi * radius;
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== is related to: S2904
|
|
|
|
=== is related to: S109
|
|
|
|
endif::env-github,rspecator-view[]
|