[Edu-sig] Long floats?

Kirby Urner pdx4d@teleport.com
Sat, 13 Jan 2001 10:50:34 -0800


At 04:18 AM 01/12/2001 -0500, Tim Peters wrote:
>The only language I know of with native support for adjustable (by the user)
>precision floats is REXX.  There are BigFloat libraries available at least
>for Perl and Ruby, and IIRC also Java.  Some specialized numeric
>environments (e.g., Macsyma) also support them.
>
>As far as I know, nobody ever bothered to write one for Python.  Python has
>something far more strange and wonderful, though:
>
>ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/
>    DataStructures/real-accurate.pyar

Thank you Tim!

Once again, your input is right on the money.  I've been having a
fun time computing things to the nth digit (plus/minus).  Such 
a powerful little package!

  O frabjous day! Callooh! Callay!" 
  He chortled in his joy. 

                -- Lewis Carroll

Kirby

PS:  appended, my letter to the math teacher, who is also
turned on about Python at this point, probably chortling 
as well:

On Fri, 12 Jan 2001 21:11:07 -0800, you wrote:

>>Here's some feedback re the "long float" question from
>>Tim Peters.  He's a Python god and, even better,
>>consistently helpful and forthcoming with hard-to-find
>>information re Python and programming in general.
>
>Nifty!
>I'd seen big floats in C++ but not in any of the other languages.
>I'll give that library a whirl.
>Looks like it has plenty of decimal places for me!
>
>Thanks,
>--[XXXXXXXX]
>

Yes, I've been playing with it too (see appended value of 
PHI = (1+sqrt(5))/2

I'm not familiar with the .pyar extension.  I renamed it
to .py after downloading, and then, since hyphenated file
names are problematic, I had to use a weird syntax for
import, shown below.


 >>> __import__("real-accurate") # after changing extension to .py
 real.README : written.
 real.py : written.
 <module 'real-accurate' from 'g:\python20\lib\real-accurate.py'>
 >>> import real
 >>> from real import *
 >>> pi()
 3.141592653589793238462643383279503+-2
 >>> sqrt(5)
 2.23606797749978969640917366873127+-2
 >>> (1+sqrt(5))/2
 1.61803398874989484820458683436564+-1
 >>> pow((1+sqrt(5))/2,2)
 2.61803398874989484820458683436564+-5
 >>> for i in range(10):  print pow( (1+sqrt(5))/2,i )

 1
 1.61803398874989484820458683436564+-1
 2.61803398874989484820458683436564+-5
 4.2360679774997896964091736687312+-4
 6.854101966249684544613760503097+-2
 11.09016994374947424102293417183+-2
 17.94427190999915878563669467491+-3
 29.03444185374863302665962884674+-3
 46.97871376374779181229632352168+-3
 76.0131556174964248389559523685+-3

 >>> for i in range(10):  print pow( (sqrt(5)*(1+sqrt(5))/2),i )

 1
 3.6180339887498948482045868343656+-1
 13.090169943749474241022934171827+-2
 47.36067977499789696409173668730+-3
 171.3525491562421136153440125775+-5
 619.95934690622108325626137945+-1
 2243.03398874989484820458683436+-3
 8115.3732092183688247416272746+-1
 29361.6961023423698826852022010+-2
 106231.614465620005289717874632+-2

And here's PHI (only took a few seconds):

 >>> rep('(1+sqrt(5))/2')  

<< SNIP -- iterations of lesser precision >>

1.61803398874989484820458683436563811772030917980576286213
5448622705260462818902449707207204189391137484754088075386
8917521266338622235369317931800607667263544333890865959395
8290563832266131992829026788067520876689250171169620703222
1043216269548626296313614438149758701220340805887954454749
2461856953648644492410443207713449470495658467885098743394
4221254487706647809158846074998871240076521705751797883416
6256249407589069704000281210427621771117778053153171410117
0466659914669798731761356006708748071013179523689427521948
4353056783002287856997829778347845878228911097625003026961
5617002504643382437764861028383126833037242926752631165339
2473167111211588186385133162038400522216579128667529465490
6811317159934323597349498509040947621322298101726107059611
6456299098162905552085247903524060201727997471753427775927
7862561943208275051312181562855122248093947123414517022373
5805772786160086883829523045926478780178899219902707769038
9532196819861514378031499741106926088674296226757560523172
7775203536139362107673893764556060605921658946675955190040
0555908950229530942312482355212212415444006470340565734797
6639723949499465845788730396230903750339938562102423690251
3868041457799569812244574717803417312645322041639723213404
4449487302315417676893752103068737880344170093954409627955
8986787232095124268935573097045095956844017555198819218020
6405290551893494759260073485228210108819464454422231889131
9294689622002301443770269923007803085261180754519288770502
1096842493627135925187607778846658361502389134933331223105
3392321362431926372891067050339928226526355620902979864247
2759772565508615487543574826471814145127000602389016207773
2244994353088999095016803281121943204819643876758633147985
7191139781539780747615077221175082694586393204565209896985
5567814106968372884058746103378105444390943683583581381131
1689938555769754841491445341509129540700501947754861630754
2264172939468036731980586183391832859913039607201445595044
9779212076124785645916160837059498786006970189409886400764
4361709334172709191433650137157660114803814306262380514321
1734815100559013456101180079050638142152709308588092875703
4505078081454588199063361298279814117453392731208092897279
2221329806429468782427487401745055406778757083237310975915
1177629784432847479081765180977872684161176325038612112914
3683437670235037111633072586988325871033632223810980901211
0198991768414917512331340152733843837234500934786049792945
9915822012581045982309255287212413704361491020547185549611
8087642657651106054588147560443178479858453973128630162544
8761148520217064404111660766950597757832570395110878230827
1064789390211156910392768384538633332156582965977310343603
2322545743637204124406408882673758433953679593123221343732
0995749889469956564736007295999839128810319742631251797141
4320123112795518947781726914158911779919564812558001845506
5632952859859100090862180297756378925999164994642819302229
3552346674759326951654214021091363018194722707890122087287
3617073486499981562554728113734798716569527489008144384053
2748378137824669174442296349147081570073525457070897726754
6934382261954686153312095335792380146092735102101191902183
6067509730895752895774681422954339438549315533963038072916
9175846101460995055064803679304147236572039860073550760902
3173125016132048435836481770484818109916024425232716721901
8933459637860878752870173935930301335901123710239171265904
7026349402830766876743638651327106280323174069317334482343
5645318505813531085497333507599667787124490583636754132890
8624063245639535721252426117027802865604323494283730172557
4405837278267996031739364013287627701243679831144643694767
0531272492410471670013824783128656506493434180390041017805
3395058772458665575522939158239708417729833728231152569260
9299594224000056062667867435792397245408481765197343626526
8944888552720274778747335983536727761407591712051326934483
7529916499809360246178442675727767900191919070380522046123
2482391326104327191684512306023627893545432461769975753689
0417636502547851382463146583363833760235778992672988632161
8583959036399818384582764491245980937043055559613797343261
3483049494968681089535696348281781288625364608420339465381
9441945714266682371839491832370908574850266568039897440662
1053603064002608171126659954199368731609457228881092077882
2772036366844815325617284117690979266665522384688311371852
9919216319052015686312228207155998764684235520592853717578
0765605036773130975191223973887224682580571597445740484298
7807352215984266766257807706201943040054255015831250301753
409411719101929890384+-1

Seems to be a powerful package.  Fun, too (guess I must
be a nerd, huh -- actually I prefer "geek" as an honorific).

Kirby