mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.10.2t30
This commit is contained in:
89
help/cfappr
Normal file
89
help/cfappr
Normal file
@@ -0,0 +1,89 @@
|
||||
NAME
|
||||
cfappr - approximate a real number using continued fractions
|
||||
|
||||
SYNOPSIS
|
||||
cfappr(x [,eps [,rnd]]) or cfappr(x, n [,rnd])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps real with abs(eps) < 1, defaults to epsilon()
|
||||
n real with n >= 1
|
||||
rnd integer, defaults to config("cfappr")
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
If x is an integer or eps is zero, either form returns x.
|
||||
|
||||
If abs(eps) < 1, cfappr(x, eps) returns the smallest-denominator
|
||||
number in one of the three intervals, [x, x + abs(eps)],
|
||||
[x - abs(eps], x], [x - abs(eps)/2, x + abs(eps)/2].
|
||||
|
||||
If n >= 1 and den(x) > n, cfappr(x, n) returns the nearest above,
|
||||
nearest below, or nearest, approximation to x with denominator less
|
||||
than or equal to n. If den(x) <= n, cfappr(x,n) returns x.
|
||||
|
||||
In either case when the result v is not x, how v relates to x is
|
||||
determined by bits 0, 1, 2 and 4 of the argument rnd in the same way as
|
||||
these bits are used in the functions round() and appr(). In the
|
||||
following y is either eps or n.
|
||||
|
||||
rnd sign of remainder x - v
|
||||
|
||||
0 sgn(y)
|
||||
1 -sgn(y
|
||||
2 sgn(x), "rounding to zero"
|
||||
3 -sgn(x), "rounding from zero"
|
||||
4 +, "rounding down"
|
||||
5 -, "rounding up"
|
||||
6 sgn(x/y)
|
||||
7 -sgn(x/y)
|
||||
|
||||
If bit 4 of rnd is set, the other bits are irrelevant for the eps case;
|
||||
thus for 16 <= rnd < 24, cfappr(x, eps, rnd) is the smallest-denominator
|
||||
number differing from x by at most abs(eps)/2.
|
||||
|
||||
If bit 4 of rnd is set and den(x) > 2, the other bits are irrelevant for
|
||||
the bounded denominator case; in the case of two equally near nearest
|
||||
approximations with denominator less than n, cfappr(x, n, rnd)
|
||||
returns the number with smaller denominator. If den(x) = 2, bits
|
||||
0, 1 and 2 of rnd are used as described above.
|
||||
|
||||
If -1 < eps < 1, cfappr(x, eps, 0) may be described as the smallest
|
||||
denominator number in the closed interval with end-points x and x - eps.
|
||||
It follows that if abs(a - b) < 1, cfappr(a, a - b, 0) gives the smallest
|
||||
denominator number in the interval with end-points a and b; the same
|
||||
result is returned by cfappr(b, b - a, 0) or cfappr(a, b - a, 1).
|
||||
|
||||
If abs(eps) < 1 and v = cfappr(x, eps, rnd), then
|
||||
cfappr(x, sgn(eps) * den(v), rnd) = v.
|
||||
|
||||
If 1 <= n < den(x), u = cfappr(x, n, 0) and v = cfappr(x, n, 1), then
|
||||
u < x < v, den(u) <= n, den(v) <= n, den(u) + den(v) > n, and
|
||||
v - u = 1/(den(u) * den(v)).
|
||||
|
||||
If x is not zero, the nearest approximation with numerator not
|
||||
exceeding n is 1/cfappr(1/x, n, 16).
|
||||
|
||||
EXAMPLE
|
||||
> c = config("mode", "frac")
|
||||
> x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1);
|
||||
> print u, v, x - u, v - x, v - u, cfappr(x, 10, 16)
|
||||
10/7 13/9 1/210 1/90 1/63 10/7
|
||||
|
||||
> pi = pi(1e-10)
|
||||
> print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16)
|
||||
311/99 22/7 355/113
|
||||
|
||||
> x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1);
|
||||
> print u, v, x - u, v - x, cfappr(x,4,16)
|
||||
4/3 3/2 1/12 1/12 3/2
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R)
|
||||
|
||||
SEE ALSO
|
||||
appr, cfsim
|
Reference in New Issue
Block a user