Though originally Lisp has been created only for operation with characters and lists, language both on computing efficiency and on the properties quite suits and numerical calculations.
Function call of subtraction without arguments returns number with the changed sign, and function abs - a number absolute value:
>(3 -)
-3
>(-3 abs)
3
For matching of numbers following operations are used:
(x = &rest xi) | ; numbers are equal |
(x <> &rest xi) | ; numbers are not equal x |
(x < &rest xi) | ; numbers increase |
(x > &rest xi) | ; numbers decrease |
(x <= &rest xi) | ; increase or are equal (do not decrease) |
(x >= &rest xi) | ; decrease or are equal (do not increase) |
Matching operations admit any number of arguments:
>(1 < 2 3 4 5 6)
1
Arithmetic operations are:
(x + &rest xi) | ; the sum |
(x - &rest xi) | ; subtraction |
(x * &rest xi) | ; multiplication |
(x / &rest xi) | ; division |
(x min &rest xi) | ; the least xi |
(x max &rest xi) | ; the greatest xi |
There is a wide range of certain transcendental functions, such as exponent, the log and trigonometrical functions:
(x exp) | ; e in a degree x |
(x ^ y) | ; x in a degree y |
(x log y) | ; the log x on the basis y |
(x ln) | ; logarithm x on the basis e |
(x sqrt) | ; the square root |
Arguments of following trigonometrical functions are set in radians:
(x sin) and (x arcsin) |
(x cos) and (x arccos) |
(x tan) and (x arctan) |
Number π is value of a global variable pi. There are hyperbolic and inversely functions:
(x sinh) and (x arsinh) |
(x cosh) and (x arcosh) |
(x tanh) and (x artanh) |
The generator of random numbers is called in shape:
(x random)
It generates strictly smaller on an absolute value, than x a random number.
Considered before function are applicable for all numbers. Besides there are specific functions which make sense only for integers.
It is possible to represent all numbers with unlimited accuracy. Integers also can be very big. At their usage accuracy is not lost.
Here some functions and the predicates defined and used only for integers:
(n evenp) | ; checks, whether even number |
(n oddp) | ; checks, whether odd number |
(n gcd &rest ni) | ; the greatest common divider |
(n lcm &rest ni) | ; the least common multiple |
Language contains possibility absent in traditional programming languages to use fractional numbers without their conversion to numbers from a floating point, that usually only reduces accuracy of their representation. Fractional numbers are represented by the sign and positive numbers between which there is a fraction bar /:
1/3
2/6 ; =1/3
4/1/3 ; =4+1/3
-4/1/3 ; =-(4+1/3)
If as a result of calculations the reduced number automatically there is a cutting of number to its initial form turns out.
For short record of very big (little) numbers it is possible to use record with an exponential curve. The exponential part displays an exponent in terms of a degree of ten:
2.1e3 ; =2100
-2.1e-3 ; =-0.0021
Record with an exponential curve does not reduce accuracy of number, and is necessary only for brevity to record.
Numbers are represented by a pair of numbers, not separated by spaces. One number must be imaginary. The imaginary part is determined by the symbol i.
1+1i
-2i
-2i+3/4
Also for convenience there is a possibility to represent number in sixteenal system of numeration.
0xff ; =255
-0xf.f ; =-(15+15/16)