-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmath.tem
46 lines (46 loc) · 3.15 KB
/
math.tem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(page "Math operations"
(newtable "Math operations"
(text "The math operations of Arc are fairly limited. Many expected
operations, such as trigonometry, are missing.")
(op * "args" "Multiplication."
(tests (* 2 3)))
(op + "args" "Addition. This operator also performs string and list
concatenation."
(tests (+ 1 2 3)
(+ "ab" "c" "de")
"(+ '(1 2) '(3 4) '(5))") )
(op - "args" "Subtraction."
(tests (- 3 2)))
(op / "args" "Division"
(tests (/ 1 2) (/ 1. 2)))
(op cos "arg" "Cosine function. New in arc3." (tests (cos 3.14)))
(op expt "base exponent" "Exponentiation."
(tests (expt 2 3)))
(op log "arg" "Natuarl logarithm function. New in arc3." (tests (log 100)))
(op mod "dividend divisor" " "
(tests (mod 10 3) (mod -10 3)))
(op rand "[max] " "Returns a random number between 0 and 1, or between 0 and
the specified integer (excluding the integer)."
(tests (rand 10) (rand)))
(op sin "arg" "Sine function. New in arc3." (tests (sin 3.14)))
(op sqrt "number" "Square root operation"
(tests (sqrt 2)(sqrt -1)))
(op tan "arg" "Tangent function. New in arc3." (tests (tan 3.14)))
(op trunc "number" "Truncates to an integer. Was 'truncate' in arc0."
(tests (trunc 1.9) (trunc -1.1)))
(def number "n" "Tests if n is a number (int or num)." (tests (number 3.14)))
(def positive "x" "Tests if x is a number and is positive (>= 0). This fails on complex numbers." (tests (positive 0) (positive -2) (positive "a")))
(def abs "n" "Returns the absolute value." (tests (abs -3)))
(def round "n" "Rounds n to the nearest value. Halfs are rounded to the nearest even number." (tests (round 1/2) (round 1.5) (round .4) (round -1.5)))
(def roundup "n" "Rounds n to the nearest value. Halfs are rounded away from zero." (tests (roundup 1/2) (roundup 1.5) (roundup .4) (roundup -1.5)))
(def nearest "n quantum" "Rounds down to the nearest multiple of n. Renamed in arc3." (tests (nearest 3.14 .1) (nearest -5 10)))
(def median "list" "Returns the median of the list (the element at the midpoint of the list when sorted highest-to-lowest). Takes the earlier element for an even-length list." (tests (median '(1 5 3 2 4)) (median '("dog" "cat" "bird") (median '(1 2 3 4)))))
(def med "list [compare-fn]" "Returns the median of the list (the element at the midpoint of the list when sorted according to compare-fn). Takes the later element for an even-length list. New in arc3." (tests (med '(1 5 3 2 4)) (med '("dog" "cat" "bird") (med '(1 2 3 4)))))
(def avg "numbers" "Computes the average of a list of numbers." (tests (avg '(1+2i .4))))
(def even "n" "Tests if n is even. Argument n must be an integer." (tests (even 1) (even 2)))
(def odd "n" "Tests if n is odd. Argument n must be an integer." (tests (odd 1) (odd 2)))
(def max "[arg ...]" "Returns the maximum arg. The args must be comparable with >." (tests (max 10 -3 5) (max "cat" "dog" "bird")))
(def min "[arg ...]" "Returns the minimum arg. The args must be comparable with <." (tests (min 10 -3 5) (min "cat" "dog" "bird")))
(def predicate multiple "x base" "Tests if <code>x</code> is a multiple of <code>base</code>." (tests (multiple 10 5) (multiple 11 5)))
)
)