On Oct 20, 2011, at 1:45 AM, Lei Jiang wrote:

When using power operator ^, both the base and index are coerced to type
"real". The range of "real" is larger than "integer".

However, an ordinary multiplication operator * offers it to two integers (as
always).

So, to avoid the warning, just add "as.real(...)" to one or both multipliers (once one multiplier is "real", the other must be coerced to "real" in the
operation):

sum(1000:1205)*as.real(sum(1000:1205))
[1] 51581223225

That does seem to be an infelicity that ought to be fixed. Using the infix addition operator does that same sort of coercions, so why would one expect the infix multiplication operator to refuse to do it?

> (sum(1000:1205))*(sum(1000:1204) +1205)
[1] 51581223225

>  (sum(1000:1205))*(sum(1000:1204) +0)
[1] 51307549650

--
David.

HTH,
Lei


On Wed, Oct 19, 2011 at 7:44 PM, Lafaye de Micheaux Pierre <
laf...@dms.umontreal.ca> wrote:

Dear gentlemen,

Can you explain me why the following happens (any OS I think, and even on
64 bits)?

sum(1000:1205)^2
[1] 51581223225
sum(1000:1205)*sum(1000:1205)
[1] NA
Warning message:
In sum(1000:1205) * sum(1000:1205) : NAs produced by integer overflow

Best,

Pierre

--
Pierre Lafaye de Micheaux
Adresse courrier:
Département de Mathématiques et Statistique
Université de Montréal
CP 6128, succ. Centre-ville
Montréal, Québec H3C 3J7
CANADA

Adresse physique:
Département de Mathématiques et Statistique
Bureau 4249, Pavillon André-Aisenstadt
2920, chemin de la Tour
Montréal, Québec H3T 1J4
CANADA

Tél.: (00-1) 514-343-6607 / Fax: (00-1) 514-343-5700
laf...@dms.umontreal.ca
http://www.biostatisticien.eu

______________________________**________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help >
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html <http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.




--
Lei Jiang

Center for Computation and Technology/
Department of Computer Science
Louisiana State University

E-mail: lji...@cct.lsu.edu

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to