Difference between revisions of "Category:ApCoCoA-1:Package elemfns"

From ApCoCoAWiki
Line 1: Line 1:
Please note that this package is in beta status. This means, that function names are still subject to changes in future releases.
+
Please note that this package is in beta status. This means, that function names may be subject to changes in future releases.
  
 
The package <code>$apcocoa/elemfns</code> (alias <code>Fn</code>) provides a fixed point software implementation of common elementary functions and constants with arbitrary accuracy and correct rounding in the following sense:
 
The package <code>$apcocoa/elemfns</code> (alias <code>Fn</code>) provides a fixed point software implementation of common elementary functions and constants with arbitrary accuracy and correct rounding in the following sense:

Revision as of 14:01, 4 May 2011

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

 Fn.SetAccuracy(N);

and be queried with

 Fn.GetAccuracy();


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.

 Fn.SetAccuracy(10);
 Fn.GetAccuracy();
 Dec(Fn.Sqrt(2), 50);
 Dec(Fn.SqrtN(2, 20), 50);
 
 10
 -------------------------------
 1.4142135624
 -------------------------------
 1.4142135623730950488
 


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

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


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);
 
 75389068[...]278.856265938734206057642793183088
 Cpu time = 8.04, User time = 8