failed attempts to intercept copy command when the cursor is in the empty text field...
[LeanCalc.git] / help / digit
1 NAME
2     digit - digit at specified position in a "decimal" representation
3
4 SYNOPSIS
5     digit(x, n [, b])
6
7 TYPES
8     x           real
9     n           integer
10     b           integer >= 2, default = 10
11
12     return      integer
13
14 DESCRIPTION
15
16     d(x,n,b) returns the digit with index n in a standard base-b "decimal"
17     representation of x, which may be described as follows:
18
19     For an arbitrary base b >= 2, following the pattern of decimal (base 10)
20     notation in elementary arithmetic, a base-b "decimal" representation of
21     a positive real number may be considered to be specified by a finite or
22     infinite sequence of "digits" with possibly a "decimal" point
23     to indicate where the fractional part of the representation begins.
24     Just as the digits for base 10 are the integers 0, 1, 2, ..., 9, the
25     digits for a base-b representation are the integers d for which
26     0 <= d < b.   The index for a digit position is the count, positively to
27     the left, of the number from the "units" position immediately to the
28     left of the "decimal" point; the digit  d_n  at position n contributes
29     additively  d_n * b^n  to the value of x.  For example,
30
31                 d_2 d_1 d_0 . d_-1 d_-2
32
33     represents the number
34
35                 d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
36
37     The sequence of digits has to be infinite if den(x) has a prime factor
38     which is not a factor of the base b.  In cases where the representation
39     may terminate, the digits are considered to continue with an infinite
40     string of zeros rather than the other possibility of an infinite
41     sequence of (b - 1)s.  Thus, for the above example, d_n = 0 for
42     n = -3, -4, ...  Similarly, a representation may be considered to
43     continue with an infinite string of zeros on the left, so that in the
44     above example d_n = 0 also for n >= 3.
45
46     For negative x, digit(x,n,b) is given by digit(abs(x),n,b); the
47     standard "decimal" representation of this x is a - sign followed by
48     the representation of abs(x).
49
50     In calc, the "real" numbers are all rational and for these the
51     digits following the decimal point eventually form a recurring sequence.
52
53     With base-b digits for x as explained above, the integer whose base-b
54     representation is
55
56                 b_n+k-1 b_n_k-2 ... b_n,
57
58     i.e. the k digits with last digit b_n, is given by
59
60                 digit(b^-r * x, q, b^k)
61
62     if r and q satisfy  n = q * b + r.
63
64
65 EXAMPLE
66         > a = 123456.789
67         > for (n = 6; n >= -6; n++) print digit(a, n),; print
68         0 1 2 3 4 5 6 7 8 9 0 0 0
69
70         > for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
71         0 0 0 0 12 34 56 78 90 0 0 0 0
72
73         > for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
74         0 0 0 0 1 226 64 201 251 231 108 139 67
75
76         > for (n = 1; n >= -12; n++) print digit(10/7, n),; print
77         > 0 1 4 2 8 5 7 1 4 2 8 5 7 1
78
79         > print digit(10/7, -7e1000, 1e6)
80         428571
81
82 LIMITS
83
84     The absolute value of the integral part of x is assumed to be less
85     than 2^2^31, ensuring that digit(x, n, b) will be zero if n >= 2^31.
86     The size of negative n is limited only by the capacity of the computer
87     being used.
88
89 LINK LIBRARY
90     NUMBER * qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base)
91
92 SEE ALSO
93     bit
94