progress
This commit is contained in:
27
section/a3.tex
Normal file
27
section/a3.tex
Normal file
@@ -0,0 +1,27 @@
|
||||
\section{課題3}
|
||||
|
||||
二次方程式の解の種類を判別するプログラム。
|
||||
|
||||
\subsection{コードリスティング}
|
||||
|
||||
\lstinputlisting[language=C,title={課題3}]{../programs/a3/main.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=\textwidth]{./assets/a3.png}
|
||||
\end{center}
|
||||
|
||||
\subsection{考察}
|
||||
|
||||
上記のコードリストは浮動少数点数の演算・変数格納時の誤差を考慮していない。
|
||||
考慮する場合は\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))) {
|
||||
puts("superposition");
|
||||
}
|
||||
\end{lstlisting}
|
||||
Reference in New Issue
Block a user