source: git/ntl/doc/tour-ex6.html @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 2cfffe, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6316, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6317 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.5 KB
Line 
1<html>
2<head>
3<title>
4A Tour of NTL: Examples: Floating Point Classes </title>
5</head>
6
7<body bgcolor="#fff9e6">
8<center>
9<a href="tour-ex5.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
10 <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
11<img src="arrow3.gif" alt="[Next]" align=bottom>
12</center>
13
14<h1> 
15<p align=center>
16A Tour of NTL: Examples: Floating Point Classes
17</p>
18</h1>
19
20<p> <hr> <p>
21
22NTL also supports arbitrary precision floating point with
23the class <tt>RR</tt>.
24Additionally, it supports two specialized classes: <tt>quad_float</tt>,
25which gives a form of quadruple precision, but without an extended
26exponent range,
27and <tt>xdouble</tt>,
28which gives double precision, but with an extended exponent range.
29The advantage of the latter two classes is efficiency.
30
31<p>
32
33Here again is a program that reads a list of numbers from the input,
34and outputs the sum of their squares, using the class <tt>RR</tt>.
35<p>
36
37<pre>
38#include &lt;NTL/RR.h&gt;
39
40int main()
41{
42   RR acc, val;
43
44   acc = 0;
45   while (SkipWhiteSpace(cin)) {
46      cin &gt;&gt; val;
47      acc += val*val;
48   }
49
50   cout &lt;&lt; acc &lt;&lt; "\n";
51}
52</pre>
53
54<p>
55
56The precision used for the computation can be set by executing
57<pre>
58   RR::SetPrecision(p);
59</pre>
60which sets the effective precision to <tt>p</tt> bits.
61By default, <tt>p=150</tt>.
62All of the basic arithmetic operations compute their results
63by rounding to the nearest <tt>p</tt>-bit floating point number.
64The semantics of this are exactly the same as in the IEEE floating
65point standard (except that there are no special values, like
66"infinity" and "not a number").
67
68<p>
69
70The number of <i>decimal</i> digits of precision that are used when
71printing an <tt>RR</tt> can be set be executing
72<pre>
73   RR::SetOutputPrecision(d);
74</pre>
75which sets the output precision to <tt>d</tt>.
76By default, <tt>d=10</tt>.
77
78<p>
79See <a href="RR.txt"><tt>RR.txt</tt></a> for details.
80
81<p>
82
83By replacing the occurences of <tt>RR</tt> by either <tt>quad_float</tt>
84or <tt>xdouble</tt>, one gets an equivalent program using one of the
85other floating point classes.
86The output precision for these two classes can be controlled just
87as with <tt>RR</tt>.
88See <a href="quad_float.txt"><tt>quad_float.txt</tt></a> and
89<a href="xdouble.txt"><tt>xdouble.txt</tt></a>
90for details.
91
92<p>
93
94
95<center>
96<a href="tour-ex5.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
97 <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
98 <img src="arrow3.gif" alt="[Next]" align=bottom>
99</center>
100
101</body>
102</html>
Note: See TracBrowser for help on using the repository browser.