finalized
This commit is contained in:
@@ -15,13 +15,14 @@
|
||||
\subsection{考察}
|
||||
|
||||
上記のコードリストは浮動少数点数の演算・変数格納時の誤差を考慮していない。
|
||||
考慮する場合は\texttt{float.h}内の\texttt{DBL\_MIN}や\texttt{DBL\_EPSILON}を用いた判別処理が必要である\cite{cppref_float}。
|
||||
考慮する場合は\texttt{float.h}内の\texttt{DBL\_MIN}、\texttt{DBL\_EPSILON}等やそれに準ずる方法を用いた判別処理が必要である\cite{cppref_float}。
|
||||
|
||||
\begin{lstlisting}[language=C,title={誤差を考慮した比較}]
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
if (D == DBL_EPSILON * fmax(1, fmax(fabs(D), 0.0))) {
|
||||
#define DBL_EPSILON 1.0E-16
|
||||
|
||||
if (fabs(D) <= DBL_EPSILON) {
|
||||
puts("superposition");
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
Reference in New Issue
Block a user