File: approx.tex

package info (click to toggle)
sollya 7.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 13,864 kB
  • sloc: ansic: 117,441; yacc: 8,822; lex: 2,419; makefile: 870; cpp: 76
file content (85 lines) | stat: -rw-r--r-- 3,312 bytes parent folder | download | duplicates (4)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
\subsection{$\sim$}
\label{labapprox}
\noindent Name: \textbf{$\sim$}\\
\phantom{aaa}floating-point evaluation of a constant expression\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_approx(sollya_obj_t)|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{$\sim$} \emph{expression} : \textsf{function} $\rightarrow$ \textsf{constant}\\
\textbf{$\sim$} \emph{something} : \textsf{any type} $\rightarrow$ \textsf{any type}\\
\end{center}
Parameters: 
\begin{itemize}
\item \emph{expression} stands for an expression that is a constant
\item \emph{something} stands for some language element that is not a constant expression
\end{itemize}
\noindent Description: \begin{itemize}

\item \textbf{$\sim$} \emph{expression} evaluates the \emph{expression} that is a constant
   term to a floating-point constant. The evaluation may involve a
   rounding. If \emph{expression} is not a constant, the evaluated constant is
   a faithful rounding of \emph{expression} with \textbf{precision} bits, unless the
   \emph{expression} is exactly $0$ as a result of cancellation. In the
   latter case, a floating-point approximation of some (unknown) accuracy
   is returned.

\item \textbf{$\sim$} does not do anything on all language elements that are not a
   constant expression.  In other words, it behaves like the identity
   function on any type that is not a constant expression. It can hence
   be used in any place where one wants to be sure that expressions are
   simplified using floating-point computations to constants of a known
   precision, regardless of the type of actual language elements.

\item \textbf{$\sim$} \textbf{error} evaluates to error and provokes a warning.

\item \textbf{$\sim$} is a prefix operator not requiring parentheses. Its
   precedence is the same as for the unary $+$ and $-$
   operators. It cannot be repeatedly used without brackets.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(exp(5));
exp(5)
> print(~ exp(5));
148.41315910257660342111558004055227962348766759388
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> autosimplify = off!;
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(~sin(5 * pi));
0
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 4: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(~exp(x));
exp(x)
> print(~ "Hello");
Hello
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 5: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(~exp(x*5*Pi));
exp((pi) * 5 * x)
> print(exp(x* ~(5*Pi)));
exp(x * 15.7079632679489661923132169163975144209858469968757)
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 6: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> print(~exp(5)*x);
148.41315910257660342111558004055227962348766759388 * x
> print( (~exp(5))*x);
148.41315910257660342111558004055227962348766759388 * x
> print(~(exp(5)*x));
exp(5) * x
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{evaluate} (\ref{labevaluate}), \textbf{prec} (\ref{labprec}), \textbf{error} (\ref{laberror})