Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Mark H Harris Newsgroups: comp.lang.python Subject: Re: Fortran (Was: The "does Python have variables?" debate) Date: Sun, 11 May 2014 23:10:49 -0500 Organization: Aioe.org NNTP Server Lines: 53 Message-ID: References: <87tx91warf.fsf@elektro.pacujo.net> <85eh05cdjx.fsf@benfinney.id.au> <87ha50hagu.fsf@elektro.pacujo.net> <536b8411$0$29965$c3e8da3$5496439d@news.astraweb.com> <536b9308$0$29965$c3e8da3$5496439d@news.astraweb.com> <536bab23$0$29965$c3e8da3$5496439d@news.astraweb.com> <87mweotfe5.fsf@dpt-info.u-strasbg.fr> NNTP-Posting-Host: RbLuqvdjwUNhJiyJQaji5Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.python:71366 On 5/11/14 10:10 PM, Dave Angel wrote: > On 05/11/2014 02:54 PM, Mark H Harris wrote: > >> >> >julia> sin(BigFloat(π/4)) >> > 7.0710678118654750275194295621751674626154323953749278952436611913748 >> > 20215180412e-01 with 256 bits of precision >> > > That answer doesn't seem to come anywhere near 256 bits of precision. > > Using Python 3.2, > > >>> x=70710678118654750275194295621751674626154323953749278952436611913748 > >>> x*x > 4999999999999999693838300213161705693483516931249926767981110058185818806614907837502621065882204197129973479350206261627418690991407504 > > > Not that this is surprising, but it does make a terrible ad for how > great Julia is. > Dave, you get the golden egg! I expected D'Aprano to catch it first! Yes, BigFloat does the same dumb thing Python's Decimal does. π/4 is not a BigFloat, and BigFloat simply makes the 16 digit float into a 256 bit float, the sin of which will only be 16 digits accurate (more or less). It has nothing to do with the language (Python vs. Julia) it has to do with the way the BigFloat is formed. So let's fix it by forming the π constant as a BigFloat constant: >julia> n = BigFloat(1) >1e+00 with 256 bits of precision >julia> π = atan(n/5)*16 - atan(n/239)*4 >3.141592653589793238462643383279502884197169399375105820974944592307816406286198e+00 >with 256 bits of precision >julia> S = sin(π/4) >7.07106781186547524400844362104849039284835937688474036588339868995366239231051e-01 >with 256 bits of precision >julia> S * S >4.999999999999999999999999999999999999999999999999999999999999999999999999999957e-01 >with 256 bits of precision Not too bad... marcus