Off[General::spell1];
Clear[Diff,f0,x0, M];
Diff[f0_,x0_,M_] := 
Module[{f,j,a,b,diff,ratio },
  Set@@{f[x_],f0};
  h=1;
  For[j=1,j<=M,j++,
    a = SetAccuracy[f[x0],digit];
    b = SetAccuracy[f[x0+h],digit]; 
    diff = SetAccuracy[b-a, digit];
    ratio = diff /h;
    Print[" "];
    Print["n = ", j,  "\t     h =", h];
    Print["f'[",x0,"] ~ ",N[ratio,8] ];  
    h = N[h/2,digit];  ];
 ];
On[General::spell1];

Clear[digit];   
digit=10;

Clear[f];
f[x_] = ArcTan[x];

Diff[f[x],Sqrt[2],20]

Off[General::spell1]; 
Clear[SymDiff,f0,x0, M];
SymDiff[f0_,x0_,M_] :=
Module[{f,j ,a,b,diff,ratio},
  Set@@{f[x_],f0};
  h=1;
  For[j=1,j<=M,j++,
    a = SetAccuracy[f[x0+h],digit];
    b = SetAccuracy[f[x0-h],digit];
    diff = SetAccuracy[b-a, digit];
    ratio = 0.5 * diff /h;
    Print[" "];
    Print["n = ", j,  "\t     h =", h];
    Print["f'[",x0,"] ~ ",N[ratio,8] ];  
    h = SetAccuracy[h/2,digit];  ];
 ];
On[General::spell1];

SymDiff[f[x],Sqrt[2],15]

Off[General::spell1]; 
Clear[SecondDiff,f0,x0, M];
SecondDiff[f0_,x0_,M_] :=
Module[{f,j ,a,b,c,diff,ratio}, 
  Set@@{f[x_],f0};
  h=1;
  For[j=1,j<=M,j++,
    a = SetAccuracy[f[x0+h],digit];
    b = SetAccuracy[f[x0-h],digit];
    c = SetAccuracy[f[x0],digit];
    diff = SetAccuracy[a+b-2c, digit];
    ratio = diff /h^2;
    Print[" "];
    Print["n = ", j,  "\t     h =", h];
    Print["f''[",x0,"] ~ ",N[ratio,16] ];  
    h = SetAccuracy[h/2,digit];  ];
 ];
On[General::spell1];

Clear[digit]; 
digit=16;

Clear[f];
f[x_] = ArcTan[x];

SecondDiff[f[x],Sqrt[2],14]

f''[Sqrt[2]]

N[%,16]

SecondDiff[f[x],Sqrt[2],28]

Off[General::spell1]; 
Clear[FirstDiff,f0,x0, M,tau];
FirstDer[f0_,x0_,M_,tau_] :=
Module[{f,j ,a,b,diff,ratio, Cond},
  Set@@{f[x_],f0};
  h=1; k =0;
  Cond = 0; old=0;
  While[Cond ==0 && k <=M,
    a = SetAccuracy[f[x0+h],digit];
    b = SetAccuracy[f[x0-h],digit];
    diff = SetAccuracy[b-a, digit];
    ratio = 0.5 * diff /h;
  Print["k =", k, "\t     
      f''[",x0,"] ~ ",N[ratio,16]];
  If[Abs[ratio - old] <= tau, Cond=1];
   h = SetAccuracy[h/2,digit];  
   old = ratio; 
   k = k +1 ]; ];
On[General::spell1];

Clear[digit]; 
digit=16;

Clear[f];
f[x_] = ArcTan[x];

FirstDer[f[x],Sqrt[2], 20, 10^(-10)]

Off[General::spell1]; 
Clear[SecondDer,f0,x0, M,tau];
SecondDer[f0_,x0_, M_,tau_] :=
Module[{f,j ,a,b,c,diff,ratio,Cond}, 
  Set@@{f[x_],f0};
  h=1; k=0;
  Cond = 0; old=0;
While[Cond == 0 && k <=M,
     a = SetAccuracy[f[x0+h],digit];
     b = SetAccuracy[f[x0-h],digit];
     c = SetAccuracy[f[x0],digit];
     diff = SetAccuracy[a+b-2c, digit];
     ratio = diff /h^2;
   Print["k =", k, "\t   
      f''[",x0,"] ~    ",N[ratio,16]];
   If[Abs[ratio - old] <= tau, Cond=1];
   h = SetAccuracy[h/2,digit];  
   old = ratio; 
     k = k +1 ]; ];
On[General::spell1];

Clear[digit]; 
digit=16;

Clear[f];
f[x_] = ArcTan[x];

SecondDer[f[x],Sqrt[2], 20, 10^(-10)]