steel/numbers
*
Multiplies the given numbers.
(* . nums) -> number?
- nums : number? - The numbers to multiply. Can have any number of arguments including zero.
Examples
> (* 5 3) ;; => 15
> (* 10 3 2) ;; => 60
> (*) ;; => 1
+
Adds the given numbers.
(+ . nums) -> number?
- nums : number? - The numbers to add. Can have any number of arguments including zero.
Examples
> (+ 5 3) ;; => 8
> (+ 10 3 2) ;; => 15
> (+) ;; => 0
-
Subtracts the given numbers.
(- . nums) -> number?
- nums : number? - The numbers to subtract. Must have at least one number.
Examples
> (- 5 3) ;; => 2
> (- 10 3 2) ;; => 5
> (- -5) ;; => 5
/
Divides the given numbers.
(/ . nums) -> number?
- nums : number? - The numbers to divide. Must have at least one number.
Examples
> (/ 10 2) ;; => 5
> (/ 10 2 2.0) ;; => 2.5
> (/ 1 3.0) ;; => 0.3333333333333333
> (/ 1 3) ;; => 1/3
abs
Computes the absolute value of the given number.
(abs number) -> number?
- number : number? - The number to compute the absolute value of.
Examples
> (abs 42) ;; => 42
> (abs -42) ;; => 42
> (abs 0) ;; => 0
ceiling
Rounds the given number up to the nearest integer not less than it.
(ceiling number) -> integer?
- number : number? - The number to round up.
Examples
> (ceiling 42) ;; => 42
> (ceiling 42.1) ;; => 43
> (ceiling -42.1) ;; => -42
denominator
Retrieves the denominator of the given rational number.
(denominator number) -> integer?
- number : number? - The rational number to retrieve the denominator from.
Examples
> (denominator 1/2) ;; => 2
> (denominator 3/4) ;; => 4
> (denominator 4) ;; => 1
exact->inexact
Converts an exact number to an inexact number.
(exact->inexact num) -> number?
- num : number? - The number to convert from exact to inexact.
Examples
> (exact->inexact 10) ;; => 10
> (exact->inexact 1/2) ;; => 0.5
> (exact->inexact 1+2i) ;; => 1+2i
exact-integer-sqrt
Computes the integer square root of the given non-negative integer.
(exact-integer-sqrt number) -> (integer? integer?)
- number : (and/c integer? positive?) - The non-negative integer to compute the square root for.
Examples
> (exact-integer-sqrt 25) ;; => (5 0)
> (exact-integer-sqrt 35) ;; => (5 10)
exact?
Checks if the given value is exact.
(exact? val) -> boolean?
- val : any - The value to check for exactness.
Examples
> (exact? 42) ;; => #t
> (exact? 3.14) ;; => #f
> (exact? "hello") ;; => #f
exp
Returns Euler’s number raised to the power of z.
(exp z) -> number?
- z : number? - The number to raise e to the power of.
Examples
> (exp 0) ;; => 1
> (exp 2) ;; => 7.38905609893065
> (exp 1.5) ;; => 4.4816890703380645
expt
Raises the left operand to the power of the right operand.
(expt base exponent) -> number?
- base : number? - The base number.
- exponent : number? - The exponent to raise the base to.
Examples
> (expt 2 3) ;; => 8
> (expt 2.0 0.5) ;; => 1.4142135623730951
> (expt 9 0.5) ;; => 3
finite?
Returns #t
if the given number is finite.
(finite? number) -> boolean?
- number : number? - The number to check for finiteness.
Examples
> (finite? 42) ;; => #t
> (finite? 0.1) ;; => #t
> (finite? +inf.0) ;; => #f
> (finite? -inf.0) ;; => #f
> (finite? +nan.0) ;; => #f
floor
Computes the largest integer less than or equal to the given number.
(floor number) -> number?
- number : number? - The number to compute the floor for.
Examples
> (floor 3.14) ;; => 3
> (floor 4.99) ;; => 4
> (floor -2.5) ;; => -3
inexact->exact
Converts an inexact number to an exact number.
(inexact->exact num) -> number?
- num : number? - The number to convert from inexact to exact.
Examples
> (inexact->exact 10.0) ;; => 10
> (inexact->exact 1.5) ;; => 3/2
> (inexact->exact 1.5+2.5i) ;; => 3/2+5/2i
inexact?
Checks if the given value is inexact.
(inexact? val) -> boolean?
- val : any - The value to check for inexactness.
Examples
> (inexact? 42) ;; => #f
> (inexact? 3.14) ;; => #t
infinite?
Returns #t
if the given number is infinite.
(infinite? number) -> boolean?
- number : number? - The number to check for infiniteness.
Examples
> (infinite? 42) ;; => #f
> (infinite? -nan.0) ;; => #f
> (infinite? +inf.0) ;; => #t
log
Computes the natural logarithm of the given number.
(log number [base]) -> number?
- number : number? - The number to compute the logarithm for.
- base : number? - The base of the logarithm. If not provided, defaults to Euler's number (e).
Examples
> (log 10) ;; => 2.302585092994046
> (log 100 10) ;; => 2
> (log 27 3) ;; => 3
magnitude
Computes the magnitude of the given number.
(magnitude number) -> number?
- number : number? - The number to compute the magnitude for.
Examples
> (magnitude 3+4i) ;; => 5
> (magnitude 5) ;; => 5
> (magnitude -5) ;; => 5
nan?
Returns #t
if the real number is Nan.
(nan? value) -> boolean?
- value : real? - The value to check
(nan? +nan.0) => #t
(nan? 100000) => #f
negative?
Checks if the given real number is negative.
(negative? num) -> boolean?
- num : real? - The real number to check for negativity.
Examples
> (negative? 0) ;; => #f
> (negative? 1) ;; => #f
> (negative? -1) ;; => #t
numerator
Retrieves the numerator of the given rational number.
(numerator number) -> number?
- number : number? - The rational number to retrieve the numerator from.
Examples
> (numerator 3/4) ;; => 3
> (numerator 5/2) ;; => 5
> (numerator -2) ;; => -2
positive?
Checks if the given real number is positive.
(positive? num) -> boolean?
- num : real? - The real number to check for positivity.
Examples
> (positive? 0) ;; => #f
> (positive? 1) ;; => #t
> (positive? -1) ;; => #f
quotient
Returns quotient of dividing numerator by denomintator.
(quotient numerator denominator) -> integer?
- numerator : integer? - The numerator.
- denominator : integer? - The denominator.
Examples
> (quotient 11 2) ;; => 5
> (quotient 10 2) ;; => 5
> (quotient -10 2) ;; => -5
round
Rounds the given number to the nearest integer.
(round number) -> number?
- number : number? - The number to round.
Examples
> (round 3.14) ;; => 3
> (round 4.6) ;; => 5
> (round -2.5) ;; => -3
sqrt
Computes the square root of the given number.
(sqrt number) -> number?
- number : number? - The number to compute the square root for.
Examples
> (sqrt 4) ;; => 2
> (sqrt 2) ;; => 1.4142135623730951
> (sqrt -1) ;; => 0+1i
square
Computes the square of the given number.
(square number) -> number?
- number : number? - The number to square.
Examples
> (square 5) ;; => 25
> (square -3) ;; => 9
> (square 2.5) ;; => 6.25
zero?
Checks if the given real number is zero.
(zero? num) -> boolean?
- num : real? - The number to check for zero.
Examples
> (zero? 0) ;; => #t
> (zero? 0.0) ;; => #t
> (zero? 0.1) ;; => #f