Bignum calculator

Sometimes you need more digits. I tried a number of variable precision calculators - most were not worth the time spent downloading. Many were trial versions that lock up after a month. Some of them tried to install malware, so you need a way to recover to a known state.

I found the simplest turned out to be the best for my needs. It has three levels of precision - 26, 152 and 306 valid decimal digits. The input and output can be expressed in any base from 2 to 16, including base 10 (decimal). It is free, open source and very easy to use and understand.

One feature I like is View -> Calcpad. It is like Notepad, but you can enter expressions and see the results immediately. You can copy and paste portions to change the equation and see the new answer. You can save the page to a file for use later.

The program is called TTCalc and the url is

formatting link

The sourceforge download site was broken when I checked just now, but it should be fixed soon.

In case you need to know what is pi / 2^64, the answer is

1.70306079004327729466759809794578735839198815414777353665956268115344693 8733184698579298387912196010685781650115592918184910566151987332517519666 7174984221045153337909221834750679014871833075677183273117440480240024420 3829651173944154518870843515349866595233665266903393947606391433996064465 6106232300364171e-19

approximately.

Reply to
Tom Swift
Loading thread data ...

You're like the Spice model makers at some foundries who list CMOS parameters out to six places. Such foolishness. Who needs it. Such folk are NOT engineers. ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| San Tan Valley, AZ 85142     Skype: skypeanalog  |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 
              
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Nah. Just calculating the correct increments for a 48-bit DDS needs long doubles.

I use a little calculator that I coded in REXX, which has arbitrary precision built in. (It actually calls the huge supervisor script for my EM simulator under the covers.)

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

One should really consider what type of calculation is done.

Any internally base 2 (4, 18, 16 etc.) calculators are useless, since

0.1 or 0.01 (important in any financial calculations) can't be expressed exactly.

For any floating point representation, I would look for something like

+/-9.9E+/-99, +/-9.9E+/-999 ranges.
Reply to
upsidedown

How does it differ from bc(1) -- other than the fact that it *only* supports 3 levels of precision?

If you're going for arbitrary precision arithmetic, it's usually smarter to opt for BigDecimal or BigRational instead of Bignum. Having "n decimal digits" of precision isn't the same as doing the actual arithmetic *in* decimal.

Reply to
Don Y

On a sunny day (Sat, 20 Dec 2014 18:46:30 +0200) it happened snipped-for-privacy@downunder.com wrote in :

If yo uhve a decent Linux distro, and type: apropos arbitrary yiu get some hints There is the 'bc' program for example, to get pi in 4000 decimals, try: ~ # echo "scale=4000; 4*a(1)" | bc -l

