Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

@eval function, interesting results any explanation?

Jul
320
3
Playing with the @eval function just to see if there are any round up/down errors with the high precision. The results were interesting. In each case the answer, namely sin(pi/4)- 2**.5/2 =0. Damn close in many, spot on for others.

rem alias k=set s=%@eval[%$] & echo %@eval[%$]

k 2**.5/2-sin(pi/4)=e1
k 2**.5/2-sin(pi/4)=e2
k 2**.5/2-sin(pi/4)=e3
k 2**.5/2-sin(pi/4)=e4
k 2**.5/2-sin(pi/4)=e5
k 2**.5/2-sin(pi/4)=e6
k 2**.5/2-sin(pi/4)=e7
k 2**.5/2-sin(pi/4)=e8
k 2**.5/2-sin(pi/4)=e9
k 2**.5/2-sin(pi/4)=e10
k 2**.5/2-sin(pi/4)=e11
k 2**.5/2-sin(pi/4)=e12
k 2**.5/2-sin(pi/4)=e13
k 2**.5/2-sin(pi/4)=e14
k 2**.5/2-sin(pi/4)=e15
k 2**.5/2-sin(pi/4)=e16
k 2**.5/2-sin(pi/4)=e17
k 2**.5/2-sin(pi/4)=e18
k 2**.5/2-sin(pi/4)=e19
k 2**.5/2-sin(pi/4)=e20
k 2**.5/2-sin(pi/4)=e21
k 2**.5/2-sin(pi/4)=e22
k 2**.5/2-sin(pi/4)=e23
k 2**.5/2-sin(pi/4)=e24
k 2**.5/2-sin(pi/4)=e25
k 2**.5/2-sin(pi/4)=e26
k 2**.5/2-sin(pi/4)=e27
k 2**.5/2-sin(pi/4)=e28
k 2**.5/2-sin(pi/4)=e29
k 2**.5/2-sin(pi/4)=e30
k 2**.5/2-sin(pi/4)=e31
k 2**.5/2-sin(pi/4)=e32
k 2**.5/2-sin(pi/4)=e33
k 2**.5/2-sin(pi/4)=e34
k 2**.5/2-sin(pi/4)=e35
k 2**.5/2-sin(pi/4)=e36
k 2**.5/2-sin(pi/4)=e37
k 2**.5/2-sin(pi/4)=e38
k 2**.5/2-sin(pi/4)=e39
k 2**.5/2-sin(pi/4)=e40
k 2**.5/2-sin(pi/4)=e41
k 2**.5/2-sin(pi/4)=e42
k 2**.5/2-sin(pi/4)=e43
k 2**.5/2-sin(pi/4)=e44
k 2**.5/2-sin(pi/4)=e45
====================

the results

0.0E+0
5.00E-23
5.000E-24
5.0000E-25
-5.00000E-26
0.000000E+0
0.0000000E+0
0.00000000E+0
-5.000000000E-30
0.0000000000E+0
5.00000000000E-32
0.000000000000E+0
0.0000000000000E+0
5.00000000000000E-35
0.000000000000000E+0
5.0000000000000000E-37
0.00000000000000000E+0
-5.000000000000000000E-39
0.0000000000000000000E+0
5.00000000000000000000E-41
-5.000000000000000000000E-42
0.0000000000000000000000E+0
5.00000000000000000000000E-44
0.000000000000000000000000E+0
-5.0000000000000000000000000E-46
0.00000000000000000000000000E+0
0.000000000000000000000000000E+0
5.0000000000000000000000000000E-49
-5.00000000000000000000000000000E-50
5.000000000000000000000000000000E-51
0.0000000000000000000000000000000E+0
5.00000000000000000000000000000000E-53
-5.000000000000000000000000000000000E-54
-5.0000000000000000000000000000000000E-55
0.00000000000000000000000000000000000E+0
0.000000000000000000000000000000000000E+0
5.0000000000000000000000000000000000000E-58
5.00000000000000000000000000000000000000E-59
0.000000000000000000000000000000000000000E+0
0.0000000000000000000000000000000000000000E+0
-5.00000000000000000000000000000000000000000E-62
0.000000000000000000000000000000000000000000E+0
0.0000000000000000000000000000000000000000000E+0
0.00000000000000000000000000000000000000000000E+0
-5.000000000000000000000000000000000000000000000E-66
 
They're certainly accurate enough for me. Any speculation on what's happening below? Using sin() I get exactly 0 every time. With cos() I see behavior similar to what thorntonpg observed.

Code:
v:\> do i=46 to 50 ( echo %@eval[1/2-sin(pi/6)=E%i] )
0.0000000000000000000000000000000000000000000000E+0
0.00000000000000000000000000000000000000000000000E+0
0.000000000000000000000000000000000000000000000000E+0
0.0000000000000000000000000000000000000000000000000E+0
0.00000000000000000000000000000000000000000000000000E+0

v:\> do i=46 to 50 ( echo %@eval[1/2-cos(pi/3)=E%i] )
-1.0000000000000000000000000000000000000000000000E-66
0.00000000000000000000000000000000000000000000000E+0
-1.000000000000000000000000000000000000000000000000E-68
0.0000000000000000000000000000000000000000000000000E+0
-1.00000000000000000000000000000000000000000000000000E-70
 
A do loop is certainly a more elegant way of demonstrating this. I doubt whether real world application makes a great deal of difference, quantum physics perhaps. It is a curiosity though. I found a site with pi to 100,000 decimals. Was going to compare them to pi generated by tcc, first 20,000 anyway.
 

Similar threads

Back
Top