@@ -23,9 +23,9 @@ The main type of interest is the :class:`BigFloat` class. The
2323a string:
2424
2525 >>> BigFloat(123 )
26- BigFloat.exact('123.00000000000000 ', precision=53 )
27- >>> BigFloat(- 4.56 )
28- BigFloat.exact('-4.5599999999999996 ', precision=53 )
26+ BigFloat.exact('123.000000000000000000000000000000000 ', precision=113 )
27+ >>> BigFloat(" -4.56" )
28+ BigFloat.exact('-4.55999999999999999999999999999999966 ', precision=113 )
2929
3030Each :class: `BigFloat ` instance has both a *value * and a *precision *.
3131The precision gives the number of bits used to store the significand
@@ -41,7 +41,8 @@ representable. Just like Python floats, the printed form of a
4141stored value, for the benefit of human readers.
4242
4343The precision of a newly-constructed :class: `BigFloat ` instance is
44- dictated by the *current precision *, which defaults to ``53 ``. This
44+ dictated by the *current precision *, which defaults to ``113 `` (the precision
45+ of the IEEE 754 "binary128" format, a.k.a. quadruple precision). This
4546setting can be overridden by supplying the ``context `` keyword
4647argument to the constructor:
4748
@@ -54,9 +55,9 @@ defaults to :data:`RoundTiesToEven`; again, this can be overridden with
5455the ``context `` keyword argument:
5556
5657 >>> BigFloat(' 3.14' )
57- BigFloat.exact('3.1400000000000001 ', precision=53 )
58+ BigFloat.exact('3.14000000000000000000000000000000011 ', precision=113 )
5859 >>> BigFloat(' 3.14' , context = RoundTowardZero)
59- BigFloat.exact('3.1399999999999997 ', precision=53 )
60+ BigFloat.exact('3.13999999999999999999999999999999972 ', precision=113 )
6061 >>> BigFloat(' 3.14' , context = RoundTowardPositive + precision(24 ))
6162 BigFloat.exact('3.14000010', precision=24)
6263
@@ -97,12 +98,13 @@ object that corresponds to the IEEE 754 binary128 interchange format::
9798 >>> BigFloat('1.1', quadruple_precision)
9899 BigFloat.exact('1.10000000000000000000000000000000008', precision=113)
99100
100- The current settings for precision and rounding mode given by the :ref: `current
101- context <current context>`, accessible via the :func: `getcontext ` function:
101+ The current settings for precision and rounding mode are given by the
102+ :ref: `current context <current context >`, accessible via the :func: `getcontext `
103+ function:
102104
103105 >>> getcontext()
104- Context(precision=53 , emax=1073741823 , emin=-1073741823 , subnormalize=False ,
105- rounding='RoundTiesToEven' )
106+ Context(precision=113 , emax=16384 , emin=-16493 , subnormalize=True ,
107+ rounding=ROUND_TIES_TO_EVEN )
106108
107109There's also a :func: `setcontext ` function for changing the current
108110context; however, the preferred method for making temporary changes to
@@ -138,9 +140,9 @@ terms of :meth:`BigFloat.exact`. The :class:`str` of a :class:`BigFloat` looks
138140prettier, but doesn't supply enough information to recover that
139141:class: `BigFloat ` exactly if you don't know the precision:
140142
141- >>> print BigFloat(' 1e1000' , precision(20 ))
143+ >>> print ( BigFloat(' 1e1000' , precision(20 ) ))
142144 9.9999988e+999
143- >>> print BigFloat(' 1e1000' , precision(21 ))
145+ >>> print ( BigFloat(' 1e1000' , precision(21 ) ))
144146 9.9999988e+999
145147
146148Arithmetic on :class: `BigFloat ` instances
@@ -151,9 +153,9 @@ those instances can be freely mixed with integers and floats (but not strings!)
151153in those operations:
152154
153155 >>> BigFloat(1234 )/ 3
154- BigFloat.exact('411.33333333333331 ', precision=53 )
156+ BigFloat.exact('411.333333333333333333333333333333317 ', precision=113 )
155157 >>> BigFloat(' 1e1233' )** 0.5
156- BigFloat.exact('3.1622776601683794e +616', precision=53 )
158+ BigFloat.exact('3.16227766016837933199889354443271851e +616', precision=113 )
157159
158160As with the :class: `BigFloat ` constructor, the precision for the result is
159161taken from the current context, as is the rounding mode used to round
@@ -176,7 +178,7 @@ representable as a :class:`BigFloat`.
176178 BigFloat.exact('323447650962475799134464776910021681085720319890462540093389
177179 5331391691459636928060001.0', precision=281)
178180 >>> + BigFloat.exact(7 ** 100 )
179- BigFloat.exact('3.2344765096247579e +84', precision=53 )
181+ BigFloat.exact('3.23447650962475799134464776910021692e +84', precision=113 )
180182
181183 This makes the unary plus operator useful as a way to round a
182184 result produced in a different context to the current context.
@@ -186,9 +188,9 @@ corresponding function. For example, the :func:`div` function
186188corresponds to usual (true) division:
187189
188190 >>> 355 / BigFloat(113 )
189- BigFloat.exact('3.1415929203539825 ', precision=53 )
191+ BigFloat.exact('3.14159292035398230088495575221238935 ', precision=113 )
190192 >>> div(355 , 113 )
191- BigFloat.exact('3.1415929203539825 ', precision=53 )
193+ BigFloat.exact('3.14159292035398230088495575221238935 ', precision=113 )
192194
193195This is useful for a couple of reasons: one reason is that it makes it
194196possible to use ``div(x, y) `` in contexts where a :class: `BigFloat ` result is
@@ -209,9 +211,9 @@ difference in the results of the following:
209211 >>> y = 10 ** 16 . # 10.**16 is exactly representable as a float
210212 >>> x - y
211213 0.0
212- >>> BigFloat(x) - BigFloat(y)
214+ >>> BigFloat(x, double_precision ) - BigFloat(y, double_precision )
213215 BigFloat.exact('0', precision=53)
214- >>> sub(x, y)
216+ >>> sub(x, y, double_precision )
215217 BigFloat.exact('1.0000000000000000', precision=53)
216218
217219For the first subtraction, the integer is first converted to a float,
@@ -247,20 +249,20 @@ operations above:
247249
248250Here are some examples::
249251
250- >>> sqrt(1729, context=RoundTowardZero)
251- BigFloat.exact('41.581245772583578 ', precision=53 )
252- >>> sqrt(1729, context=RoundTowardPositive)
253- BigFloat.exact('41.581245772583586 ', precision=53 )
254- >>> atanh(0.5, context=precision(20))
255- BigFloat.exact('0.54930592', precision=20)
256- >>> const_catalan(precision(1000))
257- BigFloat.exact('0.9159655941772190150546035149323841107741493742816721342664
258- 9811962176301977625476947935651292611510624857442261919619957903589880332585
259- 9059431594737481158406995332028773319460519038727478164087865909024706484152
260- 1630002287276409423882599577415088163974702524820115607076448838078733704899
261- 00864775113226027', precision=1000)
262- >>> 4*exp(-const_pi()/2/agm(1, 1e-100))
263- BigFloat.exact('9.9999999999998517e-101', precision=53)
252+ >>> sqrt(1729, context=RoundTowardZero)
253+ BigFloat.exact('41.5812457725835818902802091854716460 ', precision=113 )
254+ >>> sqrt(1729, context=RoundTowardPositive)
255+ BigFloat.exact('41.5812457725835818902802091854716521 ', precision=113 )
256+ >>> atanh(0.5, context=precision(20))
257+ BigFloat.exact('0.54930592', precision=20)
258+ >>> const_catalan(precision(1000))
259+ BigFloat.exact('0.9159655941772190150546035149323841107741493742816721342664
260+ 9811962176301977625476947935651292611510624857442261919619957903589880332585
261+ 9059431594737481158406995332028773319460519038727478164087865909024706484152
262+ 1630002287276409423882599577415088163974702524820115607076448838078733704899
263+ 00864775113226027', precision=1000)
264+ >>> 4*exp(-const_pi()/2/agm(1, 1e-100))
265+ BigFloat.exact('9.9999999999998517e-101', precision=53)
264266
265267For a full list of the supported functions, see the :ref: `standard functions `
266268section of the :ref: `api reference `.
@@ -282,7 +284,7 @@ the thousandth harmonic number:
282284 ... lower_bound = sum (div(1 , n) for n in range (1 , 1001 ))
283285 ... with RoundTowardPositive: # upper bound
284286 ... upper_bound = sum (div(1 , n) for n in range (1 , 1001 ))
285- ...
287+ ...
286288 >>> lower_bound
287289 BigFloat.exact('7.4854708605503449126565182015873', precision=100)
288290 >>> upper_bound
@@ -297,7 +299,7 @@ the nth harmonic number [#harmonic]_:
297299 >>> n = 1000
298300 >>> with precision(100 ):
299301 ... approx = log(n) + const_euler() + div(1 , 2 * n) - 1 / (12 * sqr(n))
300- ...
302+ ...
301303 >>> approx
302304 BigFloat.exact('7.4854708605503365793271531207983', precision=100)
303305
@@ -306,9 +308,9 @@ Let's check it:
306308
307309 >>> error = approx - lower_bound
308310 >>> error
309- BigFloat.exact('-8.3333293650807890e -15', precision=53 )
311+ BigFloat.exact('-8.33332936508078900174283813097652403e -15', precision=113 )
310312 >>> - 1 / (120 * pow (n, 4 ))
311- BigFloat.exact('-8.3333333333333336e -15', precision=53 )
313+ BigFloat.exact('-8.33333333333333333333333333333333391e -15', precision=113 )
312314
313315A more permanent change to the context can be effected using the
314316:func: `setcontext ` function, which takes a single argument of type
@@ -350,25 +352,26 @@ set and test these flags:
350352
351353 >>> set_flagstate(set ()) # clear all flags
352354 >>> get_flagstate()
353- set([] )
355+ set()
354356 >>> exp(10 ** 100 )
355- BigFloat.exact('inf', precision=53 )
357+ BigFloat.exact('inf', precision=113 )
356358 >>> get_flagstate()
357- set([ 'Overflow', 'Inexact'])
359+ { 'Overflow', 'Inexact'}
358360
359361These flags show that overflow occurred, and that the given result
360362(infinity) was inexact. The flags are sticky: none of the standard
361363operations ever clears a flag:
362364
365+
363366 >>> sqrt(2 )
364- BigFloat.exact('1.4142135623730951 ', precision=53 )
367+ BigFloat.exact('1.41421356237309504880168872420969798 ', precision=113 )
365368 >>> get_flagstate() # overflow flag still set from the exp call
366- set([ 'Overflow', 'Inexact'])
369+ { 'Overflow', 'Inexact'}
367370 >>> set_flagstate(set ()) # clear all flags
368371 >>> sqrt(2 )
369- BigFloat.exact('1.4142135623730951 ', precision=53 )
370- >>> get_flagstate() # sqrt only sets the inexact flag
371- set([ 'Inexact'])
372+ BigFloat.exact('1.41421356237309504880168872420969798 ', precision=113 )
373+ >>> get_flagstate() # sqrt only sets the inexact flag
374+ { 'Inexact'}
372375
373376The functions :func: `clear_flag `, :func: `set_flag ` and
374377:func: `test_flag ` allow clearing, setting and testing of individual
0 commit comments