?? tour-ex6.html
字號:
<html><head><title>A Tour of NTL: Examples: Floating Point Classes </title></head><body bgcolor="#fff9e6"><center><a href="tour-ex5.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> <img src="arrow3.gif" alt="[Next]" align=bottom></center><h1> <p align=center>A Tour of NTL: Examples: Floating Point Classes</p></h1><p> <hr> <p>NTL also supports arbitrary precision floating point with the class <tt>RR</tt>.Additionally, it supports two specialized classes: <tt>quad_float</tt>,which gives a form of quadruple precision, but without an extendedexponent range, and <tt>xdouble</tt>,which gives double precision, but with an extended exponent range.The advantage of the latter two classes is efficiency.<p>Here again is a program that reads a list of numbers from the input,and outputs the sum of their squares, using the class <tt>RR</tt>.<p><pre>#include <NTL/RR.h>int main(){ RR acc, val; acc = 0; while (SkipWhiteSpace(cin)) { cin >> val; acc += val*val; } cout << acc << "\n";}</pre><p>The precision used for the computation can be set by executing <pre> RR::SetPrecision(p);</pre>which sets the effective precision to <tt>p</tt> bits.By default, <tt>p=150</tt>.All of the basic arithmetic operations compute their resultsby rounding to the nearest <tt>p</tt>-bit floating point number. The semantics of this are exactly the same as in the IEEE floatingpoint standard (except that there are no special values, like "infinity" and "not a number").<p>The number of <i>decimal</i> digits of precision that are used whenprinting an <tt>RR</tt> can be set be executing<pre> RR::SetOutputPrecision(d);</pre>which sets the output precision to <tt>d</tt>.By default, <tt>d=10</tt>.<p>See <a href="RR.txt"><tt>RR.txt</tt></a> for details.<p>By replacing the occurences of <tt>RR</tt> by either <tt>quad_float</tt>or <tt>xdouble</tt>, one gets an equivalent program using one of theother floating point classes.The output precision for these two classes can be controlled justas with <tt>RR</tt>.See <a href="quad_float.txt"><tt>quad_float.txt</tt></a> and <a href="xdouble.txt"><tt>xdouble.txt</tt></a>for details.<p><center><a href="tour-ex5.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> <img src="arrow3.gif" alt="[Next]" align=bottom></center></body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -