# Welcome!

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

# @eval function, interesting results any explanation?

#### thorntonpg

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

What's happening is that sin and pi (as acos(-1)) are being computed to a different precision each time. (The precision is applied during computation, not as a truncation afterwards.)

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.

Replies
4
Views
280
Replies
8
Views
1K
Replies
10
Views
2K
Replies
9
Views
2K
Replies
7
Views
3K
Replies
14
Views
3K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
6
Views
2K
Replies
7
Views
3K
Replies
7
Views
3K
Replies
3
Views
5K
Documentation @IF Function
Replies
3
Views
240
Replies
8
Views
363
Replies
0
Views
130
Replies
4
Views
259
Replies
7
Views
355
Replies
6
Views
265
Replies
6
Views
608
Replies
11
Views
718
Replies
6
Views
668
Documentation Function parameters
Replies
0
Views
487
Replies
0
Views
524
Replies
4
Views
989
Replies
3
Views
919
Replies
8
Views
1K
Replies
6
Views
1K
Replies
10
Views
2K
Replies
5
Views
2K
Replies
3
Views
1K
Replies
3
Views
1K
Replies
3
Views
2K
Replies
17
Views
3K
Replies
0
Views
1K
Replies
10
Views
2K
Documentation @CAPI function summary
Replies
0
Views
998
Replies
3
Views
2K
Replies
10
Views
3K
Replies
8
Views
2K
Replies
5
Views
2K
Replies
13
Views
3K
Replies
2
Views
2K
Replies
10
Views
3K
Replies
2
Views
1K
Replies
5
Views
2K
Replies
15
Views
3K
Replies
13
Views
3K
Replies
1
Views
1K