/[guile]/guile/guile-core/doc/ref/scheme-data.texi
ViewVC logotype

Diff of /guile/guile-core/doc/ref/scheme-data.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39 by kryde, Fri Nov 14 20:53:22 2003 UTC revision 1.40 by mvo, Wed Nov 19 18:13:21 2003 UTC
# Line 98  other Scheme value.  In particular, @cod Line 98  other Scheme value.  In particular, @cod
98  number 0 (like in C and C++), and not the same as the ``empty list''  number 0 (like in C and C++), and not the same as the ``empty list''
99  (like in some Lisp dialects).  (like in some Lisp dialects).
100    
101  The @code{not} procedure returns the boolean inverse of its argument:  In C, the two Scheme boolean values are available as the two constants
102    @code{SCM_BOOL_T} for @code{#t} and @code{SCM_BOOL_F} for @code{#f}.
103    Care must be taken with the false value @code{SCM_BOOL_F}: it is not
104    false when used in C conditionals.  In order to test for it, use
105    @code{SCM_FALSEP} or @code{SCM_NFALSEP}.
106    
107  @rnindex not  @rnindex not
108  @deffn {Scheme Procedure} not x  @deffn {Scheme Procedure} not x
# Line 106  The @code{not} procedure returns the boo Line 110  The @code{not} procedure returns the boo
110  Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.  Return @code{#t} iff @var{x} is @code{#f}, else return @code{#f}.
111  @end deffn  @end deffn
112    
 The @code{boolean?} procedure is a predicate that returns @code{#t} if  
 its argument is one of the boolean values, otherwise @code{#f}.  
   
113  @rnindex boolean?  @rnindex boolean?
114  @deffn {Scheme Procedure} boolean? obj  @deffn {Scheme Procedure} boolean? obj
115  @deffnx {C Function} scm_boolean_p (obj)  @deffnx {C Function} scm_boolean_p (obj)
116  Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.  Return @code{#t} iff @var{obj} is either @code{#t} or @code{#f}.
117  @end deffn  @end deffn
118    
119    @rnindex SCM_BOOL_T
120    @deffn {C Macro} SCM_BOOL_T
121    Represents a value that is true in the Scheme sense.
122    @end deffn
123    
124    @rnindex SCM_BOOL_T
125    @deffn {C Macro} SCM_BOOL_F
126    Represents a value that is false in the Scheme sense.
127    @end deffn
128    
129    @rnindex SCM_FALSEP
130    @deffn {C Macro} SCM_FALSEP (SCM obj)
131    Return true in the C sense when @var{obj} is false in the Scheme
132    sense; return false in the C sense otherwise.
133    @end deffn
134    
135    @rnindex SCM_NFALSEP
136    @deffn {C Macro} SCM_NFALSEP (SCM obj)
137    Return true in the C sense when @var{obj} is true in the Scheme
138    sense; return false in the C sense otherwise.
139    @end deffn
140    
141  @node Numbers  @node Numbers
142  @section Numerical data types  @section Numerical data types
# Line 183  follows it, in the sense that every inte Line 205  follows it, in the sense that every inte
205  rational is also real, and every real number is also a complex number  rational is also real, and every real number is also a complex number
206  (but with zero imaginary part).  (but with zero imaginary part).
207    
208  Of these, Guile implements integers, reals and complex numbers as  In addition to the classification into integers, rationals, reals and
209  distinct types.  Rationals are implemented as regards the read syntax  complex numbers, Scheme also distinguishes between whether a number is
210  for rational numbers that is specified by R5RS, but are immediately  represented exactly or not.  For example, the result of
211  converted by Guile to the corresponding real number.  @m{2\sin(\pi/4),sin(pi/4)} is exactly @m{\sqrt{2},2^(1/2)} but Guile
212    can neither represent @m{\pi/4,pi/4} nor @m{\sqrt{2},2^(1/2)} exactly.
213    Instead, it stores an inexact approximation, using the C type
214    @code{double}.
215    
216    Guile can represent exact rationals of any magnitude, inexact
217    rationals that fit into a C @code{double}, and inexact complex numbers
218    with @code{double} real and imaginary parts.
219    
220  The @code{number?} predicate may be applied to any Scheme value to  The @code{number?} predicate may be applied to any Scheme value to
221  discover whether the value is any of the supported numerical types.  discover whether the value is any of the supported numerical types.
# Line 292  fractions @var{p}/@var{q}, where @var{p} Line 321  fractions @var{p}/@var{q}, where @var{p}
321  All rational numbers are also real, but there are real numbers that  All rational numbers are also real, but there are real numbers that
322  are not rational, for example the square root of 2, and pi.  are not rational, for example the square root of 2, and pi.
323    
324  Guile represents both real and rational numbers approximately using a  Guile can represent both exact and inexact rational numbers, but it
325  floating point encoding with limited precision.  Even though the actual  can not represent irrational numbers.  Exact rationals are represented
326  encoding is in binary, it may be helpful to think of it as a decimal  by storing the numerator and denominator as two exact integers.
327  number with a limited number of significant figures and a decimal point  Inexact rationals are stored as floating point numbers using the C
328  somewhere, since this corresponds to the standard notation for non-whole  type @code{double}.
329  numbers.  For example:  
330    Exact rationals are written as a fraction of integers.  There must be
331    no whitespace around the slash:
332    
333    @lisp
334    1/2
335    -22/7
336    @end lisp
337    
338    Even though the actual encoding of inexact rationals is in binary, it
339    may be helpful to think of it as a decimal number with a limited
340    number of significant figures and a decimal point somewhere, since
341    this corresponds to the standard notation for non-whole numbers.  For
342    example:
343    
344  @lisp  @lisp
345  0.34  0.34
# Line 313  by sufficient powers of 10 (or in fact, Line 355  by sufficient powers of 10 (or in fact,
355  100000000000000000.  In Guile's current incarnation, therefore, the  100000000000000000.  In Guile's current incarnation, therefore, the
356  @code{rational?} and @code{real?} predicates are equivalent.  @code{rational?} and @code{real?} predicates are equivalent.
357    
 Another aspect of this equivalence is that Guile currently does not  
 preserve the exactness that is possible with rational arithmetic.  
 If such exactness is needed, it is of course possible to implement  
 exact rational arithmetic at the Scheme level using Guile's arbitrary  
 size integers.  
   
 A planned future revision of Guile's numerical tower will make it  
 possible to implement exact representations and arithmetic for both  
 rational numbers and real irrational numbers such as square roots,  
 and in such a way that the new kinds of number integrate seamlessly  
 with those that are already implemented.  
358    
359  Dividing by an exact zero leads to a error message, as one might  Dividing by an exact zero leads to a error message, as one might
360  expect.  However, dividing by an inexact zero does not produce an  expect.  However, dividing by an inexact zero does not produce an
# Line 331  error.  Instead, the result of the divis Line 362  error.  Instead, the result of the divis
362  infinity, depending on the sign of the divided number.  infinity, depending on the sign of the divided number.
363    
364  The infinities are written @samp{+inf.0} and @samp{-inf.0},  The infinities are written @samp{+inf.0} and @samp{-inf.0},
365  respectibly.  This syntax is also recognized by @code{read} as an  respectivly.  This syntax is also recognized by @code{read} as an
366  extension to the usual Scheme syntax.  extension to the usual Scheme syntax.
367    
368  Dividing zero by zero yields something that is not a number at all:  Dividing zero by zero yields something that is not a number at all:
# Line 352  To test for the special values, use the Line 383  To test for the special values, use the
383    
384  @deffn {Scheme Procedure} real? obj  @deffn {Scheme Procedure} real? obj
385  @deffnx {C Function} scm_real_p (obj)  @deffnx {C Function} scm_real_p (obj)
386  Return @code{#t} if @var{obj} is a real number, else @code{#f}.  Return @code{#t} if @var{obj} is a real number, else @code{#f}.  Note
387  Note that the sets of integer and rational values form subsets  that the sets of integer and rational values form subsets of the set
388  of the set of real numbers, so the predicate will also be fulfilled  of real numbers, so the predicate will also be fulfilled if @var{obj}
389  if @var{obj} is an integer number or a rational number.  is an integer number or a rational number.
390  @end deffn  @end deffn
391    
392  @deffn {Scheme Procedure} rational? x  @deffn {Scheme Procedure} rational? x
393  @deffnx {C Function} scm_real_p (x)  @deffnx {C Function} scm_rational_p (x)
394  Return @code{#t} if @var{x} is a rational number, @code{#f}  Return @code{#t} if @var{x} is a rational number, @code{#f} otherwise.
395  otherwise.  Note that the set of integer values forms a subset of  Note that the set of integer values forms a subset of the set of
396  the set of rational numbers, i. e. the predicate will also be  rational numbers, i. e. the predicate will also be fulfilled if
397  fulfilled if @var{x} is an integer number.  Real numbers  @var{x} is an integer number.
398  will also satisfy this predicate, because of their limited  
399  precision.  Since Guile can not represent irrational numbers, every number
400    satisfying @code{real?} also satisfies @code{rational?} in Guile.
401    @end deffn
402    
403    @deffn {Scheme Procedure} rationalize x eps
404    @deffnx {C Function} scm_rationalize (x, eps)
405    Returns the @emph{simplest} rational number differing
406    from @var{x} by no more than @var{eps}.  
407    
408    As required by @acronym{R5RS}, @code{rationalize} returns only then an
409    exact result when both its arguments are exact.  Thus, you might need
410    to use @code{inexact->exact} on the arguments.
411    
412    @lisp
413    (rationalize (inexact->exact 1.2) 1/100)
414    @result{} 6/5
415    @end lisp
416    
417  @end deffn  @end deffn
418    
419  @deffn {Scheme Procedure} inf? x  @deffn {Scheme Procedure} inf? x
# Line 402  the imaginary part. Line 450  the imaginary part.
450  9.3-17.5i  9.3-17.5i
451  @end lisp  @end lisp
452    
453  Guile represents a complex number as a pair of numbers both of which are  Guile represents a complex number with a non-zero imaginary part as a
454  real, so the real and imaginary parts of a complex number have the same  pair of inexact rationals, so the real and imaginary parts of a
455  properties of inexactness and limited precision as single real numbers.  complex number have the same properties of inexactness and limited
456    precision as single inexact rational numbers.  Guile can not represent
457    exact complex numbers with non-zero imaginary parts.
458    
459  @deffn {Scheme Procedure} complex? x  @deffn {Scheme Procedure} complex? x
460  @deffnx {C Function} scm_number_p (x)  @deffnx {C Function} scm_number_p (x)
# Line 434  available, has no fractional part, and i Line 484  available, has no fractional part, and i
484  will only convert the latter value to the former when forced to do so by  will only convert the latter value to the former when forced to do so by
485  an invocation of the @code{inexact->exact} procedure.  an invocation of the @code{inexact->exact} procedure.
486    
487  @deffn {Scheme Procedure} exact? x  @deffn {Scheme Procedure} exact? z
488  @deffnx {C Function} scm_exact_p (x)  @deffnx {C Function} scm_exact_p (z)
489  Return @code{#t} if @var{x} is an exact number, @code{#f}  Return @code{#t} if the number @var{z} is exact, @code{#f}
490  otherwise.  otherwise.
491    
492    @lisp
493    (exact? 2)
494    @result{} #t
495    
496    (exact? 0.5)
497    @result{} #f
498    
499    (exact? (/ 2))
500    @result{} #t
501    @end lisp
502    
503  @end deffn  @end deffn
504    
505  @deffn {Scheme Procedure} inexact? x  @deffn {Scheme Procedure} inexact? z
506  @deffnx {C Function} scm_inexact_p (x)  @deffnx {C Function} scm_inexact_p (z)
507  Return @code{#t} if @var{x} is an inexact number, @code{#f}  Return @code{#t} if the number @var{z} is inexact, @code{#f}
508  else.  else.
509  @end deffn  @end deffn
510    
511  @deffn {Scheme Procedure} inexact->exact z  @deffn {Scheme Procedure} inexact->exact z
512  @deffnx {C Function} scm_inexact_to_exact (z)  @deffnx {C Function} scm_inexact_to_exact (z)
513  Return an exact number that is numerically closest to @var{z}.  Return an exact number that is numerically closest to @var{z}, when
514    there is one.  For inexact rationals, Guile returns the exact rational
515    that is numerically equal to the inexact rational.  Inexact complex
516    numbers with a non-zero imaginary part can not be made exact.
517    
518    @lisp
519    (inexact->exact 0.5)
520    @result{} 1/2
521    @end lisp
522    
523    The following happens because 12/10 is not exactly representable as a
524    @code{double} (on most platforms).  However, when reading a decimal
525    number that has been marked exact with the ``#e'' prefix, Guile is
526    able to represent it correctly.
527    
528    @lisp
529    (inexact->exact 1.2)  
530    @result{} 5404319552844595/4503599627370496
531    
532    #e1.2
533    @result{} 6/5
534    @end lisp
535    
536  @end deffn  @end deffn
537    
538  @c begin (texi-doc-string "guile" "exact->inexact")  @c begin (texi-doc-string "guile" "exact->inexact")
539  @deffn {Scheme Procedure} exact->inexact z  @deffn {Scheme Procedure} exact->inexact z
540    @deffnx {C Function} scm_exact_to_inexact (z)
541  Convert the number @var{z} to its inexact representation.  Convert the number @var{z} to its inexact representation.
542  @end deffn  @end deffn
543    
# Line 516  the number is exact Line 601  the number is exact
601  the number is inexact.  the number is inexact.
602  @end table  @end table
603    
604  If the exactness indicator is omitted, the integer is assumed to be exact,  If the exactness indicator is omitted, the number is exact unless it
605  since Guile's internal representation for integers is always exact.  contains a radix point.  Since Guile can not represent exact complex
606  Real numbers have limited precision similar to the precision of the  numbers, an error is signalled when asking for them.
607  @code{double} type in C.  A consequence of the limited precision is that  
608  all real numbers in Guile are also rational, since any number @var{r} with a  @lisp
609  limited number of decimal places, say @var{n}, can be made into an integer by  (exact? 1.2)
610  multiplying by @math{10^n}.  @result{} #f
611    
612    (exact? #e1.2)
613    @result{} #t
614    
615    (exact? #e+1i)
616    ERROR: Wrong type argument
617    @end lisp
618    
619  Guile also understands the syntax @samp{+inf.0} and @samp{-inf.0} for  Guile also understands the syntax @samp{+inf.0} and @samp{-inf.0} for
620  plus and minus infinity, respectively.  The value must be written  plus and minus infinity, respectively.  The value must be written
621  exactly as shown, that is, the always must have a sign and exactly one  exactly as shown, that is, they always must have a sign and exactly
622  zero digit after the decimal point.  It also understands @samp{+nan.0}  one zero digit after the decimal point.  It also understands
623  and @samp{-nan.0} for the special `not-a-number' value.  The sign is  @samp{+nan.0} and @samp{-nan.0} for the special `not-a-number' value.
624  ignored for `not-a-number' and the value is always printed as @samp{+nan.0}.  The sign is ignored for `not-a-number' and the value is always printed
625    as @samp{+nan.0}.
626    
627  @node Integer Operations  @node Integer Operations
628  @subsection Operations on Integer Values  @subsection Operations on Integer Values
# Line 557  otherwise. Line 650  otherwise.
650  @c begin (texi-doc-string "guile" "remainder")  @c begin (texi-doc-string "guile" "remainder")
651  @deffn {Scheme Procedure} quotient n d  @deffn {Scheme Procedure} quotient n d
652  @deffnx {Scheme Procedure} remainder n d  @deffnx {Scheme Procedure} remainder n d
653    @deffnx {C Function} scm_quotient (n, d)
654    @deffnx {C Function} scm_remainder (n, d)
655  Return the quotient or remainder from @var{n} divided by @var{d}.  The  Return the quotient or remainder from @var{n} divided by @var{d}.  The
656  quotient is rounded towards zero, and the remainder will have the same  quotient is rounded towards zero, and the remainder will have the same
657  sign as @var{n}.  In all cases quotient and remainder satisfy  sign as @var{n}.  In all cases quotient and remainder satisfy
# Line 570  sign as @var{n}.  In all cases quotient Line 665  sign as @var{n}.  In all cases quotient
665    
666  @c begin (texi-doc-string "guile" "modulo")  @c begin (texi-doc-string "guile" "modulo")
667  @deffn {Scheme Procedure} modulo n d  @deffn {Scheme Procedure} modulo n d
668    @deffnx {C Function} scm_modulo (n, d)
669  Return the remainder from @var{n} divided by @var{d}, with the same  Return the remainder from @var{n} divided by @var{d}, with the same
670  sign as @var{d}.  sign as @var{d}.
671    
# Line 583  sign as @var{d}. Line 679  sign as @var{d}.
679    
680  @c begin (texi-doc-string "guile" "gcd")  @c begin (texi-doc-string "guile" "gcd")
681  @deffn {Scheme Procedure} gcd  @deffn {Scheme Procedure} gcd
682    @deffnx {C Function} scm_gcd (x, y)
683  Return the greatest common divisor of all arguments.  Return the greatest common divisor of all arguments.
684  If called without arguments, 0 is returned.  If called without arguments, 0 is returned.
685    
686    The C function @code{scm_gcd} always takes two arguments, while the
687    Scheme function can take an arbitrary number.
688  @end deffn  @end deffn
689    
690  @c begin (texi-doc-string "guile" "lcm")  @c begin (texi-doc-string "guile" "lcm")
691  @deffn {Scheme Procedure} lcm  @deffn {Scheme Procedure} lcm
692    @deffnx {C Function} scm_lcm (x, y)
693  Return the least common multiple of the arguments.  Return the least common multiple of the arguments.
694  If called without arguments, 1 is returned.  If called without arguments, 1 is returned.
695    
696    The C function @code{scm_lcm} always takes two arguments, while the
697    Scheme function can take an arbitrary number.
698  @end deffn  @end deffn
699    
700    
# Line 600  If called without arguments, 1 is return Line 704  If called without arguments, 1 is return
704  @rnindex positive?  @rnindex positive?
705  @rnindex negative?  @rnindex negative?
706    
707    The C comparison functions below always takes two arguments, while the
708    Scheme functions can take an arbitrary number.  Also keep in mind that
709    the C functions return one of the Scheme boolean values
710    @code{SCM_BOOL_T} or @code{SCM_BOOL_F} which are both true as far as C
711    is concerned.  Thus, always write @code{SCM_NFALSEP (scm_num_eq_p (x,
712    y))} when testing the two Scheme numbers @code{x} and @code{y} for
713    equality, for example.
714    
715  @c begin (texi-doc-string "guile" "=")  @c begin (texi-doc-string "guile" "=")
716  @deffn {Scheme Procedure} =  @deffn {Scheme Procedure} =
717    @deffnx {C Function} scm_num_eq_p (x, y)
718  Return @code{#t} if all parameters are numerically equal.  Return @code{#t} if all parameters are numerically equal.
719  @end deffn  @end deffn
720    
721  @c begin (texi-doc-string "guile" "<")  @c begin (texi-doc-string "guile" "<")
722  @deffn {Scheme Procedure} <  @deffn {Scheme Procedure} <
723    @deffnx {C Function} scm_less_p (x, y)
724  Return @code{#t} if the list of parameters is monotonically  Return @code{#t} if the list of parameters is monotonically
725  increasing.  increasing.
726  @end deffn  @end deffn
727    
728  @c begin (texi-doc-string "guile" ">")  @c begin (texi-doc-string "guile" ">")
729  @deffn {Scheme Procedure} >  @deffn {Scheme Procedure} >
730    @deffnx {C Function} scm_gr_p (x, y)
731  Return @code{#t} if the list of parameters is monotonically  Return @code{#t} if the list of parameters is monotonically
732  decreasing.  decreasing.
733  @end deffn  @end deffn
734    
735  @c begin (texi-doc-string "guile" "<=")  @c begin (texi-doc-string "guile" "<=")
736  @deffn {Scheme Procedure} <=  @deffn {Scheme Procedure} <=
737    @deffnx {C Function} scm_leq_p (x, y)
738  Return @code{#t} if the list of parameters is monotonically  Return @code{#t} if the list of parameters is monotonically
739  non-decreasing.  non-decreasing.
740  @end deffn  @end deffn
741    
742  @c begin (texi-doc-string "guile" ">=")  @c begin (texi-doc-string "guile" ">=")
743  @deffn {Scheme Procedure} >=  @deffn {Scheme Procedure} >=
744    @deffnx {C Function} scm_geq_p (x, y)
745  Return @code{#t} if the list of parameters is monotonically  Return @code{#t} if the list of parameters is monotonically
746  non-increasing.  non-increasing.
747  @end deffn  @end deffn
748    
749  @c begin (texi-doc-string "guile" "zero?")  @c begin (texi-doc-string "guile" "zero?")
750  @deffn {Scheme Procedure} zero?  @deffn {Scheme Procedure} zero? z
751    @deffnx {C Function} scm_zero_p (z)
752  Return @code{#t} if @var{z} is an exact or inexact number equal to  Return @code{#t} if @var{z} is an exact or inexact number equal to
753  zero.  zero.
754  @end deffn  @end deffn
755    
756  @c begin (texi-doc-string "guile" "positive?")  @c begin (texi-doc-string "guile" "positive?")
757  @deffn {Scheme Procedure} positive?  @deffn {Scheme Procedure} positive? x
758    @deffnx {C Function} scm_positive_p (x)
759  Return @code{#t} if @var{x} is an exact or inexact number greater than  Return @code{#t} if @var{x} is an exact or inexact number greater than
760  zero.  zero.
761  @end deffn  @end deffn
762    
763  @c begin (texi-doc-string "guile" "negative?")  @c begin (texi-doc-string "guile" "negative?")
764  @deffn {Scheme Procedure} negative?  @deffn {Scheme Procedure} negative? x
765    @deffnx {C Function} scm_negative_p (x)
766  Return @code{#t} if @var{x} is an exact or inexact number less than  Return @code{#t} if @var{x} is an exact or inexact number less than
767  zero.  zero.
768  @end deffn  @end deffn
# Line 695  Return the complex number @var{x} * e^(i Line 815  Return the complex number @var{x} * e^(i
815    
816  @c begin (texi-doc-string "guile" "real-part")  @c begin (texi-doc-string "guile" "real-part")
817  @deffn {Scheme Procedure} real-part z  @deffn {Scheme Procedure} real-part z
818    @deffnx {C Function} scm_real_part (z)
819  Return the real part of the number @var{z}.  Return the real part of the number @var{z}.
820  @end deffn  @end deffn
821    
822  @c begin (texi-doc-string "guile" "imag-part")  @c begin (texi-doc-string "guile" "imag-part")
823  @deffn {Scheme Procedure} imag-part z  @deffn {Scheme Procedure} imag-part z
824    @deffnx {C Function} scm_imag_part (z)
825  Return the imaginary part of the number @var{z}.  Return the imaginary part of the number @var{z}.
826  @end deffn  @end deffn
827    
828  @c begin (texi-doc-string "guile" "magnitude")  @c begin (texi-doc-string "guile" "magnitude")
829  @deffn {Scheme Procedure} magnitude z  @deffn {Scheme Procedure} magnitude z
830    @deffnx {C Function} scm_magnitude (z)
831  Return the magnitude of the number @var{z}. This is the same as  Return the magnitude of the number @var{z}. This is the same as
832  @code{abs} for real arguments, but also allows complex numbers.  @code{abs} for real arguments, but also allows complex numbers.
833  @end deffn  @end deffn
834    
835  @c begin (texi-doc-string "guile" "angle")  @c begin (texi-doc-string "guile" "angle")
836  @deffn {Scheme Procedure} angle z  @deffn {Scheme Procedure} angle z
837    @deffnx {C Function} scm_angle (z)
838  Return the angle of the complex number @var{z}.  Return the angle of the complex number @var{z}.
839  @end deffn  @end deffn
840    
# Line 729  Return the angle of the complex number @ Line 853  Return the angle of the complex number @
853  @rnindex truncate  @rnindex truncate
854  @rnindex round  @rnindex round
855    
856    The C arithmetic functions below always takes two arguments, while the
857    Scheme functions can take an arbitrary number.  When you need to
858    invoke them with just one argument, for example to compute the
859    equivalent od @code{(- x)}, pass @code{SCM_UNDEFINED} as the second
860    one: @code{scm_difference (x, SCM_UNDEFINED)}.
861    
862  @c begin (texi-doc-string "guile" "+")  @c begin (texi-doc-string "guile" "+")
863  @deffn {Scheme Procedure} + z1 @dots{}  @deffn {Scheme Procedure} + z1 @dots{}
864    @deffnx {C Function} scm_sum (z1, z2)
865  Return the sum of all parameter values.  Return 0 if called without any  Return the sum of all parameter values.  Return 0 if called without any
866  parameters.  parameters.
867  @end deffn  @end deffn
868    
869  @c begin (texi-doc-string "guile" "-")  @c begin (texi-doc-string "guile" "-")
870  @deffn {Scheme Procedure} - z1 z2 @dots{}  @deffn {Scheme Procedure} - z1 z2 @dots{}
871    @deffnx {C Function} scm_difference (z1, z2)
872  If called with one argument @var{z1}, -@var{z1} is returned. Otherwise  If called with one argument @var{z1}, -@var{z1} is returned. Otherwise
873  the sum of all but the first argument are subtracted from the first  the sum of all but the first argument are subtracted from the first
874  argument.  argument.
# Line 744  argument. Line 876  argument.
876    
877  @c begin (texi-doc-string "guile" "*")  @c begin (texi-doc-string "guile" "*")
878  @deffn {Scheme Procedure} * z1 @dots{}  @deffn {Scheme Procedure} * z1 @dots{}
879    @deffnx {C Function} scm_product (z1, z2)
880  Return the product of all arguments.  If called without arguments, 1 is  Return the product of all arguments.  If called without arguments, 1 is
881  returned.  returned.
882  @end deffn  @end deffn
883    
884  @c begin (texi-doc-string "guile" "/")  @c begin (texi-doc-string "guile" "/")
885  @deffn {Scheme Procedure} / z1 z2 @dots{}  @deffn {Scheme Procedure} / z1 z2 @dots{}
886    @deffnx {C Function} scm_divide (z1, z2)
887  Divide the first argument by the product of the remaining arguments.  If  Divide the first argument by the product of the remaining arguments.  If
888  called with one argument @var{z1}, 1/@var{z1} is returned.  called with one argument @var{z1}, 1/@var{z1} is returned.
889  @end deffn  @end deffn
# Line 765  magnitude of a complex number, use @code Line 899  magnitude of a complex number, use @code
899    
900  @c begin (texi-doc-string "guile" "max")  @c begin (texi-doc-string "guile" "max")
901  @deffn {Scheme Procedure} max x1 x2 @dots{}  @deffn {Scheme Procedure} max x1 x2 @dots{}
902    @deffnx {C Function} scm_max (x1, x2)
903  Return the maximum of all parameter values.  Return the maximum of all parameter values.
904  @end deffn  @end deffn
905    
906  @c begin (texi-doc-string "guile" "min")  @c begin (texi-doc-string "guile" "min")
907  @deffn {Scheme Procedure} min x1 x2 @dots{}  @deffn {Scheme Procedure} min x1 x2 @dots{}
908    @deffnx {C Function} scm_min (x1, x2)
909  Return the minimum of all parameter values.  Return the minimum of all parameter values.
910  @end deffn  @end deffn
911    
912  @c begin (texi-doc-string "guile" "truncate")  @c begin (texi-doc-string "guile" "truncate")
913  @deffn {Scheme Procedure} truncate  @deffn {Scheme Procedure} truncate
914    @deffnx {C Function} scm_truncate_number (x)
915  Round the inexact number @var{x} towards zero.  Round the inexact number @var{x} towards zero.
916  @end deffn  @end deffn
917    
918  @c begin (texi-doc-string "guile" "round")  @c begin (texi-doc-string "guile" "round")
919  @deffn {Scheme Procedure} round x  @deffn {Scheme Procedure} round x
920    @deffnx {C Function} scm_round_number (x)
921  Round the inexact number @var{x} to the nearest integer.  When exactly  Round the inexact number @var{x} to the nearest integer.  When exactly
922  halfway between two integers, round to the even one.  halfway between two integers, round to the even one.
923  @end deffn  @end deffn
924    
925  @c begin (texi-doc-string "guile" "floor")  @c begin (texi-doc-string "guile" "floor")
926  @deffn {Scheme Procedure} floor x  @deffn {Scheme Procedure} floor x
927    @deffnx {C Function} scm_floor (x)
928  Round the number @var{x} towards minus infinity.  Round the number @var{x} towards minus infinity.
929  @end deffn  @end deffn
930    
931  @c begin (texi-doc-string "guile" "ceiling")  @c begin (texi-doc-string "guile" "ceiling")
932  @deffn {Scheme Procedure} ceiling x  @deffn {Scheme Procedure} ceiling x
933    @deffnx {C Function} scm_ceiling (x)
934  Round the number @var{x} towards infinity.  Round the number @var{x} towards infinity.
935  @end deffn  @end deffn
936    
 C functions for some of the above rounding functions are provided by  
 the standard C mathematics library.  Naturally these expect and return  
 @code{double} arguments (@pxref{Rounding Functions,,, libc, GNU C  
 Library Reference Manual}).  
   
 @multitable {xx} {Scheme Procedure} {C Function}  
 @item @tab Scheme Procedure @tab C Function  
 @item @tab @code{floor}     @tab @code{floor}  
 @item @tab @code{ceiling}   @tab @code{ceil}  
 @item @tab @code{truncate}  @tab @code{trunc}  
 @end multitable  
   
 @code{trunc} is C99 standard and might not be available on older  
 systems.  Guile provides an @code{scm_truncate} equivalent (on all  
 systems), plus a C level version of the Scheme @code{round} procedure.  
   
 @deftypefn {C Function} double scm_truncate (double x)  
 @deftypefnx {C Function} double scm_round (double x)  
 @end deftypefn  
   
937    
938  @node Scientific  @node Scientific
939  @subsection Scientific Functions  @subsection Scientific Functions
# Line 1073  be seen that adding 6 (binary 110) to su Line 1193  be seen that adding 6 (binary 110) to su
1193  zeros.  zeros.
1194    
1195  @deffn {Scheme Procedure} logand n1 n2 @dots{}  @deffn {Scheme Procedure} logand n1 n2 @dots{}
1196    @deffnx {C Function} scm_logand (n1, n2)
1197  Return the bitwise @sc{and} of the integer arguments.  Return the bitwise @sc{and} of the integer arguments.
1198    
1199  @lisp  @lisp
# Line 1083  Return the bitwise @sc{and} of the integ Line 1204  Return the bitwise @sc{and} of the integ
1204  @end deffn  @end deffn
1205    
1206  @deffn {Scheme Procedure} logior n1 n2 @dots{}  @deffn {Scheme Procedure} logior n1 n2 @dots{}
1207    @deffnx {C Function} scm_logior (n1, n2)
1208  Return the bitwise @sc{or} of the integer arguments.  Return the bitwise @sc{or} of the integer arguments.
1209    
1210  @lisp  @lisp
# Line 1093  Return the bitwise @sc{or} of the intege Line 1215  Return the bitwise @sc{or} of the intege
1215  @end deffn  @end deffn
1216    
1217  @deffn {Scheme Procedure} logxor n1 n2 @dots{}  @deffn {Scheme Procedure} logxor n1 n2 @dots{}
1218    @deffnx {C Function} scm_loxor (n1, n2)
1219  Return the bitwise @sc{xor} of the integer arguments.  A bit is  Return the bitwise @sc{xor} of the integer arguments.  A bit is
1220  set in the result if it is set in an odd number of arguments.  set in the result if it is set in an odd number of arguments.
1221    

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26