Procedure: rational-valued? obj
Procedure: integer-valued? obj
These numerical type predicates can be applied to any kind of argument. The
real-valued?procedure returns#tif the object is a number object and is equal in the sense of=to some real number object, or if the object is a NaN, or a complex number object whose real part is a NaN and whose imaginary part is zero in the sense ofzero?. Therational-valued?andinteger-valued?procedures return#tif the object is a number object and is equal in the sense of=to some object of the named type, and otherwise they return#f.(real-valued? +nan.0) ⇒ #t (real-valued? +nan.0+0i) ⇒ #t (real-valued? -inf.0) ⇒ #t (real-valued? 3) ⇒ #t (real-valued? -2.5+0.0i) ⇒ #t (real-valued? -2.5+0i) ⇒ #t (real-valued? -2.5) ⇒ #t (real-valued? #e1e10) ⇒ #t (rational-valued? +nan.0) ⇒ #f (rational-valued? -inf.0) ⇒ #f (rational-valued? 6/10) ⇒ #t (rational-valued? 6/10+0.0i) ⇒ #t (rational-valued? 6/10+0i) ⇒ #t (rational-valued? 6/3) ⇒ #t (integer-valued? 3+0i) ⇒ #t (integer-valued? 3+0.0i) ⇒ #t (integer-valued? 3.0) ⇒ #t (integer-valued? 3.0+0.0i) ⇒ #t (integer-valued? 8/4) ⇒ #tNote: These procedures test whether a given number object can be coerced to the specified type without loss of numerical accuracy. Specifically, the behavior of these predicates differs from the behavior of
real?,rational?, andinteger?on complex number objects whose imaginary part is inexact zero.Note: The behavior of these type predicates on inexact number objects is unreliable, because any inaccuracy may affect the result.
Returns
#tifzis both exact and an integer; otherwise returns#f.(exact-integer? 32) ⇒ #t (exact-integer? 32.0) ⇒ #t (exact-integer? 32/5) ⇒ #f
Returns
#tifzis finite real number (i.e. an infinity and not a NaN), or ifzis a complex number whose real and imaginary parts are both finite.(finite? 3) ⇒ #t (finite? +inf.0) ⇒ #f (finite? 3.0+inf.0i) ⇒ #f
Return
#tifzis an infinite real number (+int.0or-inf.0), or ifzis a complex number where either real or imaginary parts or both are infinite.(infinite? 5.0) ⇒ #f (infinite? +inf.0) ⇒ #t (infinite? +nan.0) ⇒ #f (infinite? 3.0+inf.0i) ⇒ #t
For a real numer returns whether its is a NaN; for a complex number if the real or imaginary parts or both is a NaN.
(nan? +nan.0) ⇒ #t (nan? 32) ⇒ #f (nan? +nan.0+5.0i) ⇒ #t (nan? 1+2i) ⇒ #f
These procedures return the sum or product of their arguments.
(+ 3 4) ⇒ 7 (+ 3) ⇒ 3 (+) ⇒ 0 (+ +inf.0 +inf.0) ⇒ +inf.0 (+ +inf.0 -inf.0) ⇒ +nan.0 (* 4) ⇒ 4 (*) ⇒ 1 (* 5 +inf.0) ⇒ +inf.0 (* -5 +inf.0) ⇒ -inf.0 (* +inf.0 +inf.0) ⇒ +inf.0 (* +inf.0 -inf.0) ⇒ -inf.0 (* 0 +inf.0) ⇒ +nan.0 (* 0 +nan.0) ⇒ +nan.0 (* 1.0 0) ⇒ 0.0For any real number object
xthat is neither infinite nor NaN:(+ +inf.0x) ⇒ +inf.0 (+ -inf.0x) ⇒ -inf.0For any real number object
x:(+ +nan.0x) ⇒ +nan.0For any real number object
xthat is not an exact 0:(* +nan.0x) ⇒ +nan.0The behavior of
-0.0is illustrated by the following examples:(+ 0.0 -0.0) ⇒ 0.0 (+ -0.0 0.0) ⇒ 0.0 (+ 0.0 0.0) ⇒ 0.0 (+ -0.0 -0.0) ⇒ -0.0
With two or more arguments, this procedures returns the difference of its arguments, associating to the left. With one argument, however, it returns the negation (additive inverse) of its argument.
(- 3 4) ⇒ -1 (- 3 4 5) ⇒ -6 (- 3) ⇒ -3 (- +inf.0 +inf.0) ⇒ +nan.0The behavior of
-0.0is illustrated by the following examples:(- 0.0) ⇒ -0.0 (- -0.0) ⇒ 0.0 (- 0.0 -0.0) ⇒ 0.0 (- -0.0 0.0) ⇒ -0.0 (- 0.0 0.0) ⇒ 0.0 (- -0.0 -0.0) ⇒ 0.0
If all of the arguments are exact, then the divisors must all be nonzero. With two or more arguments, this procedure returns the quotient of its arguments, associating to the left. With one argument, however, it returns the multiplicative inverse of its argument.
(/ 3 4 5) ⇒ 3/20 (/ 3) ⇒ 1/3 (/ 0.0) ⇒ +inf.0 (/ 1.0 0) ⇒ +inf.0 (/ -1 0.0) ⇒ -inf.0 (/ +inf.0) ⇒ 0.0 (/ 0 0) ⇒ exception &assertion (/ 3 0) ⇒ exception &assertion (/ 0 3.5) ⇒ 0.0 (/ 0 0.0) ⇒ +nan.0 (/ 0.0 0) ⇒ +nan.0 (/ 0.0 0.0) ⇒ +nan.0If this procedure is applied to mixed non–rational real and non–real complex arguments, it either raises an exception with condition type
&implementation-restrictionor returns an unspecified number object.
These procedures implement number–theoretic integer division. They accept two real numbers
xandyas operands, whereymust be nonzero. In all cases the result is two valuesq(an integer) andr(a real) that satisfy the equations:x=q*y+rq=rounding-op(x/y)The result is inexact if either argument is inexact.
For
floor/therounding-opis thefloorfunction (below).(floor/ 123 10) ⇒ 12 3 (floor/ 123 -10) ⇒ -13 -7 (floor/ -123 10) ⇒ -13 7 (floor/ -123 -10) ⇒ 12 -3For
truncate/therounding-opis thetruncatefunction.(truncate/ 123 10) ⇒ 12 3 (truncate/ 123 -10) ⇒ -12 3 (truncate/ -123 10) ⇒ -12 -3 (truncate/ -123 -10) ⇒ 12 -3For
div-and-modtherounding-opis eitherfloor(ifyis positive) orceiling(ifyis negative). We have:0 <=r< |y|(div-and-mod 123 10) ⇒ 12 3 (div-and-mod 123 -10) ⇒ -12 3 (div-and-mod -123 10) ⇒ -13 7 (div-and-mod -123 -10) ⇒ 13 7For
div0-and-mod0therounding-opis theroundfunction, andrlies within a half–open interval centered on zero.-|y/2| <=r< |y/2|(div0-and-mod0 123 10) ⇒ 12 3 (div0-and-mod0 123 -10) ⇒ -12 3 (div0-and-mod0 -123 10) ⇒ -12 -3 (div0-and-mod0 -123 -10) ⇒ 12 -3 (div0-and-mod0 127 10) ⇒ 13 -3 (div0-and-mod0 127 -10) ⇒ -13 -3 (div0-and-mod0 -127 10) ⇒ -13 3 (div0-and-mod0 -127 -10) ⇒ 13 3The inconsistent naming is for historical reasons:
div-and-modanddiv0-and-mod0are from R6RS, whilefloor/andtruncate/are from R7RS.
Procedure: truncate-quotient x y
These procedures return the quotient part (first value) of respectively
floor/,truncate/,div-and-mod, anddiv0-and-mod0.
Procedure: floor-remainder x y
Procedure: truncate-remainder x y
These procedures return the remainder part (second value) of respectively
floor/,truncate/,div-and-mod, anddiv0-and-mod0.As a Kawa extension
ymay be zero, in which case the result isx:(mod 123 0) ⇒ 123 ;; Kawa extension
These are equivalent to
truncate-quotient,truncate-remainder, andfloor-remainder, respectively. These are provided for backward compatibility.(remainder 13 4) ⇒ 1 (remainder -13 4) ⇒ -1 (remainder 13 -4) ⇒ 1 (remainder -13 -4) ⇒ -1 (remainder -13 -4.0) ⇒ -1.0 (modulo 13 4) ⇒ 1 (modulo -13 4) ⇒ 3 (modulo 13 -4) ⇒ -4 (modulo -13 -4) ⇒ -1
Returns the absolute value of its argument.
(abs -7) ⇒ 7 (abs -inf.0) ⇒ +inf.0
These procedures return the greatest common divisor or least common multiple of their arguments. The result is always non–negative. The arguments must be integers; if an argument is inexact, so is the result.
(gcd 32 -36) ⇒ 4 (gcd) ⇒ 0 (lcm 32 -36) ⇒ 288 (lcm 32.0 -36) ⇒ 288.0 ; inexact (lcm) ⇒ 1
These procedures return the numerator or denominator of their argument; the result is computed as if the argument was represented as a fraction in lowest terms. The denominator is always positive. The denominator of
0is defined to be1. The arguments must be integers; if an argument is inexact, so is the result.(numerator (/ 6 4)) ⇒ 3 (denominator (/ 6 4)) ⇒ 2 (denominator (inexact (/ 6 4))) ⇒ 2.0
These procedures return inexact integer objects for inexact arguments that are not infinities or NaNs, and exact integer objects for exact rational arguments.
floorReturns the largest integer object not larger than
x.ceilingReturns the smallest integer object not smaller than
x.truncateReturns the integer object closest to
xwhose absolute value is not larger than the absolute value ofx.roundReturns the closest integer object to
x, rounding to even whenxrepresents a number halfway between two integers.If the argument to one of these procedures is inexact, then the result is also inexact. If an exact value is needed, the result should be passed to the
exactprocedure.Although infinities and NaNs are not integer objects, these procedures return an infinity when given an infinity as an argument, and a NaN when given a NaN.
(floor -4.3) ⇒ -5.0 (ceiling -4.3) ⇒ -4.0 (truncate -4.3) ⇒ -4.0 (round -4.3) ⇒ -4.0 (floor 3.5) ⇒ 3.0 (ceiling 3.5) ⇒ 4.0 (truncate 3.5) ⇒ 3.0 (round 3.5) ⇒ 4.0 (round 7/2) ⇒ 4 (round 7) ⇒ 7 (floor +inf.0) ⇒ +inf.0 (ceiling -inf.0) ⇒ -inf.0 (round +nan.0) ⇒ +nan.0
The
rationalizeprocedure returns a number object representing the simplest rational number differing fromx1 by no more thanx2.A rational number r_1 is simpler than another rational number r_2 if
r_1 = p_1/q_1andr_2 = p_2/q_2(in lowest terms) and|p_1| <= |p_2|and|q_1| <= |q_2|. Thus3/5is simpler than4/7.Although not all rationals are comparable in this ordering (consider
2/7and3/5) any interval contains a rational number that is simpler than every other rational number in that interval (the simpler2/5lies between2/7and3/5).Note that
0 = 0/1is the simplest rational of all.(rationalize (exact .3) 1/10) ⇒ 1/3 (rationalize .3 1/10) ⇒ #i1/3 ; approximately (rationalize +inf.0 3) ⇒ +inf.0 (rationalize +inf.0 +inf.0) ⇒ +nan.0The first two examples hold only in implementations whose inexact real number objects have sufficient precision.
These procedures compute the usual transcendental functions.
The
expprocedure computes the base–eexponential ofz. Thelogprocedure with a single argument computes the natural logarithm ofz(not the base–10 logarithm);(logcomputes the base–z1z2)z2 logarithm ofz1.The
asin,acos, andatanprocedures compute arcsine, arccosine, and arctangent, respectively. The two–argument variant ofatancomputes:(angle (make-rectangularx2x1))These procedures may return inexact results even when given exact arguments.
(exp +inf.0) ⇒ +inf.0 (exp -inf.0) ⇒ 0.0 (log +inf.0) ⇒ +inf.0 (log 0.0) ⇒ -inf.0 (log 0) ⇒ exception &assertion (log -inf.0) ⇒ +inf.0+3.141592653589793i ; approximately (atan -inf.0) ⇒ -1.5707963267948965 ; approximately (atan +inf.0) ⇒ 1.5707963267948965 ; approximately (log -1.0+0.0i) ⇒ 0.0+3.141592653589793i ; approximately (log -1.0-0.0i) ⇒ 0.0-3.141592653589793i ; approximately ; if -0.0 is distinguished
The hyperbolic functions.
Returns the square of
z. This is equivalent to(*.zz)(square 42) ⇒ 1764 (square 2.0) ⇒ 4.0
Returns the principal square root of
z. For rationalz, the result has either positive real part, or zero real part and non–negative imaginary part. The value of(sqrtcould be expressed as:z)e^((log z)/2)The
sqrtprocedure may return an inexact result even when given an exact argument.(sqrt -5) ⇒ 0.0+2.23606797749979i ; approximately (sqrt +inf.0) ⇒ +inf.0 (sqrt -inf.0) ⇒ +inf.0iNote that if the argument is a primitive number (such as
double) or an instance of the corresponding boxed class (such asjava.lang.Double) then we use the real-number version ofsqrt:(sqrt (->double -5)) ⇒ NaNThat is, we get different a result for
java.lang.Doubleandgnu.math.DFloNum, even for arguments that are numerically equal in the sense of=. This is so that the compiler can use thejava.lang.Math.sqrtmethod without object allocation when the argument is adouble(and because we wantdoubleandjava.lang.Doubleto behave consistently).
Procedure: exact-integer-sqrt k
The
exact-integer-sqrtprocedure returns two non–negative exact integer objects s and r whereandk= s^2 + r.k< (s+1)^2(exact-integer-sqrt 4) ⇒ 2 0 ; two return values (exact-integer-sqrt 5) ⇒ 2 1 ; two return values