Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Precision
#1
Hello
For some rather complicated mathematical calculations, I use the # tag to increase the precision. As a result of the calculations, errors arise. A professional astronomer suggested that he use more than 32 bits for his calculations. So the question is how to increase the accuracy of the calculations? Is the # sign already the most accurate option ?.
Regards Chris
Reply
#2
There is ## but not that much better.

Hi Chris, welcome to forum! I sure hope we are talking about QB64 preferable pe versions.
b = b + ...
Reply
#3
We usually write our own programs for these situations.

Search terms for this forum:

1) "String math" Fast for +_*/ but slow for decimal powers and nth roots. (Authors Pete, bplus, Treebeard).

2) "Dec_Float" To 52 places, if memory serves. (Author: Jack).

For QB64 variable types, look here: https://qb64phoenix.com/qb64wiki/index.p...able_Types


Pete
Reply
#4
## But is it more than 32 bits ?. I don't really understand what more than 32 bit accuracy means.
Reply
#5
I don't know how it happened: two topics
Reply
#6
How to apply dec float here? It only gives part of the code.


rplus1 = c1plus1 MOD 1095
rminus1 = c1minus1 MOD 1095
v1 = 32336 * q + INT((15 * q + 765433 * R + 12084) / 25920)
v1plus1 = 32336 * qplus1 + INT((15 * qplus1 + 765433 * rplus1 + 12084) / 25920)
v1minus1 = 32336 * qminus1 + INT((15 * qminus1 + 765433 * rminus1 + 12084) / 25920)
v2 = v1 + INT(6 * (v1 / 7)) MOD 2
v2plus1 = v1plus1 + INT(6 * (v1plus1 / 7)) MOD 2
v2minus1 = v1minus1 + INT(6 * (v1minus1 / 7)) MOD 2
L2 = v2plus1 - v2
L2minus1 = v2 - v2minus1
v3 = 2 * (INT((L2 + 19) / 15) MOD 2)
v4 = INT((L2minus1 + 7) / 15) MOD 2
c2 = v2 + v3 + v4
v3plus1 = 2 * (INT((L2plus1 + 19) / 15) MOD 2)
v4plus1 = INT((L2 + 7) / 15) MOD 2
c2plus1 = v2plus1 + v3 + v4
L = c2plus1 - c2
c8 = INT((L + 7) / 2) MOD 15
c9 = -(INT((385 - L) / 2) MOD 15)
c3 = INT((384 * x3 + 7) / 13) + c8 * INT((x3 + 4) / 12) + c9 * INT((x3 + 3) / 12)
Reply
#7
(11-22-2022, 09:04 PM)Chris Wrote: I don't know how it happened: two topics

No worries.  I merged them for you.  ?
Reply
#8
Easiest fix for you would appear to be:

_DEFINE A-Z AS _FLOAT

Add to top of code and see if that helps.
Reply
#9
Welcome to the forums.

You can't have an astronomer nor anybody else decide for you.

Now you presented some code, you'll have to declare all those variables "AS DOUBLE" and see if the results are satisfactory. If the code stands just as it is, the variables will be type "SINGLE" which is lesser precision than "DOUBLE".

Using type sigils is a bad habit taught to new programmers of BASIC. Learn to use "DIM" to declare variables so there is no confusion what type it is. Yes the sigil helps to describe what type straight away but what if other "simple" types come around in the future? How to decorate an UDT variable? So with this program try to put "#" right after each word which is more time consuming than a single "DIM" line. But it's only my opinion.

Another bad habit which is a shortcut, is to place "_DEFINE A-Z AS DOUBLE" as the first line of this code that was presented.
Reply
#10
Probably don't want to mix floats (##) with MOD. 

Maybe you want _Integer64 Type (&& suffix)

v1 = 32336 * q + INT((15 * q + 765433 * R + 12084) / 25920)
I don't know, do you expect rounding v1 to Integer or want to keep a float?
b = b + ...
Reply




Users browsing this thread: 6 Guest(s)