Files
information-processing-1_11…/section/a3.tex
2025-06-26 15:18:33 +09:00

28 lines
792 B
TeX

\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}