3.141592653589793238462643383279502884197169399375105820974944592307\ 81640628620899862803482534211706798214808651328230664709384460955058\ 22317253594081284811174502841027019385211055596446229489549303819644\ 28810975665933446128475648233786783165271201909145648566923460348610\ 45432664821339360726024914127372458700660631558817488152092096282925\ 40917153643678925903600113305305488204665213841469519415116094330572\ 70365759591953092186117381932611793105118548074462379962749567351885\ 75272489122793818301194912983367336244065664308602139494639522473719\ 07021798609437027705392171762931767523846748184676694051320005681271\ 45263560827785771342757789609173637178721468440901224953430146549585\ 37105079227968925892354201995611212902196086403441815981362977477130\ 99605187072113499999983729780499510597317328160963185950244594553469\ 08302642522308253344685035261931188171010003137838752886587533208381\ 42061717766914730359825349042875546873115956286388235378759375195778\ 18577805321712268066130019278766111959092164201989380952572010654858\ 63278865936153381827968230301952035301852968995773622599413891249721\ 77528347913151557485724245415069595082953311686172785588907509838175\ 46374649393192550604009277016711390098488240128583616035637076601047\ 10181942955596198946767837449448255379774726847104047534646208046684\ 25906949129331367702898915210475216205696602405803815019351125338243\ 00355876402474964732639141992726042699227967823547816360093417216412\ 19924586315030286182974555706749838505494588586926995690927210797509\ 30295532116534498720275596023648066549911988183479775356636980742654\ 25278625518184175746728909777727938000816470600161452491921732172147\ 72350141441973568548161361157352552133475741849468438523323907394143\ 33454776241686251898356948556209921922218427255025425688767179049460\ 16534668049886272327917860857843838279679766814541009538837863609506\ 80064225125205117392984896084128488626945604241965285022210661186306\ 74427862203919494504712371378696095636437191728746776465757396241389\ 08658326459958133904780275900994657640789512694683983525957098258226\ 20522489407726719478268482601476990902640136394437455305068203496252\ 45174939965143142980919065925093722169646151570985838741059788595977\ 29754989301617539284681382686838689427741559918559252459539594310499\ 72524680845987273644695848653836736222626099124608051243884390451244\ 13654976278079771569143599770012961608944169486855584840635342207222\ 58284886481584560285060168427394522674676788952521385225499546667278\ 23986456596116354886230577456498035593634568174324112515076069479451\ 09659609402522887971089314566913686722874894056010150330861792868092\ 08747609178249385890097149096759852613655497818931297848216829989487\ 22658804857564014270477555132379641451523746234364542858444795265867\ 82105114135473573952311342716610213596953623144295248493718711014576\ 54035902799344037420073105785390621983874478084784896833214457138687\ 51943506430218453191048481005370614680674919278191197939952061419663\ 42875444064374512371819217999839101591956181467514269123974894090718\ 64942319615679452080951465502252316038819301420937621378559566389377\ 87083039069792077346722182562599661501421503068038447734549202605414\ 66592520149744285073251866600213243408819071048633173464965145390579\ 62685610055081066587969981635747363840525714591028970641401109712062\ 80439039759515677157700420337869936007230558763176359421873125147120\ 53292819182618612586732157919841484882916447060957527069572209175671\ 16722910981690915280173506712748583222871835209353965725121083579151\ 36988209144421006751033467110314126711136990865851639831501970165151\ 16851714376576183515565088490998985998238734552833163550764791853589\ 32261854896321329330898570642046752590709154814165498594616371802709\ 81994309924488957571282890592323326097299712084433573265489382391193\ 25974636673058360414281388303203824903758985243744170291327656180937\ 73444030707469211201913020330380197621101100449293215160842444859637\ 66983895228684783123552658213144957685726243344189303968642624341077\ 3226978028073189154411010446823252716201052652272111660396

(free, from man bc )

But Jim is right, normally I do not need that sort of precision, but it is fun to play with.

Reply to
Jan Panteltje

First, not everyone *is* an engineer. So, they may not understand the significance of particular operator/operand orderings and their consequences on a given precision math implementation.

Second, I suspect lots of engineers ALSO fall in this camp -- though perhaps understand the *obvious* issues (rounding, lack of precision, etc.). But, may be ignorant of other aspects of numerical analysis that will

*silently* corrupt the results of their calculations. (How close to 1/3 is your *actual* representation of that quantity?)

I've got 300 people in a room. How many different ways can I pair them up? Or, assign them to groups of 20 souls? Surely, this is no different than rewording it as "15 people in a room, how many potential pairings"? Yet, the latter will readily yield a numeric result while the former will challenge anything that doesn't like "really big numbers".

Finding roots to polynomials is another case that's rife with possibilities for cancellation/overflow.

Chances are, you'll plug these into a formula -- *or*, a program already designed for these purposes -- and never notice the "bad things" that happen along the way.

Reply to
Don Y

Good one. Thanks.

Yeah, some numerical problems need mega precision. We're going to do a

64 bit DDS soon! The LSB is 5e-20 of full scale. Around 0.1 picoHertz.

Most Windows calculators use double (64 bit) floats underneath.

PowerBasic has an 80 bit float type, which sometimes helps a little.

--

John Larkin         Highland Technology, Inc 
picosecond timing   laser drivers and controllers 

jlarkin att highlandtechnology dott com 
http://www.highlandtechnology.com
Reply to
John Larkin

I tend to use Algebra a lot in my behavioral modeling, so I'm quite wary. ...Jim Thompson

--
| James E.Thompson                                 |    mens     | 
| Analog Innovations                               |     et      | 
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    | 
| San Tan Valley, AZ 85142     Skype: skypeanalog  |             | 
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  | 
| E-mail Icon at http://www.analog-innovations.com |    1962     | 
              
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

You do not seem to understands the issue.

Within EU, when converting from non euro-based currency to an other non-euro based currency, you first convert to euros at a specific number of decimals, cutting with some exactly specified number of decimals, before converting to a target currency.

Reply to
upsidedown

Sure -- but not all calculations are financial. :> As you said, "what type of calculation is done". And, also, who/what the ultimate consumer of that calculation will be.

