Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
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
Posts: 3,986
Threads: 178
Joined: Apr 2022
Reputation:
222
11-22-2022, 08:54 PM
(This post was last modified: 11-22-2022, 08:55 PM by bplus.)
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 + ...
Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
11-22-2022, 09:00 PM
(This post was last modified: 11-22-2022, 09:02 PM by Chris.)
## But is it more than 32 bits ?. I don't really understand what more than 32 bit accuracy means.
Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
I don't know how it happened: two topics
Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
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)
Posts: 2,698
Threads: 328
Joined: Apr 2022
Reputation:
218
Easiest fix for you would appear to be:
_DEFINE A-Z AS _FLOAT
Add to top of code and see if that helps.
Posts: 1,581
Threads: 59
Joined: Jul 2022
Reputation:
52
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.
Posts: 3,986
Threads: 178
Joined: Apr 2022
Reputation:
222
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 + ...