[Question]
  [
The [Dottie number](http://mathworld.wolfram.com/DottieNumber.html) is the fixed point of the cosine function, or the solution to the equation **cos(x)=x**.1
Your task will be to make code that approximates this constant. Your code should represent a function that takes an integer as input and outputs a real number. The limit of your function as the input grows should be the Dottie number.
You may output as a fraction, a decimal, or an algebraic representation of a number. Your output should be capable of being arbitrarily precise, floats and doubles are not sufficient for this challenge. If your language is not capable of arbitrary precision numbers, then you must either implement them or choose a new language.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") question so answers will be scored in bytes, with fewer bytes being better.
### Tips
One way of calculating the constant is to take any number and repeatedly apply the cosine to it. As the number of applications tends towards infinity the result tends towards the fixed point of cosine.
Here is a fairly accurate approximation of the number.
```
0.739085133215161
```
1: Here we will take cosine in radians
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~34~~ ~~30~~ 19 bytes
*11 bytes off thanks to [Sanchises](https://codegolf.stackexchange.com/users/32352/sanchises)!*
```
48i:"'cos('wh41hGY$
```
The last decimal figures in the output may be off. However, the number of correct figures starting from the left increases with the input, and the result converges to the actual constant.
[**Try it online!**](https://tio.run/##y00syfn/38Qi00pJPTm/WEO9PMPEMMM9UuX/fyMDAwA)
### Explanation
For input *n*, and starting at *x*=1, this applies the function
              *x* ↦ cos(*x*)
with *n*-digit [variable-precision arithmetic](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic) *n* times.
```
48         % Push 48, which is ASCII for '1': initial value for x as a string
i:"        % Do n times, where n is the input
  'cos('   %   Push this string
  w        %   Swap. Moves current string x onto the top of the stack
  h        %   Concatenate
  41       %   Push 41, which is ASCII for ')'
  h        %   Concatenate. This gives the string 'cos(x)', where x is the
           %   current number
  GY$      %   Evaluate with variable-prevision arithmetic using n digits
           %   The result is a string, which represents the new x
           % End (implicit). Display (implicit). The stack contains the last x
```
[Answer]
# [dzaima/APL](https://github.com/dzaima/APL), 55 bytes
```
⎕←⊃{⍵,⍨-/P,((P÷⍨×)/¨(2×⍳N)⍴¨⊃⍵)÷!2L×⍳N}⍣{⍵≢∪⍵}P←10L*N←⎕
```
Using big integer (no big decimals!) arithmetic (where \$10^N\$ is the equivalent of a `1`), iterate the first \$N\$ terms of the Taylor series (an overestimate, but that's fine) until a duplicate has been encountered. May be off by a bit due to lost precision in the end, but, as with other answers, those differences will disappear with higher \$N\$.
 No TIO link as TIO's dzaima/APL hasn't been updated to support bigintegers.
Example I/O:
```
1
9L
10
7390851332L
100
7390851332151606416553120876738734040134117589007574649656806357732846548835475945993761069317665318L
200
73908513321516064165531208767387340401341175890075746496568063577328465488354759459937610693176653184980124664398716302771490369130842031578044057462077868852490389153928943884509523480133563127677224L
```
[Answer]
# [Python 3](https://docs.python.org/3/), 58 bytes
```
lambda n:S('cos('*n+'0'+')'*n).evalf(n)
from sympy import*
```
[Try it online!](https://tio.run/##FcsxDoMwDADAGV7hzTZIVVA3pL6CtUtoSYlE7MhElfL6tGy3XK5lV7m3AA94tsOn9e1B5oXwpSfhICM6HJH/4tv29Ucg4T6YJjhryhViymplaEENBKKAeflsNDnHc99li1LoOtx@ "Python 3 – Try It Online")
[Answer]
# GNU bc -l, 30
Score includes +1 for `-l` flag to `bc`.
```
for(a=1;a/A-b/A;b=c(a))a=b
a
```
The final newline is significant and necessary.
[Try it online](https://tio.run/##S0r@/z8tv0gj0dbQOlHfUTdJ39E6yTZZI1FTM9E2iSuR6////7o5AA).
`-l` does 2 things:
* enable the "math" library, including `c()` for cos(x)
* sets precision (scale) to 20 decimal places (`bc` has arbitrary precision calculation)
I'm not really clear on the precision requirement. As it is, this program calculates to 20 decimal places. If a different precision is required, then `scale=n;` needs to be inserted at the start of the program, where `n` is the number of decimal places. I don't know if I should add this to my score or not.
Note also that for some numbers of decimal places (e.g. 21, but not 20), the calculation oscillates either side of the solution in the last digit. Thus in the comparison of current and previous iterations, I divide both sides by 10 (`A`) to erase the last digit.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 19 bytes
```
Nest[Cos,0,9#]~N~#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773y@1uCTaOb9Yx0DHUjm2zq9OWe1/QFFmXomCQ3q0oYFB7P//AA "Wolfram Language (Mathematica) – Try It Online")
-3 bytes from @alephalpha
[Answer]
# [R](https://www.r-project.org/) (+Rmpfr), 55 bytes
```
function(n,b=Rmpfr::mpfr(1,n)){for(i in 1:n)b=cos(b);b}
```
Dennis has now added Rmpfr to TIO so this will work; added some test cases.
### Explanation:
Takes the code I wrote from [this challenge](https://codegolf.stackexchange.com/questions/137527/calculate-the-n-th-iterate-of-a-polynomial-for-a-specific-value-f%E2%81%BFx) to evaluate `cos` `n` times starting at `1`, but first I specify the precision I want the values to be in by creating an object `b` of class `mpfr` with value `1` and precision `n`, `n>=2`, so we get more precision as we go along.
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPJ8k2KLcgrcjKCkRqGOrkaWpWp@UXaWQqZOYpGFrlaSbZJucXayRpWifV/i9OLCjIqdQwNIjTMLAy0dQ21EnT/A8A)
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 42 bytes
```
@(n)digits(n)*0+vpasolve(sym('cos(x)-x'));
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI08zJTM9s6QYyNAy0C4rSCzOzylL1SiuzNVQT84v1qjQ1K1Q19S0/p@mYWSo@R8A "Octave – Try It Online")
Pretty much a duplicate of [my answer to Approximate the Plastic Number](https://codegolf.stackexchange.com/questions/126820/approximate-the-plastic-number), but somewhat shorter due to more relaxed requirements.
[Answer]
# [Mathics](http://mathics.github.io/) or Mathematica, 46 bytes
```
{$MaxPrecision=#}~Block~Cos~FixedPoint~N[1,#]&
```
[Try it online!](https://tio.run/##y00sychMLv7/v1rFN7EioCg1ObM4Mz/PVrm2ziknPzm7zjm/uM4tsyI1JSA/M6@kzi/aUEc5Vu1/QBGQF60abWhgEBv7HwA "Mathics – Try It Online")
[Answer]
# [PHP](https://php.net/), 50 bytes
```
$a=$argv[1];$i=$j=0;while($i<$a){$j=cos($j);$i++;}
```
[Try it online!](https://tio.run/##K8go@G9jXwAkVRJtVRKL0suiDWOtVTJtVbJsDazLMzJzUjVUMm1UEjWrgSLJ@cUaKlmaQHltbeva/6nJGfkqWdb2dv//GxoAAQA "PHP – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 57 54 bytes
```
u_.tG1lX$globals()$"neg"$__import__("decimal").Decimal
```
This would be much shorter if we didn't need the Decimal to be up to spec, but it is what it is.
Edit 1: -3 bytes because we need a number anyways, so we can use `X`s returned copy of `globals()` length as our starting value, moving it to the end and removing a `$` and some whitespace.
[Try it online!](https://tio.run/##K6gsyfj/vzRer8TdMCdCJT0nPykxp1hDU0UpLzVdSSU@PjO3IL@oJD5eQyklNTkzNzFHSVPPBcL6//9ffkFJZn5e8X/dFAA "Pyth – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 84 bytes
```
n=>"0."+(F=(J,Z=c=0n)=>J?F(J*-I*I/++c/++c/B/B,Z+J):I-Z>>2n?(I=Z,F(B)):I)(B=I=10n**n)
```
[Try it online!](https://tio.run/##Hcw9CsMwDEDhu2SS/JO4hS4FOeDBIB/BW3CT0hLk0oRc3w0d3vIN7z0d01a@r89upT7mtlAT8p3rOw2RIJlMhZwg@TRGSMqy4kHr8i8MwWSd8M42e3@VEZiyiRDwJIRATBcnSgm2UmWr69yv9QkL3M4jth8 "JavaScript (Node.js) – Try It Online")
Has a precision of roughly `n-1` digits. BigInt is used and `cos(x)` is calculated using its Taylor expansion. The `I-Z>>2n` part is used only to prevent looping forever (with a cost of 4 bytes and some precision). Although theoretical applicable for arbitrary precision, practical range is `n<63` because of stack overflow.
### Shorter (82 bytes), no worries about stack overflow, but far fewer precision
```
n=>"0."+eval("for(I=B=10n**n;n--;I=Z)for(Z=J=B,c=0n;J;)Z+=(J=J*-I*I/++c/++c/B/B)")
```
### Much shorter (80 bytes), larger range until stack overflow (`n<172`), but same precision as the 82-byte.
```
n=>"0."+(F=(J,Z=c=0n)=>J?F(J*-I*I/++c/++c/B/B,Z+J):n--?(I=Z,F(B)):I)(B=I=10n**n)
```
### If arbitrary precision is not the main point, then 25 bytes:
```
F=n=>n?Math.cos(F(n-1)):1
```
[Answer]
# [Factor](https://factorcode.org/) + `math.polynomials math.factorials`, 66 bytes
```
[| x | 1 x [ sq neg x [0,b) [ 2 * n! recip ] map polyval ] times ]
```
[Try it online!](https://tio.run/##NY0xC8IwFIT3/opzVEqx4qTgKi4u4lQ6pPG1BtMkTVKx0P8ek6LL8e7j3l3LuNc23G@X6/mAF1lFElJzJh165p@LFO2SEn9YGC0npfsEsgVYpjpyMJa8n4wVysPRMJLikR6zPaoyb@pQzfhgRhm1ghugqEvnNm/WEeywgVrBEhcGdVwySENvJqPzoo9VdUj0MRoU8eHUSs38L1qELw "Factor – Try It Online")
Factor has rational numbers, but no arbitrary-precision decimals. This answer tries to exploit it as much as possible: iterate the evaluation of the fist `n` terms of Taylor series (more precisely, Maclaurin series) `n` times, with the starting value of 1. The output is given as a rational number; the floating-point representation is also shown on TIO to check the value in human-readable form.
The function is very slow to calculate and very slow to converge, but in theory it must converge to the Dottie number as `n` increases, since the iterated function approaches the cosine function, the iteration count increases to infinity, and the whole computation is done in rationals (and therefore exact).
### How it works
Given a positive integer \$n\$, the code approximates the Dottie number as follows:
$$
\cos{x} = \sum\_{i=0}^{\infty}{\frac{(-1)^i}{(2i)!}x^{2i}}
\approx \sum\_{i=0}^{n-1}{\frac{(-x^2)^i}{(2i)!}} \\
\text{Dottie number } = \cos{x} \text{ iterated } \infty \text{ times on } 1 \\
\approx \sum\_{i=0}^{n-1}{\frac{(-x^2)^i}{(2i)!}} \text{ iterated } n \text{ times on } 1
$$
```
[| x |  ! an anonymous function that takes one arg `x` as a local variable
  1 x [ ... ] times  ! repeat the inner function x times on the value 1...
    sq neg           !   val -> -val^2
    x [0,b)          !   0..x-1
    [ 2 * n! recip ] map  ! convert each number `i` to 1/(2i)!
    polyval          !   evaluate the array as polynomial at the value of -val^2
]
```
[Answer]
# [Julia 1.0](http://julialang.org/), 42 bytes
```
!n=big(n<2||setprecision(()->cos(!~-n),n))
```
[Try it online!](https://tio.run/##DcFNCoAgEAbQfafQ3QwUaMuo7tKPxYR8iha0iK5uvXdcXiZ7l6IxzLIT@vZ5sjtjcotkCSDiZlxCJv024BrMZQtJiRIo21ljTKV@MQlOD9LClcNaPg "Julia 1.0 – Try It Online")
sets the precision of `BigFloat`s to `n` bits and computes \$cos^{n-1}(1)\$ recursively
[Answer]
# Perl 5, 41 Bytes
```
use bignum;sub f{$_[0]?cos(f($_[0]-1)):0}
```
Bignum is required for the arbitrary precision. Defines a function f that recursively applies cosine to 0 N times.
TIO doesn't seem to have bignum so no link :(
[Answer]
## Mathematica 44 Bytes
```
FindRoot[Cos@x-x,{x,0},WorkingPrecision->#]&
```
`FindRoot` uses Newton's method by default.
[Answer]
# Axiom, 174 bytes
```
f(n:PI):Complex Float==(n>10^4=>%i;m:=digits(n+10);e:=10^(-n-7);a:=0;repeat(b:=a+(cos(a)-a)/(sin(a)+1.);if a~=0 and a-b<e then break;a:=b);a:=floor(b*10^n)/10.^n;digits(m);a)
```
ungolfed and commented
```
-- Input: n:PI numero di cifre
-- Output la soluzione x a cos(x)=x con n cifre significative dopo la virgola
-- Usa il metodo di Newton a_0:=a  a_(n+1)=a_n-f(a_n)/f'(a_n)
fo(n:PI):Complex Float==
  n>10^4=>%i
  m:=digits(n+10)
  e:=10^(-n-7)
  a:=0     -- Punto iniziale
  repeat
     b:=a+(cos(a)-a)/(sin(a)+1.)
     if a~=0 and a-b<e then break
     a:=b
  a:=floor(b*10^n)/10.^n
  digits(m)
  a
```
results:
```
(3) -> for i in 1..10 repeat output[i,f(i)]
   [1.0,0.7]
   [2.0,0.73]
   [3.0,0.739]
   [4.0,0.739]
   [5.0,0.73908]
   [6.0,0.739085]
   [7.0,0.7390851]
   [8.0,0.73908513]
   [9.0,0.739085133]
   [10.0,0.7390851332]
                                                               Type: Void
           Time: 0.12 (IN) + 0.10 (EV) + 0.12 (OT) + 0.02 (GC) = 0.35 sec
(4) -> f 300
   (4)
  0.7390851332 1516064165 5312087673 8734040134 1175890075 7464965680 635773284
  6 5488354759 4599376106 9317665318 4980124664 3987163027 7149036913 084203157
  8 0440574620 7786885249 0389153928 9438845095 2348013356 3127677223 158095635
  3 7765724512 0437341993 6433512538 4097800343 4064670047 9402143478 080271801
  8 8377113613 8204206631
                                                      Type: Complex Float
                                   Time: 0.03 (IN) + 0.07 (OT) = 0.10 sec
```
I would use the Newton method because it would be faster
than 'repeated cos(x) method'
```
 800   92x
1000  153x
2000  379x
```
where in the first column there is the number of digit
and in the second column there is how much Newton method
is faster than use repeated cos(x) method, here.
Good Morning
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), 35 bytes
```
1.."$args"|%{$x=[Math]::Cos($x)}
$x
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNydFNzi9K/a@SZlv931BPT0klsSi9WKlGtVqlwjbaN7EkI9bKyjm/WEOlQrOWS6Xify0Xl5pKmoKhgYHBfwA "PowerShell Core – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/tree/version-2), 6 bytes
```
(∆c)$Ḟ
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyJBIiwiIiwiKOKIhmMpJOG4niIsIiIsIjVcbjEwXG4yMFxuNTBcbjEwMCJd)
Uses sympy's arbitrary-precision cosine function. Since decimals are outputted to a fixed precision (although stored as arbitrary-precision) it has to be taken to n decimal places.
```
(  )   # n times
 ∆c    # cosine
    $Ḟ # result to n decimal places
```
[Answer]
# [Maxima](http://maxima.sourceforge.net/), 93 bytes
A port of [@MarcMush's Julia 1.0 answer](https://codegolf.stackexchange.com/a/238273/110802) in Maxima.
93 bytes, it can be golfed much more.
---
Golfed version. [Try it online!](https://tio.run/##NY69DoMwDIT3PIVHgqiAjmm79QG6Vx0gJMIq2CgJ/Xn6NBHFy8mf7k43dx@cu1iXcDUWyUAYDTijV@fxZcCupAMywRvDCMOXuhk1LMmAPuOyFrEvSKpLP7F@Fnd@VKzskh3VJooqp9ACnY@5nKC3E3chhczkzf5p9kUqOrRSyj3IlZPxJEQad3NI4b/Nr1PwYB3P0EJgaJumyUMsO0CV0OjWDQ4MhYB0S46nfpRSyFP8AQ)
```
b(n):=block([o],o:fpprec,fpprec:n,r:if n<2 then bfloat(n)else bfloat(cos(b(n-1))),fpprec:o,r)
```
Ungolfed version. [Try it online!](https://tio.run/##fZHBTsQgEIbvfYo5lo1mW49Vbz6A0ePGGEqHlEihGWB3ffrKtLa7GxO5EIb/G/5/GOTZDHLa7@AFtXEIsUcgVImCOSLo5FQ03sHJxB66bycHo2DMAhO4vNsXbekENM/QWq@@ygLyOnjbfbLo424@5@7v8rj0zle3PAtWfQN65P2CYZypC0FoZWRr0cPGL1QDbgNfkbSnYYaVtCoxtebgosPTXx@EIdnYgNG59xM8sNJBq62XkWOiDbgelQ9lzn5fCyG2Z98wRE//JF2dromvyJjI/Y6fXdx6KsRjUXAuMi5eqQJo8gPUPI66qiqmcnAwTS71lJZi52H5mZHxbNsIkTtO0/QD)
```
/* Define the recursive function with dynamic precision */
b(n) := block(
    [old_prec],
    /* Save the old precision */
    old_prec: fpprec,
    /* Set the precision relative to n */
    fpprec: n,
    /* Perform the calculation with the new precision */
    result: if n < 2 then bfloat(n) else bfloat(cos(b(n-1))),
    /* Restore the old precision */
    fpprec: old_prec,
    /* Return the result */
    result
);
/* Print the results from 1 to 1000 */
for i:1 thru 1000 do (
    print(b(i))
);
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 47 bytes
```
f(n)=if(n,subst(Pol(cos(x+O(x^n))),x,f(n-1)),1)
```
[Try it online!](https://tio.run/##K0gsytRNL/j/P00jT9M2E0jqFJcmFZdoBOTnaCTnF2tUaPtrVMTlaWpq6lToAKV1DYEsQ83/aflFGnkKtgoGOgpmOgoFRZl5JUC@koKuHZAAGaap@R8A "Pari/GP – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 267 bytes
```
f d=(iterate(\(b,e)->r(\(x,y)(z,w)->(x*10^(2*d-y)+z*10^(2*d-w),2*d))(0,0)$takeWhile((/=0).fst)[r(\(x,y)(z,w)->(x*z,y+w))((-1)^n,0)[let z=2*e*n;s=max(z-d)0in(b^(2*n)`div`10^s,z-s),(10^d`div`product[2..2*n],d)]|n<-[0..]])(7,1))#[];(h:t)#v|h`elem`v=h|0<1=t#(h:v);r=foldr
```
[Try it online!](https://tio.run/##ZU/BboMwDP2VqOxgQ8gCl0prwxfstsMOjAq6BAWVhiqk0KL@O3N32GUXv/dsPz/ZNuPJ9P26tkwr6ILxTTDwBUduMC08sRu/Iyx8Jgm3OJMHyGOd3jFZ/sSMnAARJJf4EpqT@bRdbwBelUTRjgHL/5cWfk9m8kCa4cGRsexNYIvKYxO73ajOzQ2WVKPsHByfOQ5r3U01hY58SUfkQFT/9i5@0NfvUOZC0F7FNVYPt09LKURVIWx5hhiV1Q7sW8Boetja9OZcT8o@5D5TIaLBhDuv2qHXfj03nWOKedPod8eKQrHLNXwET0Iw2EixSRIkOtphJqAHn3Xdyh8 "Haskell – Try It Online")
[Answer]
# [Go](https://go.dev), 71 bytes
```
import."math"
func f(n int)(k float64){for;n>=0;n--{k=Cos(k)}
return k}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY5NCoMwFIT3OcUjq0SqSCmlVOymi25LbxCKsY_oi8TnSjxJN1LoobxNtX-rgRnmm7k_Sj9OUWOuzpQF1AZJYN34wIlsOSCVrfwbtmb57NjGu-n082rDNylsR1ewigCJtXJgK294u9G99SGjQ55mFMe9y4--VU4PIhTcBQI3_HBvwLKuNPRibgHCPodgaH51KZrCsJKJXK3TJccoR3Ge33FFClfzMmotBvHFjeNHXw)
Input is the number of times to apply `cos`. Limited to 64-bit floating point precision.
[Answer]
# [J-uby](https://github.com/cyoce/J-uby), 33 bytes
Takes the desired precision as an argument.
```
~:!~%(:& &~(:cos&BigMath))&0.to_d
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700K740qfKmVbSSblFSZnpKanJmbmKOko4CCl8_N7EkA0OwtCQzRyl2kZvt0tKSNF2Lm4p1Vop1qhpWagpqdRpWyfnFak6Z6b5AnZqaagZ6JfnxKRCFywoU3KItYiGcBQsgNAA)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
õ Ôr@McX
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=9SDUckBNY1g&input=NTAw)
```
õ Ôr@McX     :Implicit input of integer U
õ            :Range [1,U]
  Ô          :Reverse
   r         :Reduce by
    @        :Passing the current value X (initially the first element) through the following function
     McX     :  Cosine of X
```
[Answer]
# APL(NARS), 219 chars
```
R←{⍵=0:⍵⋄10≥m←(⍺-⍨⌊10⍟d←∣1∧÷⍵×1x)⌊⍺-⍨⌊10⍟n←∣1∧⍵×1x:⍵⋄(×⍵)×(⌊n÷q)÷⌊d÷q←{(10∘×⍣⍵)1x}m-5}
r←p C w;d;e;v;m
r←d←1⋄e←1÷10x*p⋄v←¯1,0⋄m←w×w×¯1
r+←d×←m÷×/v+←2⋄→2×⍳e<∣d⋄r←p R r
r←D w;e;v
e←1÷10x*w⋄v←1x
r←w C v⋄→0×⍳e>∣v-r⋄v←r⋄→2
```
C is the cos function, has as parameters p the precision (or the number of digits afther the decimal point)
and w the rational number (here represented using r as in 23r4 for 23/4) and return a rational. If the argument
of that function is a int or a float, it return one float. For 3 significative digits we have
```
      3 C 1
0.5403028025 
      3 C 1x
4357r8064 
      2○1
0.5403023059
```
D is the function that would return the number in question that has argument the digit of precision.
How appear one fractional result?
```
      D 3
117407r158925 
```
So there is need one function that traslate the fractional result in a decimal string we can read
r2fs: input ⍺ the precision ⍵ one rational number
```
r2fs←{⎕ct←0⋄k←≢b←⍕⌊⍵×10x*a←⍺⋄k-←s←'¯'=↑b⋄c←{s:'¯'⋄''}⋄m←s↓b⋄0≥k-⍺:c,'0.',((⍺-k)⍴'0'),m⋄c,((k-⍺)↑m),'.',(k-⍺)↓m}  
```
One has to note as ⎕ct is a local varible in r2fs and its value in use out of that function is different.
So all could be more clear
```
      8 r2fs¨ D¨ 1 2 3 4 5 6 7 8
 0.70224186 0.73556389 0.73875727 0.73905483 0.73908230 0.73908552 0.73908517 0.73908513 
      19 r2fs D 20 
0.7390851332151606416
      40 r2fs D 39
0.7390851332151606416553120876738734040131
      39 r2fs D 40
0.739085133215160641655312087673873404013
```
For the C function sometime the result is not ok for float input
```
     10 C 45
55.65114514
      2○45
0.5253219888
      10 C 45
55.65114514
      2○45
0.5253219888
```
but the fraction input it seems converge right for cos
```
      49 r2fs 50 C 45x
0.5253219888177296960474644048235629188973106884573
```
One other problem one has to solve here it seems to me that the function D can converge to that number but its fraction in r
is so big that consume all resources so have to be cut in some way... I would say one could reduce the size of the fraction in memory
cuting the final parts of the numerator and denomicator (save all the digits of both until precision number),
something as function R make (for me R has to be used inside the cos).
]