I provide BigDecimals to (novice) users in my scripting language. I don't expect -- or want -- them to be aware of the idiosyncrasies of "math packages". Rather, let them concentrate on "saying what they want" without regard for the mechanism that "makes it happen". If they wanted to add together the paychecks of every man woman and child on the planet and divide by the number of souls to get a *real* "average income", they should be able to -- without having to lecture them in the issues of roundoff error, precision, etc.

When *I* need to do something comparable (in a "canned" -- one size fits all -- implementation), I use BigRationals. This still doesn't help with *irrational* quantities -- but moving into symbolic math packages is seldom worth that effort (for one-offs, Mathematica fares delightfully well!)

Where *efficiency* is the driving issue, then other choices are more appropriate! (I sure wouldn't use Bignums to count to 10!)

Reply to
Don Y

Nonsense. You just use Stirling's formula for the gamma function, the way it's done in thermodynamics with pairwise interactions of 10**25 particles.

There are pathological polynomials, but not many.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

"

A long time ago as an undergraduate I had a "Sinclair Scientific" calculato r. In an assessed (week long) physics practical I used this to calculate t he radius of gyration of electrons in a magnetron. The result was wrong. Just a bit wrong. It was slightly larger than the dimensions of the appara tus. I didn't comment on this in my report.

I was marked by Prof. Mott who was still teaching despite having "retired".

He reduced my mark by 10% because "I don't want you ever to forget this". And I didn't.

His main point was that I should have commented on a result that was obviou sly wrong. The cause of the problem was that dividing one number by the di fference between two similar numbers can result in some spectacular errors if the calculator is less precise than you had supposed.

John

Reply to
jrwalliker

Oops - reformatted

A long time ago as an undergraduate I had a "Sinclair Scientific" calculator. In an assessed (week long) physics practical I used this to calculate the radius of gyration of electrons in a magnetron. The result was wrong. Just a bit wrong. It was slightly larger than the dimensions of the apparatus. I didn't comment on this in my report.

I was marked by Prof. Mott who was still teaching despite having "retired".

He reduced my mark by 10% because "I don't want you ever to forget this". And I didn't.

His main point was that I should have commented on a result that was obviously wrong. The cause of the problem was that dividing one number by the difference between two similar numbers can result in some spectacular errors if the calculator is less precise than you had supposed.

John

Reply to
jrwalliker

On a sunny day (Sat, 20 Dec 2014 21:15:08 +0200) it happened snipped-for-privacy@downunder.com wrote in :

Is not that what the 'scale' command is all about in the bc calculator?

Reply to
Jan Panteltje

On a sunny day (Sat, 20 Dec 2014 12:10:09 -0800 (PST)) it happened snipped-for-privacy@gmail.com wrote in :

Yes, one thing that intrigues me is the 'alien problem' (found in sci.crypt years ago). It goes something like this: Alien comes to earth, is impressed by all the knowledge humans have acquired, and wants to take some of that wisdom home. He wants to take the Encyclopedia Britannica, but there is no space and the weight is too much for his flying saucer. He then takes a stick, and puts a mark somewhere on it so that the 2 length divided by each other give the ASCII numbers of the text of the encyclopedia.

L1 L2 ================ stick ^ mark

Reply to
Jan Panteltje

I believe the on chip floating point processor is 80bits in extended percision, thats why. Other wise its 64bit.

Cheers

Reply to
Martin Riddle

~=.170306079004327729466759809794578735839198815414777353665956268115344693

8733184698579298387912196010685781650115592918184910566151987332517519666 7174984221045153337909221834750679014871833075677183273117440480240024420 3829651173944154518870843515349866595233665266903393947606391433996064465 6106232300364171083150710598639894630276435540352202824712921369669656717 3854815141945045138756087464734125975146350421238550806960996220092184847 229056533598102207522728315084583434057710046314270032518354317e-18

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward" 
speff@interlog.com             Info for manufacturers: http://www.trexon.com 
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

On a sunny day (Sat, 20 Dec 2014 16:38:48 -0500) it happened Spehro Pefhany wrote in :

~ # bc -l bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type arranty'. scale=40

4*a(1)/2^64 .0000000000000000001703060790043277294667

scale=400

4*a(1)/2^64 .0000000000000000001703060790043277294667598097945787358391988154147\ 77353665956268115344693873318469857929838791219601068578165011559291\ 81849105661519873325175196667174984221045153337909221834750679014871\ 83307567718327311744048024002442038296511739441545188708435153498665\ 95233665266903393947606391433996064465610623230036417108315071059863\ 9894630276435540352202824712921369669656717385481514194504513

scale=4000

4*a(1)/2^64 .0000000000000000001703060790043277294667598097945787358391988154147\ 77353665956268115344693873318469857929838791219601068578165011559291\ 81849105661519873325175196667174984221045153337909221834750679014871\ 83307567718327311744048024002442038296511739441545188708435153498665\ 95233665266903393947606391433996064465610623230036417108315071059863\ 98946302764355403522028247129213696696567173854815141945045138756087\ 46473412597514635042123855080696099622009218484722905653359810220752\ 27283150845834340577100463142700325183543173640687653669825926850616\ 85780513957492495817875308275217897873458651601529275766703558372460\ 36647375079966966007925214321930019915569633989887238266405891109654\ 73689994993805031901152701697445770552126282019377898124701734354969\ 42261307961191258472007476199089803705474305891436922098909736035360\ 69096416646177417750307070042454590051383400555173694950334948411016\ 87606633071519968701871908943053327760162564366399146755391592090126\ 41311268826523874061171164312192070502033401342378855064547094946006\ 55286050467038535282314908056874750953077604589541735033134556306885\ 87523188244797409464158248348329454034484666487633209546291076199335\ 87376796351735360925201131248063246669948061821426974978307923303294\ 48965575802200545511032066896314425848953359043506556810449601816817\ 60326175164440875581070430904780201737592893954226060574328232170525\ 52561547600536891341092163603849728296512018367465394238205351933148\ 29847896703526899527721185547286399858713573406062074625256818708974\ 25697587496367904218367700698607126400818199541877703823227433433079\ 28538627782439146457135002850403612333166054024109725392134481497791\ 26986011052823053624829077735651390887624450773533747279157804038680\ 35830252297874986727740614879956632315699098553465202708449251415421\ 12582936735381582884647575930318654136148718288839078627283514388760\ 06875165555819526762848636818788518295701324468758701233124001418764\ 00619628395483859544243787178261013344348171013879992216598743852487\ 15994009072586644700223827383097000088489341265465868065128456627034\ 44097444831426979518415039983732575385176091798125549386022374974521\ 31367656517484210856034439090905874584937915348900238119597733084964\ 94012318833710704029085123833920300100262336540144440879695412809340\ 39350071170508196660039264912855609356650160413633420096406634284477\ 73799659695218025218360590062639679477802688106981722671725865422558\ 08110309542389950765637526538905056701855328787840994947116486208619\ 58195420277131352454820109054514575174557349411453490086958838513463\ 63831336326538691631289325238513697615842461961372737539070772853395\ 89225037338881970981850681505850401091960442759190321497810264910644\ 00449620921842253585804787884680410007261629164989898746475992759028\ 88565092929439127813706370286286013761458705063450514824871530384837\ 08645098156848905612975284733215059786459812034867549890919347091263\ 05348063978489764310236726229253028216605471274362604782779740318692\ 56939976910724129370141744412922987638228491989993358761920465829425\ 52137650656513571524934688161504994742714383676198285012348395708261\ 73675704960727823979281958711503489353138663613845122898883231216050\ 23614298407878506217399549015753342446814769793201197199086701678478\ 10265164822096400238751837713188699346863705481136283537431870913237\ 81309326239119705044956082232250354199408102626845445616322101435405\ 00840604488762357876265745433866920984916983310750282543651386487052\ 65413334459274792086161241930518403216606970834261801819079371928885\ 98651654339276737826749967826044729005300415583488226815203468801592\ 35804116987386092354373191737823655786076577483829195971357103440574\ 98504269018260421965242339221829225390073345387866744397511680752082\ 26078204601405185137282704158431105650021135569130852428440109404247\ 73836281395477743031847742764003125810518917285145404504108154212834\ 67835385209379017557378941515190907443271330865767705231215458309975\ 08898547188053065321697415837189073250565126019947721902595990936984\ 875017622155697940191069790801815730030527439835310184494
Reply to
Jan Panteltje

There are times when, if you arrange your calculations so that the math is easy, the precision needed is absurd. It would be foolish to make a circuit like that (unless you have a PhD and no experience -- then it would be obvious), but doing the math that way makes sense.

For that matter, there are a number of problems in control systems where you really want 32-bit fixed-point numbers, even in a system where an analog circuit that has a dynamic range of 120dB would be absurd.

--
www.wescottdesign.com
Reply to
Tim Wescott

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.