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.
Tests whether it is not an infinity and not a NaN.
(finite? 3) ⇒ #t (finite? +inf.0) ⇒ #t
Tests whether it is an infinity.
(infinite? 5.0) ⇒ #f (infinite? +inf.0) ⇒ #t
Tests whether it is a NaN.
(nan? +nan.0) ⇒ #t (nan? 32) ⇒ #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
x1andx2as operands, wherex2must be nonzero. (Kawa allowsx2to be zero formod.)divreturns an integer, andmodreturns a real. Their results are specified by:(divx1x2) ⇒nd(modx1x2) ⇒xmsuch that:
x1=nd*x2+xm0 <=xm< |x2|(div-and-modx1x2) ⇒ (values (divx1x2) (modx1x2))(div 123 10) ⇒ 12 (mod 123 10) ⇒ 3 (div 123 -10) ⇒ -12 (mod 123 -10) ⇒ 3 (div -123 10) ⇒ -13 (mod -123 10) ⇒ 7 (div -123 -10) ⇒ 13 (mod -123 -10) ⇒ 7 (mod 123 0) ⇒ 123 ;; Kawa extension
Procedure: div0-and-mod0 x1x2
div0andmod0are likedivandmod, except the result ofmod0lies within a half–open interval centered on zero. The results are specified by:(div0x1x2) ⇒nd(mod0x1x2) ⇒xmsuch that:
x1=nd*x2+xm-|x2| <=xm< |x2/2|(div0-and-mod0x1x2) ⇒ (values (div0x1x2) (mod0x1x2))(div0 123 10) ⇒ 12 (mod0 123 10) ⇒ 3 (div0 123 -10) ⇒ -12 (mod0 123 -10) ⇒ 3 (div0 -123 10) ⇒ -12 (mod0 -123 10) ⇒ -3 (div0 -123 -10) ⇒ 12 (mod0 -123 -10) ⇒ -3
Kawa generalizes
quotientto arbitrary real numbers, using the definition:(truncate (/ x y)).
Generalized to arbitrary real numbers, using the definition:
(- x (* y (truncate (/ x y)))). Ifyis0, the result isx- i.e. we take(* 0 (quotient x 0))to be0. The result is inexact if either argument is inexact, even ifxis exact andyis 0.(remainder 13 4) ⇒ 1 (remainder -13 4) ⇒ -1 (remainder 13 -4) ⇒ 1 (remainder -13 -4) ⇒ -1 (remainder -13 -4.0) ⇒ -1.0
Generalized to arbitrary real numbers, using the definition:
(- x (* y (floor (/ x y)))). Ifyis0, the result isx. The result is inexact if either argument is inexact, even ifxis exact andyis 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. (R6RS allows inexact integer arguments; Kawa does not.)
(gcd 32 -36) ⇒ 4 (gcd) ⇒ 0 (lcm 32 -36) ⇒ 288 (lcm 32.0 -36) ⇒ 288.0 (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. (R6RS allows inexact integer arguments; Kawa does not.)(numerator (/ 6 4)) ⇒ 3 (denominator (/ 6 4)) ⇒ 2
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 fromx1by 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)z2logarithm 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
Return 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.0i
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