I came across a method to check the mathematical precision of the math library. The c-stdlib should be the partner of comparison.
Requirement:
Produce Exponents of 10. Multiply them with Pi. Take the sinus of the result.
sin (Pi) = 0 (half a revolution), any integer multiples of Pi must be 0 again.
We'll see about this.
Here some code in Purebasic:
Code: Select all
EnableExplicit
Define.d dWinkel1, dWinkel2, dPi
Define.i iNummer, index
dPi = 3.1415926535897932384;626433832795028841971693993751058209749445
For index = 0 To 30
Debug Str(index) + " Index"
dWinkel1 = Pow(10, index)
Debug StrD(dWinkel1) + " Ergebnis"
dWinkel1 = dPi * dWinkel1
dWinkel2 = Sin( dWinkel1 )
Debug StrD(dWinkel2) + " Sinus"
Debug Chr(13)
Next
Code: Select all
#include <math.h>
#include <stdio.h>
int main() {
double dWinkel;
double dWinkel2;
double dIndex; //
const double dPi = 3.1415926535897932384626433832795028841971693993751058209749445;
int index;
for (index =0; index < 30; index++) {
dIndex = (double) index;
printf("%f. Index \n", dIndex);
dWinkel = pow (10.00000 , dIndex);
printf("%f. Ergebnis \n", dWinkel);
dWinkel = dPi * dWinkel;
dWinkel2 = sin( dWinkel );
printf("%f. Sinus \n", dWinkel2);
printf("\n");
}
return(0);
}
- Purebasic C
0 0.000000. Index
1 1.000000. Ergebnis
0 0.000000. Sinus
1 1.000000. Index
10 10.000000. Ergebnis
0 -0.000000. Sinus
2 2.000000. Index
100 100.000000. Ergebnis
0 0.000000. Sinus
3 3.000000. Index
1000 1000.000000. Ergebnis
0 -0.000000. Sinus
4 4.000000. Index
10000 10000.000000. Ergebnis
0 -0.000000. Sinus
5 5.000000. Index
100000 100000.000000. Ergebnis
0 -0.000000. Sinus
6 6.000000. Index
1000000 1000000.000000. Ergebnis
-0.0000000002 -0.000000. Sinus
7 7.000000. Index
10000000 10000000.000000. Ergebnis
0.0000000006 0.000000. Sinus
8 8.000000. Index
100000000 100000000.000000. Ergebnis
-0.0000000391 -0.000000. Sinus
9 9.000000. Index
1000000000 1000000000.000000. Ergebnis
-0.0000000332 -0.000000. Sinus
10 10.000000. Index
10000000000 10000000000.000000. Ergebnis
-0.0000022393 -0.000002. Sinus
11 11.000000. Index
100000000000 100000000000.000000. Ergebnis
-0.0000147638 -0.000015. Sinus
12 12.000000. Index
1000000000000 1000000000000.000000. Ergebnis
-0.0002697086 -0.000270. Sinus
13 13.000000. Index
10000000000000 10000000000000.000000. Ergebnis
-0.0026970827 -0.002697. Sinus
14 14.000000. Index
100000000000000 100000000000000.000000. Ergebnis
-0.0113456165 -0.011346. Sinus
15 15.000000. Index
1000000000000000 1000000000000000.000000. Ergebnis
-0.2362051232 -0.236209. Sinus
16 16.000000. Index
1E+016 10000000000000000.000000. Ergebnis
-0.3751753994 -0.375213. Sinus
17 17.000000. Index
1E+017 100000000000000000.000000. Ergebnis
-0.84818399 -0.847970. Sinus
18 18.000000. Index
1E+018 1000000000000000000.000000. Ergebnis
-0.6447503601 -0.641653. Sinus
19 19.000000. Index
1E+019 10000000000000000000.000000. Ergebnis
3,14159265358979E+019 0.746337. Sinus
20 20.000000. Index
1E+020 100000000000000000000.000000. Ergebnis
3,14159265358979E+020 -0.394071. Sinus
21 21.000000. Index
1E+021 1000000000000000000000.000000. Ergebnis
3,14159265358979E+021 -0.580805. Sinus
22 22.000000. Index
1E+022 10000000000000000000000.000000. Ergebnis
3,14159265358979E+022 -0.688675. Sinus
23 23.000000. Index
1E+023 99999999999999991611392.000000. Ergebnis
3,14159265358979E+023 -0.796516. Sinus
24 24.000000. Index
1E+024 999999999999999983222784.000000. Ergebnis
3,14159265358979E+024 0.930141. Sinus
25 25.000000. Index
1E+025 10000000000000000905969664.000000. Ergebnis
3,14159265358979E+025 0.994809. Sinus
26 26.000000. Index
1E+026 100000000000000004764729344.000000. Ergebnis
3,14159265358979E+026 0.957898. Sinus
27 27.000000. Index
1E+027 1000000000000000013287555072.000000. Ergebnis
3,14159265358979E+027 0.789794. Sinus
28 28.000000. Index
1E+028 9999999999999999583119736832.000000. Ergebnis
3,14159265358979E+028 -0.492936. Sinus
29 29.000000. Index
1E+029 99999999999999991433150857216.000000. Ergebnis
3,14159265358979E+029 -0.999143. Sinus
30 30.000000. Index
1E+030 1000000000000000019884624838656.000000. Ergebnis
3,14159265358979E+030 0.872051. Sinus
StrD works fine as very precise output.
With 1E16 the difference appears without rounding.
With 1E19 Purebasics sinus-function quits while C can provide an output near 0.
Anyone trying to work with Purebasic in high-number science? Do we need a better library?
A discussion might help...
Nice evening
LN