-
Notifications
You must be signed in to change notification settings - Fork 0
Numbers
A rational number is any number that can be expressed as the quotient or fraction of two integers. For example, 12, 2.75, and 1/9 are all rational numbers, while √2, √-1, e, and π are not.
(rational? 1.234) -> #true
An irrational number is any number that cannot be expressed as the quotient or fraction of two integers. For example, √2, √-1, e, and π are all irrational numbers, while 12, 1.75, and 1/11 are not.
(rational? pi) -> #false
An integer is a rational number that can be written without a fractional component. For example, 21, 4, 0, and -2048 are integers, while 9.75, π, and √2 are not.
(integer? 1.234) -> #false
A natural is a positive integer not including zero, more commonly referred to as the counting numbers. For example, 21, 4, 1, and 2048 are all naturals, while 0, -1, 9.75, π, and √2 are not.
(natural? 1) -> #true
An exact number is any number that is derived without any assumption or estimation. For example, a number derived from the function sine would not produce an exact number where a number derived from the function add would.
(exact? -20) -> #true
An inexact number is any number that is derived with rounding or truncation. For example, a number derived from the function cosine would produce an inexact number where a number derived from the function add would not.
(exact? #i3.14159) -> #false
(abs [number]) -> number
Determines the absolute value of a number.
(abs -12)
12
(+ [number] [number] [number] ...) -> number
Adds up all numbers.
(+ 1 2 3)
6
(add1 [number]) -> number
Increments the given number by one.
(add1 2)
3
(acos [number]) -> number
Computes the arccosine (inverse of cos) of a number.
(acos 0)
#i1.5707963267948966
(asin [number]) -> number
Computes the arcsine (inverse of sin) of a number.
(asin 0)
#i0.0
(atan [number]) -> number
Computes the arctangent of the given number.
(atan 0)
#i0.0
(ceiling [number]) -> integer
Determines the closest integer (exact or inexact) above a number. See round.
(ceiling 12.3)
13.0
(cos [number]) -> number
Computes the cosine of a number (radians).
(cos pi)
#i-1.0
(current-seconds) -> integer
Determines the current time in seconds elapsed (since a platform-specific starting date in the case of Racket-Lite: January 1st, 1 AD at 12:00:00 AM).
(current-seconds)
63738984180
(/ [number] [number] [number] ...) -> number
Divides the first by the second (and all following) number(s).
(/ 12 2 3)
2
(= [number] [number] [number] ...) -> boolean
Compares numbers for equality.
(= 2 3)
#false
(expt [number] [number]) -> number
Computes the power of the first to the second number.
(expt 16 1/2)
4
(exp [number]) -> number
Determines e raised to a number.
(exp -2)
#i0.1353352832366127
(floor [number]) -> integer
Determines the closest integer (exact or inexact) below a number. See round.
(floor 12.3)
12.0
(> [number] [number] [number] ...) -> boolean
Compares numbers for greater-than.
(> 3 2)
#true
(>= [number] [number] [number] ...) -> boolean
Compares numbers for greater-than or equality.
(>= 3 2)
#true
(gcd [integer] [integer] [integer] ...) -> integer
Determines the greatest common divisor of two integers (exact or inexact).
(gcd 6 12 8)
2
(cosh [number]) -> number
Computes the hyperbolic cosine of a number.
(cosh 10)
#i11013.232920103324
(sinh [number]) -> number
Computes the hyperbolic sine of a number.
(sinh 10)
#i11013.232874703393
(even? [integer]) -> boolean
Determines if some integer (exact or inexact) is even or not.
(even? 2)
#true
(exact? [number]) -> boolean
Determines whether some number is exact.
(exact? #i12.87)
#false
(integer? [any]) -> boolean
Determines whether some value is an integer (exact or inexact).
(integer? "hello world")
#false
(natural? [any]) -> boolean
Determines whether some value is a natural (exact or inexact).
(natural? -2)
#false
(negative? [number]) -> boolean
Determines if some number is strictly smaller than zero.
(negative? -2)
#true
(number? [any]) -> boolean
Determines whether some value is a number.
(number? "hello world")
#false
(odd? [integer]) -> boolean
Determines if some integer (exact or inexact) is odd or not.
(odd? 2)
#false
(positive? [number]) -> boolean
Determines if some number is strictly larger than zero.
(positive? -2)
#false
(rational? [any]) -> boolean
Determines whether some value is a rational number.
(rational? #i3.141592653589793)
#false
(zero? [number]) -> boolean
Determines if some number is zero or not.
(zero? 2)
#false
(< [number] [number] [number] ...) -> boolean
Compares numbers for less-than.
(< 2 2)
#false
(<= [number] [number] [number] ...) -> boolean
Compares numbers for less-than or equality.
(<= 2 2)
#true
(lcm [integer] [integer] [integer] ...) -> integer
Determines the least common multiple of two integers (exact or inexact).
(lcm 6 12 8)
24
(max [number] [number] [number] ...) -> number
Determines the largest number (AKA the maximum).
(max 36 25 16 9)
36
(min [number] [number] [number] ...) -> number
Determines the smallest number (AKA the minimum).
(min 36 25 16 9)
9
(modulo [integer] [integer]) -> integer
Finds the remainder of the division of the first number by the second.
(modulo 9 2)
1
(* [number] [number] [number] ...) -> number
Multiplies all numbers.
(* 1 3 5)
15
(log [number]) -> number
Determines the base-e logarithm of a number.
(log 12)
#i2.4849066497880004
(quotient [integer] [integer]) -> integer
Divides the first integer (also called dividend) by the second integer (also known as the divisor) to obtain the quotient.
(quotient 9 2)
4
(random [natural]) -> natural
Generates a random natural number less than or equal to some given natural.
(random 42)
11
(remainder [integer] [integer]) -> [integer]
Determines the remainder of dividing the first by the second integer (exact or inexact).
(remainder 9 2)
1
(round [number]) -> [integer]
Rounds a number to an integer (rounds to even to break ties). See floor and ceiling.
(round 12.3)
12.0
(sgn [number]) -> (union 1 or -1)
Determines the sign of a number.
(sgn -12)
-1
(sin [number]) -> number
Computes the sine of a number (radians).
(sin pi)
#i1.2246467991473532e-16
(sqr [number]) -> number
Computes the square of a number.
(sqr 8)
64
(sqrt [number]) -> number
Computes the square root of a number.
(sqrt 9)
3
(- [number] [number] [number] ...) -> number
Subtracts the second (and following) number(s) from the first; negates the number if there is only one argument.
(- 5 3 1)
1
(sub1 [number]) -> number
Decrements the given number by one.
(sub1 2)
1
(tan [number]) -> number
Computes the tangent of a number (radians).
(tan pi)
#i-1.2246467991473532e-16
(exact->inexact [number]) -> number
Converts an exact number to an inexact one.
(exact->inexact 12)
#i12.0
(inexact->exact [number]) -> number
Approximates an inexact number by an exact one.
(exact->inexact #i12.0)
12.0
(number->string [number]) -> string
Converts a number to a string.
(number->string 65)
"65"