mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.2t1
This commit is contained in:
91
help/digit
91
help/digit
@@ -1,93 +1,38 @@
|
||||
NAME
|
||||
digit - digit at specified position in a "decimal" representation
|
||||
digit - digit at specified position in a decimal representation
|
||||
|
||||
SYNOPSIS
|
||||
digit(x, n [, b])
|
||||
digit(x, y)
|
||||
|
||||
TYPES
|
||||
x real
|
||||
n integer
|
||||
b integer >= 2, default = 10
|
||||
y integer
|
||||
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
By extending the digits on the left, and if necessary, the digits
|
||||
on the right, by infinite strings of zeros, abs(x) may be considered
|
||||
to have the decimal representation:
|
||||
|
||||
d(x,n,b) returns the digit with index n in a standard base-b "decimal"
|
||||
representation of x, which may be described as follows:
|
||||
|
||||
For an arbitrary base b >= 2, following the pattern of decimal (base 10)
|
||||
notation in elementary arithmetic, a base-b "decimal" representation of
|
||||
a positive real number may be considered to be specified by a finite or
|
||||
infinite sequence of "digits" with possibly a "decimal" point
|
||||
to indicate where the fractional part of the representation begins.
|
||||
Just as the digits for base 10 are the integers 0, 1, 2, ..., 9, the
|
||||
digits for a base-b representation are the integers d for which
|
||||
0 <= d < b. The index for a digit position is the count, positively to
|
||||
the left, of the number from the "units" position immediately to the
|
||||
left of the "decimal" point; the digit d_n at position n contributes
|
||||
additively d_n * b^n to the value of x. For example,
|
||||
|
||||
d_2 d_1 d_0 . d_-1 d_-2
|
||||
|
||||
represents the number
|
||||
|
||||
d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
|
||||
|
||||
The sequence of digits has to be infinite if den(x) has a prime factor
|
||||
which is not a factor of the base b. In cases where the representation
|
||||
may terminate, the digits are considered to continue with an infinite
|
||||
string of zeros rather than the other possibility of an infinite
|
||||
sequence of (b - 1)s. Thus, for the above example, d_n = 0 for
|
||||
n = -3, -4, ... Similarly, a representation may be considered to
|
||||
continue with an infinite string of zeros on the left, so that in the
|
||||
above example d_n = 0 also for n >= 3.
|
||||
|
||||
For negative x, digit(x,n,b) is given by digit(abs(x),n,b); the
|
||||
standard "decimal" representation of this x is a - sign followed by
|
||||
the representation of abs(x).
|
||||
|
||||
In calc, the "real" numbers are all rational and for these the
|
||||
digits following the decimal point eventually form a recurring sequence.
|
||||
|
||||
With base-b digits for x as explained above, the integer whose base-b
|
||||
representation is
|
||||
|
||||
b_n+k-1 b_n_k-2 ... b_n,
|
||||
|
||||
i.e. the k digits with last digit b_n, is given by
|
||||
|
||||
digit(b^-r * x, q, b^k)
|
||||
|
||||
if r and q satisfy n = q * b + r.
|
||||
... d_2 d_1 d_0.d_-1 d_-2 ...
|
||||
|
||||
digit(x,y) then returns the digit d_y.
|
||||
|
||||
EXAMPLE
|
||||
> a = 123456.789
|
||||
> for (n = 6; n >= -6; n++) print digit(a, n),; print
|
||||
0 1 2 3 4 5 6 7 8 9 0 0 0
|
||||
> x = 12.34
|
||||
> print digit(x,2), digit(x,1), digit(x,0), digit(x,-1), digit(x,-2)
|
||||
0 1 2 3 4
|
||||
|
||||
> for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
|
||||
0 0 0 0 12 34 56 78 90 0 0 0 0
|
||||
|
||||
> for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
|
||||
0 0 0 0 1 226 64 201 251 231 108 139 67
|
||||
|
||||
> for (n = 1; n >= -12; n++) print digit(10/7, n),; print
|
||||
> 0 1 4 2 8 5 7 1 4 2 8 5 7 1
|
||||
|
||||
> print digit(10/7, -7e1000, 1e6)
|
||||
428571
|
||||
> x = 10/7
|
||||
> print digit(x,1), digit(x,0), digit(x,-1), digit(x,-2), digit(x,-3)
|
||||
0 1 4 2 8
|
||||
|
||||
LIMITS
|
||||
|
||||
The absolute value of the integral part of x is assumed to be less
|
||||
than 2^2^31, ensuring that digit(x, n, b) will be zero if n >= 2^31.
|
||||
The size of negative n is limited only by the capacity of the computer
|
||||
being used.
|
||||
If x is not an integer, y > -2^31
|
||||
|
||||
LINK LIBRARY
|
||||
NUMBER * qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base)
|
||||
long qdigit(NUMBER *x, long y)
|
||||
|
||||
SEE ALSO
|
||||
bit
|
||||
@@ -108,8 +53,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: digit,v 29.3 2000/12/14 10:32:24 chongo Exp $
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: digit,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digit,v $
|
||||
##
|
||||
## Under source code control: 1995/10/03 10:40:01
|
||||
|
Reference in New Issue
Block a user