%mathpiper,def="Trigonometry"

Defun("Trigonometry",{x,i,sum,term})
[
  Local(x2,orig,eps,previousPrec,newPrec);
  Bind(previousPrec,BuiltinPrecisionGet());
  Bind(newPrec,AddN(BuiltinPrecisionGet(),2));
  Bind(x2,MultiplyN(x,x));
  BuiltinPrecisionSet(newPrec);
  Bind(eps,MathIntPower(10,MathNegate(previousPrec)));
  While(IsGreaterThan(AbsN(term),eps))
  [
    Bind(term,MultiplyN(term,x2));
    Bind(i,AddN(i,1.0));
    Bind(term,DivideN(term,i));
    Bind(i,AddN(i,1.0));
    Bind(term,DivideN(MathNegate(term),i));
    BuiltinPrecisionSet(previousPrec);
    Bind(sum, AddN(sum, term));
    BuiltinPrecisionSet(newPrec);
  ];
  BuiltinPrecisionSet(previousPrec);
  sum;
];

%/mathpiper