Category:Package elemfns

From CoCoAWiki
Jump to: navigation, search

Please note that this package is in beta status. This means, that function names may be subject to changes in future releases.

The package $apcocoa/elemfns (alias Fn) provides a fixed point software implementation of common elementary functions and constants with arbitrary accuracy and correct rounding in the following sense:

Let f be a mathematical function and F be its implementation, let N (the accuracy) be a positive integer and X be a rational number in the domain of f. Then

  • F(X) * 10^N is the closest integer to f(X) * 10^N
  • Ties are rounded away from zero.

In consequence, |F(X) - f(X)| <= 0.5*10^(-N).

The global accuracy N can be set with


and be queried with


For each implementation F(X) an alternative form FN(X, MyN) is provided, where the accuracy MyN can be directly set, as is illustrated by the following example.

 Dec(Fn.Sqrt(2), 50);
 Dec(Fn.SqrtN(2, 20), 50);

When the domain of the functions allows it, the size of the input is not limited:

 Dec(Fn.SinN(10^1000+42, 30), 30);

Because of the current fixed point approach, the performance of the computation suffers in situations, where high accuracy might not not be wanted:

 Time Dec(Fn.ExpN(2300, 30), 30);
 Cpu time = 8.04, User time = 8