Author Topic: Calculator v QB64  (Read 4514 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Calculator v QB64
« 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
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculator v QB64
« Reply #1 on: September 13, 2021, 05:45:58 pm »
My string-math app gives me:

105.2631578947368421052631578947368421052631578947368421052631578947368

105.2631578947368 via Windows 10 calculator.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calculator v QB64
« Reply #2 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.)
« Last Edit: September 13, 2021, 06:05:47 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculator v QB64
« Reply #3 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calculator v QB64
« Reply #4 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.  

  [ You are not allowed to view this attachment ]  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calculator v QB64
« Reply #5 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.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Calculator v QB64
« Reply #6 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
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculator v QB64
« Reply #7 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Calculator v QB64
« Reply #8 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/
« Last Edit: September 13, 2021, 10:42:11 pm by jack »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculator v QB64
« Reply #9 on: September 13, 2021, 10:51:13 pm »
6.031226062630295×10^19727.78040560677

I'll settle for 11!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Calculator v QB64
« Reply #10 on: September 13, 2021, 11:05:35 pm »
not quite right

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Calculator v QB64
« Reply #11 on: September 13, 2021, 11:17:58 pm »
2^(2^(2^(2^(2^2)))) is equivalent to 2^(2^65536)

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Calculator v QB64
« Reply #12 on: September 13, 2021, 11:31:54 pm »
it's more like 2.12003872880821198488x10^(10^19727.780405607)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Calculator v QB64
« Reply #13 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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Calculator v QB64
« Reply #14 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.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/