Karim BELABAS on Tue, 18 Mar 2003 11:25:17 +0100 (MET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: real precision again


On Tue, 18 Mar 2003, Walter Neumann wrote:
> At large precision (over 395 digits) sin(Pi*2.) claims to have twice as
> many significant digits as it should:
[...]
> ? sin(%)
> %4 = 2.083415134163379771317306786512007684572941095163701634157290887739967165726519878072310347834290217941711584606256087453734814712822486064338376377290291271528114660633609372113745774583418171579011473210390805058843715841645813527378491473322289166282480743273765616722933205149866985251359777695245970930844694020475677754390894758209754567147135178467574886857510516861792192562776849904346531125 E-404

That's much more than twice as many...

(11:18) gp > \p400
(11:18) gp > sin(2*Pi)
%1 = 2.083415135 E-404

is better.

It's related to a topic recently discussed [ subject was sin(x) for exact huge
argument ] : we really compute cos(x mod Pi/2) - 1, which can't have more
significant digits than x mod Pi/2. Unfortunately the computation was
organized in the following way:

  let prec := precision of x
  reduce x mod Pi/2
  ...
  assign result to real of precision prec

which is wrong if catastrophic cancellation occurs when reducing mod Pi/2.


Fixed.  [ The computation also required a reduction mod Pi/2 in full
accuracy, which is wasteful; and always computed Pi, even if |x| < 1. Both
fixed. ]

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425   Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://www.parigp-home.de/  [PARI/GP]