APL(NARS), 100109 chars
r←a F w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-2=↑a
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2
6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕
15+42+28+2+13=10015+42+28+2+22=109
the last line call the function F that is a sin and cos function depend of first input on the left (inputit is ≠2 is sin input =2 is cos). Some test:
6⍕¨(⊂1 2)⎕ F⎕
⎕:
⍪{6⍕⍵a[2]F 31⊃a}¨⍳2⊣a←⎕
⎕:
5 3
10.208333
14.541667
6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕
⎕:
12 8.555
⎕:13
0.765431 6.54
0.253986 0¯0.967147641092
6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕
⎕:
13
⎕:
9.26 10
8¯3.555154677
0.765431 ¯0¯8.641092404354
OT it would be possible to calculate the exactexact answer using rationals and input rational for example of 1r4 (0.25=1/4)
⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
1r4 10
0.247404
0.968912
{⍵○1r4}¨⍳2
0.2474039593 0.9689124217
{⍵○0.25}¨⍳2
0.2474039593 0.9689124217
1 10 F 1r4
8264318085745811128158727r33404146443928530321408000
2 10 F 1r4
17051609536099989115458551r17598710837038136237752320
thisthese last number2 numbers both cut, it would be the decimaldecimals 0.247403959254522929592474039592 and 0.9689124217