Liberty BASIC Community Forum
« Extended ('infinite') precision calculations »

Welcome Guest. Please Login or Register.
Feb 18th, 2018, 3:44pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Extended ('infinite') precision calculations  (Read 113 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1182
xx Extended ('infinite') precision calculations
« Thread started on: Jan 22nd, 2018, 09:25am »

Over the years I've had fun calculating beyond the intrinsic numeric accuracy of my languages' compilers/interpreters. It recently cropped up again on Yahoo forum.
For those who are interested, see my digame site. It has code for things like calculating the decimal expansion of fractions to your choice of significant figures....
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2834
xx Re: Extended ('infinite') precision calculations
« Reply #1 on: Jan 23rd, 2018, 12:51pm »

Here is an example that I posted on Yahoo as a response to the original poster. The longSci$() function returns an extended precision version of a floating point number. This is just the beginning of an ultimate solution because it only works with numbers between 0 and 1.

Please consider yourselves invited to extend it. ;)

-Carl

Code:
    global pad$
    pad$ = replstr$(space$(15), " ", "#")+"."+replstr$(space$(300), " ", "#")
    a=123456789
    for n=1 to -15 step -1
        b=a^n
        print n; tab(5);longSci$(b); tab(30); b
    next n
    end

function longSci$(value)
    shortForm$ = str$(value)
    if left$(shortForm$, 2) = "0." or left$(shortForm$, 3) = "-0." then
        offset = val(mid$(shortForm$, instr(shortForm$, "-")+1))
    end if
    longForm$ = using(left$(pad$, offset+16+15),value)
    longForm$ = trim$(longForm$)
    if instr(longForm$,"0.") = 1 then
       longSci$ = "0."+left$(mid$(longForm$, offset+3), 16)+"e-"+str$(offset)
       if value < 0 then longSci$ = "-" + longSci$
     else
       longSci$ = shortForm$
    end if
end function  
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1182
xx Re: Extended ('infinite') precision calculations
« Reply #2 on: Jan 23rd, 2018, 5:44pm »

Such functions are very region-specific, and in my career I've always used 'scientist notation' and powers/exponents and in my programming they've always been sufficient. I've written specific formatting functions, but a general-purpose one is potentially an endless task to chase!

Different countries use period '.' signs where others use spaces or commas ','. I write pound sign before the number on my tax return. (Guess what I was doing today!) Most other countries write the currency sign afterwards.

My reference in this topic was to 'unlimited' precision of handling fractions. The OP was the one looking for such a function, which is why I posted here as well as replying to his thread.

My LB code that produced this result for 1/7th plus 6/7ths will happily churn out the result to say 10000 places...
User Image
Available as mentioned on my site..
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls