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 s4QLP75v005425 for ; Mon, 26 May 2014 23:25:09 +0200 Received: from relay2.uni-heidelberg.de ([129.206.210.211]) by mx-ha.gmx.net (mxgmx001) with ESMTPS (Nemesis) id 0LomRH-1WLTCX0ydv-00goZH for ; Mon, 26 May 2014 23:25:02 +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 s4QLMGmk005439 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 26 May 2014 23:22:16 +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 s4QHlJSC029629; Mon, 26 May 2014 23:22:15 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 11125145 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Mon, 26 May 2014 23:22:15 +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 s4QLMFNH008493 for ; Mon, 26 May 2014 23:22:15 +0200 Received: from smtp3.clear.net.nz (smtp3.clear.net.nz [203.97.33.64]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id s4QLLvji013856 for ; Mon, 26 May 2014 23:22:00 +0200 Received: from mxin2-orange.clear.net.nz (lb2-srcnat.clear.net.nz [203.97.32.237]) by smtp3.clear.net.nz (CLEAR Net Mail) with ESMTP id <0N67008LL9ZXBS10@smtp3.clear.net.nz> for LATEX-L@listserv.uni-heidelberg.de; Tue, 27 May 2014 09:21:56 +1200 (NZST) Received: from 121-74-43-114.telstraclear.net (HELO [127.0.0.1]) ([121.74.43.114]) by smtpin2.clear.net.nz with ESMTP; Tue, 27 May 2014 09:21:53 +1200 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 7bit X-Antivirus: avast! (VPS 140526-3, 27/05/2014), Outbound message X-Antivirus-Status: Clean References: <5382FD21.6040600@clear.net.nz> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 Message-ID: <5383B06E.1000908@clear.net.nz> Date: Tue, 27 May 2014 09:21:50 +1200 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: aparsloe Subject: Re: l3fp and sin(pi), cos(pi/2) To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: 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:QJoQ9VYA4Sk=:AdG9LS+uETcmhCWf4RJ7LexRVH xl63MuxazEju5wwDoPCmdT3vdqOWEUYyUoPXhA8B7Qq53pvivFQqmq036liszvXmsyngjXE4i mUrtiFvyJjbRsgGh6IMluflYEIoxIXtJqjVsqu6wNcjBawlfEQpIDh7AhSzDbY8YHlPovXcon FofN7vf0zHx8NT4sQMc65ofPmos0ZzDjS63cWm5Xor4t/eW29D192eGZAmZFwf9SH1N8VzLpj R0nKaCwefrB59flSS369N5YWHYwRv5DEfys4RZeRyLRXQ5y2DHLJbyObfKteWudg0EHZ+L0Js 1RhhZ4lqQG57gVAXcMJqJGOPdQvN0j//ZApbPiH2ZgYlttx8l/9Afyrjch07/0SqMWcyd+UA7 8z6QAUUcSuK4sQebGh5T01EvMgwtIhGJhjW15qaEGtyG8hI6gOvz76nf7ysTKxlfi2fJVlATf oFjaEEHzF4rCozxRk/SVlsrLtUIBf/a6diuEGXdTubJBLie7QKxVR0DQQ8aicHuUqWUeO22Hc A7OV1A/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w== X-UI-Loop:V01:sEyzj3aLa+c=:Z6Q6brLS+df1/aY9oQ612SIL9aUQNjeyAfsjfzTIMs0= Status: R X-Status: X-Keywords: X-UID: 7452 On 27/05/2014 5:41 a.m., Bruno Le Floch wrote: > 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. Not at all: thank you for the full explanation. Andrew