Skip to content

Commit

Permalink
Create c-style-math-functions.qhelp
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade authored Apr 9, 2020
1 parent 50f9580 commit 9e02bc1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lgtm/cpp-queries/c-style-math-functions.qhelp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>

<overview>
<p>The C++ standard library provides a large selection of math functions.
These functions are available for use either in the std namespace or in the global namespace.</p>

<p>In order to highlight invocations of the standard library and avoid occasional
definitional differences of these functions, we prefer to avoid use of the functions in the global namespace.</p>

</overview>
<recommendation>

<p>Prefer to invoke the functions defined in the std namespace.</p>

</recommendation>
<example>

<p>Most current c++ standard libraries will allow invoking math functions in the global namespace</p>
<code>
#include <cmath>

float my_pow( float base, float exp ) {
return pow( base, exp );
}
</code>

<p>Prefer invoking the version in the std namespace.</p>
<code>
#include <cmath>

float my_pow( float base, float exp ) {
return std::pow( base, exp );
}
</code>

</example>
<references>

<li>
Informative Stack Exchange Answer:
<a href="https://stackoverflow.com/a/8734292/280690">Differences between math.h and cmath</a>.
</li>

</references>
</qhelp>

0 comments on commit 9e02bc1

Please sign in to comment.