Files
information-processing-1_11…/section/a3.tex
2025-06-26 22:31:42 +09:00

29 lines
808 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 <math.h>
#define DBL_EPSILON 1.0E-16
if (fabs(D) <= DBL_EPSILON) {
puts("superposition");
}
\end{lstlisting}