[Rd] sqrt(.Machine$double.xmax)^2 == Inf, but only on Windows in R

Pavel Krivitsky p@kr|v|t@ky @end|ng |rom un@w@edu@@u
Mon Apr 28 07:13:41 CEST 2025


Hello,

Under R 4.5.0 on Windows (x86-64), I get:

> sqrt(.Machine$double.xmax)^2
[1] Inf
> sqrt(.Machine$double.xmax)*sqrt(.Machine$double.xmax)
[1] Inf

On other hand on other platforms, including Debian Linux (x86-64), I
get:

d> sqrt(.Machine$double.xmax)^2
[1] 1.797693134862315508561e+308
d> sqrt(.Machine$double.xmax)*sqrt(.Machine$double.xmax)
[1] 1.797693134862315508561e+308

Windows is running inside a VirtualBox instance on the same host as
Linux. I don't have direct results from the MacOS platforms, but based
on the symptoms that had led me to investigate, the behaviour is as the
Linux.

Adding to the mystery, if I implement the same operation in C, e.g.,

library(inline)
sqrsqrt <- cfunction(sig = c(x = "numeric"), language = "C", "
  double sqrtx = sqrt(Rf_asReal(x));
  return Rf_ScalarReal(sqrtx*sqrtx);
")

R on Linux yields:

d> sqrsqrt(.Machine$double.xmax)
[1] 1.797693134862315508561e+308

i.e., the same number, whereas R on Windows yields:

d> sqrsqrt(.Machine$double.xmax)
[1] 1.797693134862315508804e+308

which is not Inf but not the same as Linux either.

Lastly, on both platforms,

d> sqrsqrt(.Machine$double.xmax) < .Machine$double.xmax
[1] TRUE

I am not sure if this is a bug, intended behaviour, or something else.

				Best Regards,
				Pavel


More information about the R-devel mailing list