mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.0t10
This commit is contained in:
@@ -15,7 +15,7 @@ Using objects
|
||||
where D is a fixed integer, and 'a' and 'b' are arbitrary rational
|
||||
numbers. Addition, subtraction, multiplication, and division can be
|
||||
performed on such numbers, and the result can be put unambiguously
|
||||
into the same form. (Complex numbers are an example of surds, where
|
||||
into the same form. (Complex numbers are an example of surds, where
|
||||
D is -1.)
|
||||
|
||||
The "obj" statement defines either an object type or an actual
|
||||
@@ -53,8 +53,8 @@ Using objects
|
||||
called.
|
||||
|
||||
The user function is called with the necessary arguments for that
|
||||
operation. For example, for "surd_mul", there are two arguments,
|
||||
which are the two numbers. The order of the arguments is always
|
||||
operation. For example, for "surd_mul", there are two arguments,
|
||||
which are the two numbers. The order of the arguments is always
|
||||
the order of the binary operands. If only one of the operands to
|
||||
a binary operator is an object, then the user function for that
|
||||
object type is still called. If the two operands are of different
|
||||
@@ -64,7 +64,7 @@ Using objects
|
||||
The above rules mean that for full generality, user functions
|
||||
should detect that one of their arguments is not of its own object
|
||||
type by using the 'istype' function, and then handle these cases
|
||||
specially. In this way, users can mix normal numbers with object
|
||||
specially. In this way, users can mix normal numbers with object
|
||||
types. (Functions which only have one operand don't have to worry
|
||||
about this.) The following example of "surd_mul" demonstrates how
|
||||
to handle regular numbers when used together with surds:
|
||||
@@ -88,13 +88,13 @@ Using objects
|
||||
x.b = a.a * b.b + a.b * b.a;
|
||||
}
|
||||
if (x.b == 0)
|
||||
return x.a; /* normal number */
|
||||
return x.a; /* normal number */
|
||||
return x; /* return surd */
|
||||
}
|
||||
|
||||
In order to print the value of an object nicely, a user defined
|
||||
routine can be provided. For small amounts of output, the print
|
||||
routine should not print a newline. Also, it is most convenient
|
||||
routine should not print a newline. Also, it is most convenient
|
||||
if the printed object looks like the call to the creation routine.
|
||||
For output to be correctly collected within nested output calls,
|
||||
output should only go to stdout. This means use the 'print'
|
||||
@@ -121,50 +121,50 @@ Using objects
|
||||
in order to make object calls quicker in general.
|
||||
|
||||
The double-bracket operator can be used to reference the elements
|
||||
of any object in a generic manner. When this is done, index 0
|
||||
of any object in a generic manner. When this is done, index 0
|
||||
corresponds to the first element name, index 1 to the second name,
|
||||
and so on. The 'size' function will return the number of elements
|
||||
and so on. The 'size' function will return the number of elements
|
||||
in an object.
|
||||
|
||||
The following is a list of the operations possible for objects.
|
||||
The 'xx' in each function name is replaced with the actual object
|
||||
type name. This table is displayed by the 'show objfuncs' command.
|
||||
type name. This table is displayed by the 'show objfuncs' command.
|
||||
|
||||
Name Args Comments
|
||||
|
||||
xx_print 1 print value, default prints elements
|
||||
xx_one 1 multiplicative identity, default is 1
|
||||
xx_test 1 logical test (false,true => 0,1),
|
||||
xx_print 1 print value, default prints elements
|
||||
xx_one 1 multiplicative identity, default is 1
|
||||
xx_test 1 logical test (false,true => 0,1),
|
||||
default tests elements
|
||||
xx_add 2
|
||||
xx_sub 2 subtraction, default adds negative
|
||||
xx_neg 1 negative
|
||||
xx_mul 2
|
||||
xx_div 2 non-integral division, default multiplies
|
||||
xx_add 2
|
||||
xx_sub 2 subtraction, default adds negative
|
||||
xx_neg 1 negative
|
||||
xx_mul 2
|
||||
xx_div 2 non-integral division, default multiplies
|
||||
by inverse
|
||||
xx_inv 1 multiplicative inverse
|
||||
xx_abs 2 absolute value within given error
|
||||
xx_norm 1 square of absolute value
|
||||
xx_conj 1 conjugate
|
||||
xx_pow 2 integer power, default does multiply,
|
||||
xx_inv 1 multiplicative inverse
|
||||
xx_abs 2 absolute value within given error
|
||||
xx_norm 1 square of absolute value
|
||||
xx_conj 1 conjugate
|
||||
xx_pow 2 integer power, default does multiply,
|
||||
square, inverse
|
||||
xx_sgn 1 sign of value (-1, 0, 1)
|
||||
xx_cmp 2 equality (equal,non-equal => 0,1),
|
||||
xx_sgn 1 sign of value (-1, 0, 1)
|
||||
xx_cmp 2 equality (equal,non-equal => 0,1),
|
||||
default tests elements
|
||||
xx_rel 2 inequality (less,equal,greater => -1,0,1)
|
||||
xx_quo 2 integer quotient
|
||||
xx_mod 2 remainder of division
|
||||
xx_int 1 integer part
|
||||
xx_frac 1 fractional part
|
||||
xx_inc 1 increment, default adds 1
|
||||
xx_dec 1 decrement, default subtracts 1
|
||||
xx_square 1 default multiplies by itself
|
||||
xx_scale 2 multiply by power of 2
|
||||
xx_shift 2 shift left by n bits (right if negative)
|
||||
xx_round 2 round to given number of decimal places
|
||||
xx_bround 2 round to given number of binary places
|
||||
xx_root 3 root of value within given error
|
||||
xx_sqrt 2 square root within given error
|
||||
xx_rel 2 inequality (less,equal,greater => -1,0,1)
|
||||
xx_quo 2 integer quotient
|
||||
xx_mod 2 remainder of division
|
||||
xx_int 1 integer part
|
||||
xx_frac 1 fractional part
|
||||
xx_inc 1 increment, default adds 1
|
||||
xx_dec 1 decrement, default subtracts 1
|
||||
xx_square 1 default multiplies by itself
|
||||
xx_scale 2 multiply by power of 2
|
||||
xx_shift 2 shift left by n bits (right if negative)
|
||||
xx_round 2 round to given number of decimal places
|
||||
xx_bround 2 round to given number of binary places
|
||||
xx_root 3 root of value within given error
|
||||
xx_sqrt 2 square root within given error
|
||||
xx_or 2 boolean or
|
||||
xx_and 2 boolean and
|
||||
xx_not 1 boolean not
|
||||
|
Reference in New Issue
Block a user