Next Previous Contents

9. Miscellaneous commands

9.1 The rand command

This command returns a random number from 0 (inclusive) to 1 (exclusive).

9.2 The rdz command

This command takes a number as argument, and stores that number as the random number generator seed. If the argument is 0, then a seed is generated from the current time.

9.3 The ! command

This command returns the factorial of the number given as argument. For non-integers, it returns gamma(x + 1).

Examples:

> 5 !
[ 1]                       120
> 6.3 !
[ 2]                       120
[ 1]          1271.42363366391

9.4 The lgamma command

This command returns the logarithm of the absolute value of the gamma function of its argument.

Examples:

> 6.3 lgamma
[ 1]          5.30734288962476

9.5 The perm command

This command returns the number of permutations of n elements (level two) taken m by m (level one.)

Examples:

> 10 3 perm
[ 1]                       720

9.6 The comb command

This command returns the number of combinations of n elements (level two) taken m by m (level one.)

Examples:

> 10 3 comb
[ 1]                       120

9.7 The min command

This command returns the smallest of its two arguments.

Examples:

> 3 4 min
[ 1]                         3

9.8 The max command

This command returns the largest of its two arguments.

Examples:

> 3 4 max
[ 1]                         4

9.9 The sign command

For real numbers, this command returns -1 if the number is negative, 0 if it is zero or 1 if it is positive. For complex numbers, it returns the unit vector in the direction of a complex number.

Examples:

> -6 sign
[ 1]                        -1
> 0 sign
[ 2]                        -1
[ 1]                         0
> 8 sign
[ 3]                        -1
[ 2]                         0
[ 1]                         1
> (3, 4) sign
[ 4]                        -1
[ 3]                         0
[ 2]                         1
[ 1]                 (0.6,0.8)

9.10 The psign command

This command returns -1 if the number is negative, or 1 if it is positive or zero.

Examples:

> -6 psign
[ 1]                        -1
> 0 psign
[ 2]                        -1
[ 1]                         1
> 8 psign
[ 3]                        -1
[ 2]                         1
[ 1]                         1

9.11 The mant command

This command returns the mantissa of its argument.

Examples:

> 1.3515413566333e20
[ 1]       1.3515413566333e+20
> mant
[ 1]           1.3515413566333

9.12 The xpon command

This command returns the exponent of its argument.

Examples:

> 1.3515413566333e20
[ 1]       1.3515413566333e+20
> xpon
[ 1]                        20

9.13 The rnd command

This command truncates the level two argument (a real or complex number) to n (in level one) decimal places.

Examples:

> pi
[ 1]          3.14159265358979
> 4 rnd
[ 1]                    3.1416

9.14 The type command

This command returns the type of its argument. The type is one of the following:

0

A real number

1

A complex number

2

A string

6

An identifier

Examples:

> 45 type
[ 1]                         0
> "Hello World" type
[ 2]                         0
[ 1]                         2

9.15 The = command

This command is special. It allows you to override the number of stack elements to show, but only for the next time the stack is displayed. It accepts an argument, but not from the stack. If there is a number immediately following the ``='' command, it is treated as the number of elements to display. If there is no number, or the number is less than or equal to zero, the whole stack is displayed. Note that there must be no space between the number and the ``='' sign.

9.16 The shell command

The shell command is used to run commands from calc. To run a command, just enter shell COMMAND. The command will be run, and after it finishes, a message will be displayed asking you to press ENTER. When you're done examining the output of the command, press ENTER to return to calc.

If you do not specify a command for the shell command, an interactive shell will be called instead. When you're finished, exit the shell as usual, normally by entering exit at the prompt or pressing CTRL-D.


Next Previous Contents