Name:

rationalapprox returns a fraction close to a given number.

Library name:

sollya_obj_t sollya_lib_rationalapprox(sollya_obj_t, sollya_obj_t)

Usage:

rationalapprox(x,n) : (constant, integer) -> function

Parameters:

Description:

Example 1:

   > pi10 = rationalapprox(Pi,10);
   > pi50 = rationalapprox(Pi,50);
   > pi100 = rationalapprox(Pi,100);
   > print( pi10, ": ", simplify(floor(-log2(abs(pi10-Pi)/Pi))), "bits." );
   3.140625 :  11 bits.
   > print( pi50, ": ", simplify(floor(-log2(abs(pi50-Pi)/Pi))), "bits." );
   85563208 / 27235615 :  51 bits.
   > print( pi100, ": ", simplify(floor(-log2(abs(pi100-Pi)/Pi))), "bits." );
   4422001152019829 / 1407566683404023 :  100 bits.

Example 2:

   > a=0.1;
   > b=rationalapprox(a,4);
   > numerator(b); denominator(b);
   1
   10
   > print(simplify(floor(-log2(abs((b-a)/a)))), "bits.");
   166 bits.
See also: print, numerator, denominator, rationalmode
Go back to the list of commands