Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with ESMTP id s4QHi0rN004374 for ; Mon, 26 May 2014 19:44:01 +0200 Received: from relay2.uni-heidelberg.de ([129.206.210.211]) by mx-ha.gmx.net (mxgmx006) with ESMTPS (Nemesis) id 0LZmsW-1WRySs3ifc-00lUqB for ; Mon, 26 May 2014 19:43:55 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s4QHfSq1017494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 26 May 2014 19:41:28 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s4QGb11U029629; Mon, 26 May 2014 19:41:27 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 11118899 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Mon, 26 May 2014 19:41:27 +0200 Received: from relay.uni-heidelberg.de (relay.uni-heidelberg.de [129.206.100.212]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s4QHfRFc010783 for ; Mon, 26 May 2014 19:41:27 +0200 Received: from mail-qc0-f178.google.com (mail-qc0-f178.google.com [209.85.216.178]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id s4QHfHnu030567 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Mon, 26 May 2014 19:41:20 +0200 Received: by mail-qc0-f178.google.com with SMTP id l6so12369704qcy.37 for ; Mon, 26 May 2014 10:41:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.95.80 with SMTP id h74mr32819885qge.2.1401126076888; Mon, 26 May 2014 10:41:16 -0700 (PDT) Received: by 10.96.19.42 with HTTP; Mon, 26 May 2014 10:41:16 -0700 (PDT) References: <5382FD21.6040600@clear.net.nz> Content-Type: text/plain; charset=UTF-8 Message-ID: Date: Mon, 26 May 2014 13:41:16 -0400 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Bruno Le Floch Subject: Re: l3fp and sin(pi), cos(pi/2) To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: <5382FD21.6040600@clear.net.nz> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: Envelope-To: X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=V3; X-GMX-Antivirus: 0 (no virus found) X-UI-Filterresults: notjunk:1;V01:K0:QePvHZeymug=:5qxkwChk4QElshGQkUAHWd3mK9 wn7QqACaACD8lj43yoXmmZH4Aj6SVMa1OtRGNOcGZcJxVkhRkoPbD4YgegEhx/JO+VLBr29BR qI0c7OFCqqeiMYiKoFkkhuYU54r45xtj7ZrP6JAUcL5Rdgd6OKw01sCQ0y1nax/WIKZpi7rBs NpFQCaiqS9DS/gXnt4+vP2PqC+m+aqyvmTXxsW54iwYUp1Qh2HtS0gipd8rWevpG7sZciC/Rc Kh8p2azXCCsCO/KgJukrKYGYnXozuKplb6O/SWRE/pJVSWasttdXKjPi2dIwLFGL7Hvg1/fBX IzNnjojc69LA9bR2myLKkVQiTzTS+SI7V2IrceaqGEH1pNTm8Kyd78ghu7KoO7CIq+aI/Z/qN 23BxMjpIY+rROH6ULhuz5uKGhioNvo3ZbJsj1wWONSZ1zpkRNYxyFjvKVCXgoHd9XbyZY3fcf PYjYEEU/6yDyS/ueiZxR8eabXs0Obn6FrUsvj98bGWhpJkuf+3RmwMd7XqOJrjqlbUs3HAnnP bn4xLjPXeCiwkHFD9B9ZAUzyisbAsMdZfm1bKAD3JJI/GYxSpUo/voPUYjqZ1VnOyMPHXLJzr fF6tzS3609CbmYvnF/2Xa5p4a858oKtBuV/a6rgF6XlwtPxJYYeRaWNS/JKKNXw6Aa9qNVzfj Q8KcOfwKWjEyRJ0JvP+PC6flGjoIfVKkDjKqMd4AHwU/BW3z0lhD+rijVvT3wHkOluwB0Lb+C jBNQFwfkCbWZGANEjoeO8gLcy6g+rL6Li5T4375hswLQACNAOh0hiakEoPVb4yIj2IZIugdpg pLPcyhmi2Nfghdj4++JniyDGPgTAmm4ms2ujt2SQcGuV0gOQXBwNTFy7tydrrDdMlDzQYxJxF q1+p7aHkpxoi9ZmJkIP1iYm86DcOGj+IlzQWiT7zlKd5KObl4zeL7ysYzUkQHEyGXoYFT7NeR uk6z2X2xpMXwDJ+psiB66mDFkQm+JGj7UMpOJ6pWbevuUNbrRpm3HuUXmHZWnqhAG3eHgz3pP ZMMe0+OVLXXnNSPpns9ISmGd5uxf+kTJiqmGgtTM8wciPg1hKezLifLr9b/luHhk65IVvpBC9 5V/CmOCtjsJpuhj28nmGfLmZh8ZEbQj49WgPdu2rQioeU7en/6vyQfRcMvI9jHtkTE99fIDPE kKYH0bO5giQqoMLsezQFDZuSEP8u9iHs2d68e4mFzfDWlqLpccu3Bf80EihDtO1GkZETfHC99 +szyrNOL5dgj1l9jGTKxfTxPrDEF9JTgaTWDLDQF+QpugtGlMoYnyy3NJNM9iDjXZFpFIIxfx wOd8jGmgynmcySDgaykXlEez44Ca05fWn79EYNvS7zAATgmhQ4EWXBwrsECeo63MT0tdXWZsm LMjpjx1Rz9G32LbaevmQnWYNlpspSbuaxQc6D3cA1zPzyZX2+E71nP0IlFJIZq1NRycZWNLqx TqFyb5yEV6Mit9T3we22g3LI8OnuZMjlBo/E9Sd7TJm3QFWPWOLPLTTkqDpHcZDf9Z/Eu+9RR aP8mVj1coo7fulMMLJ5TCPCS2dFat3wv8KZAqPbfj X-UI-Loop:V01:Onzt1Gk5lyM=:qlyyzoXyvYqcsEpBGkl+KlVxM8i/7X8aopIKD30eonU= Status: R X-Status: X-Keywords: X-UID: 7451 Hello, Short answer: use the trigonometric functions which expect arguments in degrees: sind, cosd, tand,... sind(180) correctly gives -0. On 5/26/14, aparsloe wrote: > \fp_eval:n { sin(pi) } -> 0.0000000000000002384626433832795 > > as if the 16 nonzero digits after the run of zeros are the significant > ones. They are. When computing sin(pi), the great majority (exceptions: sage, mathematica, maple,...) of programming languages/libraries will first round pi to a number that can be represented in memory (with a finite number of binary or decimal digits), then compute the sine of that number, then round again. For instance, python: echo 'from math import *; print sin(pi)' | python gives 1.22460635382e-16, which is the representable number (in a 53? bit mantissa) closest to the exact sine of the representable number (in a 53? bit mantissa) closest to pi. Exactly the same happens in l3fp, as it should. pi is rounded to 3.141592653589793, and the sine of this number is computed, giving approximately 2e-16 as you saw. In an earlier version of l3fp, I had actually implemented trigonometric functions so that they would have a period of exactly 3.141592653589794 (there were technical reasons for this approximation of pi instead of the slightly more accurate 3.141592653589793). Now that trigonometric functions are available in degrees too, it is not necessary to cheat for radians any more. > Rounding the cosine to 16 figures gives a 6 in the last place, which > seems large to me. cos(pi/2) => cos(3.141592653589793/2) => cos(1.570796326794896) => 6.192313216916398e-16 The approximation of pi differs from the real value by about 2e-16. When dividing by 2, the last digit is odd hence there is a rounding involved (as per the IEEE standard the rounding should be in such a way that the result's last digit is even), giving an approximation of pi/2 which is off by about 5e-16+(2e-16)/2=6e-16. Since cos(pi/2+epsilon) is approximately -epsilon, we do expect the result of cos(pi/2), computed with 16 decimal digits of precision, to be about 6e-16. > Perhaps sin and cos and their fellows should be given > the exact value 0 at the appropriate multiples of pi/2? No. See above: use sind, cosd, and so on. Regards, Bruno PS: Probably more details than needed, sorry.