Compute pi to base 12 using Python?

Paul Rubin http
Wed Apr 13 21:20:06 EDT 2005


Dick Moores <rdm at rcblue.com> writes:
> I need to figure out how to compute pi to base 12, to as many digits
> as possible. I found this reference,
> <http://mathworld.wolfram.com/Base.html>, but I really don't
> understand it well enough. Could someone show me how to do what I need?

Using the GNU "bc" utility:

  $ bc -l
  bc 1.06
  Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
  This is free software with ABSOLUTELY NO WARRANTY.
  For details type `warranty'. 
  scale = 3000    # number of output places wanted
  obase = 12      # output base
  print 4 * a(1)  # pi = 4*arctan(1)
  3.184809493B918664573A6211BB151551A05729290A7809A492742140A60A55256A\
  0661A03753A3AA54805646880181A3683083272BBBA0A370B12265529A828903B4B2\
  56B8403759A71626B8A54687621849B849A8225616B442796A31737B229B23914898\
  53943B8763725616447236B027A421AA17A38B52A18A838B01514A51144A23315A30\
  09A8906B61B8B48A62253A88A50A43BA0944572315933664476B3AABB77583975120\
  683526B75B462060BB03B432551913772729A2147553531793848A0402B999B50585\
  35374465A68806716644039539A8431935198527B9399B112990ABB0383B10764542\
  4577A51601B3624A88B7A676A3992912121A213887B92873946A61332242217AA735\
  4115357744939112602BA4B888818A3269222B528487747839994AB223B65B876269\
  5422822669BA00A586097842A51750362073B5A768363B21BB1A97A4A19444774939\
  9804922175A068A46739461990A2065BB0A30BBAB7024A585B1A84428195489784A0\
  7A331A7B0A1574565B373B05B03A5A80A13AB87857734679985558A5373178A7B282\
  71992A3894A5776085083B9B238B2220542462888641A2BAB8B3083AB49659172A31\
  2B78518654494A068662586A181835A64440B2970A12281397589881536720890580\
  1032881449223841428763329617531239B9A657405584014534390B587625606BB8\
  0923795944B43757A431B039556282978A6A49590553490BA1844947175637A90824\
  7B50127722464441380A852B0847B5813019BB70A67663B426565434069884476132\
  193344BA55A2128A03838974606B851B2979321A408067225A5AA4B3464A1A174735\
  95333909AB9127079655B3164B68B9B28A9B818A220A025AB0934203995B7A62A7AA\
  739355340539BA3182905B193905603A43B660B9426A92294697144A896A5B233935\
  8BB2B7294BB89635B071A6351211360B820B1882AB8433B54757B87A373284B1BA18\
  2A10326476B369A4A6365B58B8018994BB152556765475A704BB94B6B2A39458971A\
  8B90512786B5029404818644323552916170B3ABB7363496427B088B68725A685700\
  40617949289077B278069A09B559324B8A66828B40549B0296065B2300330592569A\
  7B76B92BA1293585B6A9B604567A0901362856373B4B56897946256B4172B1B50474\
  351364749A33996A81BA8847347A8411B850B79A03018291672AA0945656A159AA6A\
  A0A845531A592005B8A34366B882257107B190969A846474836A9800750778920BA7\
  97297A2791101B0685A86BB704B9BAA17B055293679843B35215B0A8B1182B611953\
  B080AA5431B219907A8448A81B1A9493245676B88013B47033524085959415862101\
  4216619553246570601967448B470174B9244892444817453865A4003B5AA7176451\
  AAB90681A949786154AA040477382BA69371041710B8728458A23979252B25423675\
  3A44A1900AA283536A227648812525743868B410A567794663359A6726A528678332\
  8135114789B7645505B047848020A730A9557B206776AA56A19682744107901306B2\
  9008808619866B4911A05264B872A46B5376383932699531B449195640B62A636228\
  30886247A47B3957169861239358041AA281333622AA15912B0A636047A489BB0726\
  282A78B96671B27305A9652496B9B999011A7BA36898891665B1A6009058978850A2\
  1B01A158A1473B84A192B8672542A2A7056581995207A436A5B3BA2824637A3112AB\
  B57176468206A071200A327B3216425148100786502AA21236ABB35499277670A126\
  9730583403B1922A483856007301983989159BB688A58B602339806B63002A339A50\
  B0BA533B84827793913081070A32595A101803A9A20234691B1A0B623274B69B0B44\
  688195169461059543A252BB05208720BA13118266A872B26B9B584959B44B
  quit
  $ 

The arctan calculation takes about 20 sec on an Athlon of around 2 ghz.



More information about the Python-list mailing list