Skip to content
Prev 9751 / 398500 Next

testing for integer

Faheem Mitha <faheem at email.unc.edu> writes:
Generally the S languages do not encourage distinguishing between
floating point and integer values at the level of S code.  The way the
values are stored should not be important to the user unless the user
is going to call C or Fortran code in which case you really do want to
use as.integer.  If you prefer not to get truncation then I would
suggest using as.integer(round(n)).

A more common way of writing the function would be

  n <- as.numeric(n)[1]
  r <- as.numeric(r)[1]
  if( n <= 0 || r < 0 ) stop("n must be positive and r non-negative")
  .C("choose", as.integer(round(n)), as.integer(round(r)), comb = double(1))$comb

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._