QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: johnno56 on September 13, 2021, 05:27:33 pm

Title: Calculator v QB64
Post by: johnno56 on September 13, 2021, 05:27:33 pm
I enjoy using Basic to calculate basic (no pun intended) Astronomical stuff. For the past several decade I have been using a book, "Practical Astronomy with your calculator". Time for an upgrade. Write a simple program to do it for me... Right?

My very first problem... Divide 2000 by 19. How simple could you get.... My handheld calculator states: 105.2631579. My computer's calculator states: 105.263157895 and RCBasic states: 105.263158. However, QB64 states: 105.2631607.

I know the difference is quite small, but when it comes to Astronomy, precision is a must.

Can someone check this simple equation on both computer and calculator... Just in case I may be doing something wrong? An explanation for the difference and a possible solution would be appreciated.

J
Title: Re: Calculator v QB64
Post by: Pete on September 13, 2021, 05:45:58 pm
My string-math app gives me:

105.2631578947368421052631578947368421052631578947368421052631578947368

105.2631578947368 via Windows 10 calculator.

Pete
Title: Re: Calculator v QB64
Post by: SMcNeill on September 13, 2021, 06:03:07 pm
Code: QB64: [Select]
  1. n## = 2000## / 19##
  2. PRINT USING "###.##################"; n##
  3. PRINT "105.2631578947368421052631578947368421052631578947368421052631578947368"
  4.  

Comparing to Pete's string math figure, I get 17 digits of matching precision.  It isn't until the 18th digit that the numbers vary by a minute amount.

(105.263157894736842105 is the value I'm getting, if you're curious.)
Title: Re: Calculator v QB64
Post by: Pete on September 13, 2021, 06:40:23 pm
So I looked up this inline big numbers calculator, and fed in 100 digits after the decimal place. My string math is shown on top, and the online results directly below. Nice to know my 68th digit after the decimal is correctly rounded, but I can't remember if that's a coincidence or if I programed it to toss the last digit and round.

105.2631578947368421052631578947368421052631578947368421052631578947368
105.2631578947368421052631578947368421052631578947368421052631578947368421052631578947368421052631578947

Anyway, if you want to check it out to up to 9,999 decimal places, go here...
https://www.calculator.net/big-number-calculator.html

However, see the pattern? This decimal infinitely repeats as .263157894736842105

Pete
Title: Re: Calculator v QB64
Post by: bplus on September 13, 2021, 06:57:12 pm
@johnno56

Try QB64 highest precision for default variable type
Code: QB64: [Select]
  1. _Define A-Z As _FLOAT  ' < default variables at highest precision for QB64
  2. n = 2000
  3. d = 19
  4. Print n / d
  5.  
  6.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Calculator v QB64
Post by: SMcNeill on September 13, 2021, 07:03:27 pm
@bplus Remember to use Print Using -- you can specify to display a higher degree of printed results than with Print alone.  (See my post above and compare to yours.  I have several extra digits of precision displayed.)
Title: Re: Calculator v QB64
Post by: johnno56 on September 13, 2021, 07:23:54 pm
Thanks guys. Calculating the phase of the moon or the next eclipse or the approximate position of the planets could get by with six to nine decimal places.... Much appreciated.

J
Title: Re: Calculator v QB64
Post by: Pete on September 13, 2021, 08:25:59 pm
Just make sure you mark my post as "The Best Answer" or you'll get my full moon in your phase!

Pete :D
Title: Re: Calculator v QB64
Post by: jack on September 13, 2021, 10:39:31 pm
hey Pete, here's challenge for you, find the first 50 digits of 2^(2^(2^(2^(2^2))))  https://community.wolfram.com/groups/-/m/t/2359839
you can calculate the answer easily enough using the pari/gp program http://pari.math.u-bordeaux.fr/
Title: Re: Calculator v QB64
Post by: Pete on September 13, 2021, 10:51:13 pm
6.031226062630295×10^19727.78040560677

I'll settle for 11!

Pete
Title: Re: Calculator v QB64
Post by: jack on September 13, 2021, 11:05:35 pm
not quite right
Title: Re: Calculator v QB64
Post by: jack on September 13, 2021, 11:17:58 pm
2^(2^(2^(2^(2^2)))) is equivalent to 2^(2^65536)
Title: Re: Calculator v QB64
Post by: jack on September 13, 2021, 11:31:54 pm
it's more like 2.12003872880821198488x10^(10^19727.780405607)
Title: Re: Calculator v QB64
Post by: SMcNeill on September 14, 2021, 12:11:15 am
it's more like 2.12003872880821198488x10^(10^19727.780405607)

Might as well be the SQRT(-1) on my farm.  As far as I can tell, they’re both imaginary numbers with no real bearing on my life!  :P
Title: Re: Calculator v QB64
Post by: Pete on September 14, 2021, 12:31:16 am
Well find a round whoe and have her dig those square roots up!

Pete

I tried measuring an atom once, but I couldn't get the the damn thing to hold still. It cost me my job at the nuclear accelerator plant. You know like they say, measure twice, split once.