1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
\subsection{round}
\label{labround}
\noindent Name: \textbf{round}\\
\phantom{aaa}rounds a number to a floating-point format.\\[0.2cm]
\noindent Library name:\\
\verb| sollya_obj_t sollya_lib_round(sollya_obj_t, sollya_obj_t, sollya_obj_t)|\\[0.2cm]
\noindent Usage:
\begin{center}
\textbf{round}(\emph{x},\emph{n},\emph{mode}) : (\textsf{constant}, \textsf{integer}, \textsf{RN$|$RZ$|$RU$|$RD}) $\rightarrow$ \textsf{constant}\\
\textbf{round}(\emph{x},\emph{format},\emph{mode}) : (\textsf{constant}, \textsf{HP$|$halfprecision$|$SG$|$single$|$D$|$double$|$DE$|$doubleextended$|$DD$|$doubledouble$|$QD$|$quad$|$TD$|$tripledouble}, \textsf{RN$|$RZ$|$RU$|$RD}) $\rightarrow$ \textsf{constant}\\
\end{center}
Parameters:
\begin{itemize}
\item \emph{x} is a constant to be rounded.
\item \emph{n} is the precision of the target format.
\item \emph{format} is the name of a supported floating-point format.
\item \emph{mode} is the desired rounding mode.
\end{itemize}
\noindent Description: \begin{itemize}
\item If used with an integer parameter \emph{n}, \textbf{round}(\emph{x},\emph{n},\emph{mode}) rounds \emph{x} to a floating-point number with
precision \emph{n}, according to rounding-mode \emph{mode}.
\item If used with a format parameter \emph{format}, \textbf{round}(\emph{x},\emph{format},\emph{mode}) rounds \emph{x} to a floating-point number in the
floating-point format \emph{format}, according to rounding-mode \emph{mode}.
\item Subnormal numbers are handled for the case when \emph{format} is one of
\textbf{halfprecision}, \textbf{single}, \textbf{double}, \textbf{doubleextended}, \textbf{doubledouble},
\textbf{quad} or \textbf{tripledouble}. Otherwise, when \emph{format} is an integer,
\textbf{round} does not take any exponent range into consideration,
i.e. typically uses the full exponent range of the underlying MPFR
library.
\item It is worth mentioning that the result of \textbf{round} does not depend on
the current global precision of \sollya, unless a warning is
displayed. As a matter of fact, \textbf{round} rounds the given constant or
constant expression \emph{x} applying all rules of IEEE 754 correct
rounding, unless a warning is displayed. The result of \textbf{round} is
hence the floating-point value of the given precision \emph{n} or format
\emph{format} that is nearest to \emph{x} (resp. just below or just above,
depending on \emph{mode}), computed as if infinite precision were used for
evaluating the constant \emph{x}, unless a warning is displayed.
\end{itemize}
\noindent Example 1:
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> display=binary!;
> round(Pi,20,RN);
1.100100100001111111_2 * 2^(1)
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2:
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> printdouble(round(exp(17),53,RU));
0x417709348c0ea4f9
> printdouble(D(exp(17)));
0x417709348c0ea4f9
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3:
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> display=binary!;
> a=2^(-1100);
> round(a,53,RN);
1_2 * 2^(-1100)
> round(a,D,RN);
0
> double(a);
0
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{RN} (\ref{labrn}), \textbf{RD} (\ref{labrd}), \textbf{RU} (\ref{labru}), \textbf{RZ} (\ref{labrz}), \textbf{halfprecision} (\ref{labhalfprecision}), \textbf{single} (\ref{labsingle}), \textbf{double} (\ref{labdouble}), \textbf{doubleextended} (\ref{labdoubleextended}), \textbf{doubledouble} (\ref{labdoubledouble}), \textbf{quad} (\ref{labquad}), \textbf{tripledouble} (\ref{labtripledouble}), \textbf{roundcoefficients} (\ref{labroundcoefficients}), \textbf{roundcorrectly} (\ref{labroundcorrectly}), \textbf{printdouble} (\ref{labprintdouble}), \textbf{printsingle} (\ref{labprintsingle}), \textbf{ceil} (\ref{labceil}), \textbf{floor} (\ref{labfloor}), \textbf{nearestint} (\ref{labnearestint})
|