Skip to content
Prev 63016 / 63424 Next

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

On 4/29/25 12:00, Martin Maechler wrote:
This depends on C math function sqrt. With sqrt implemented in mingw-w64 
(mingwex), which is still the case of mingw-w64 v11, so still of 
Rtools45, the result of sqrt(.Machine$double.xmax) is

"0x1p+512"

with mingw-w64 v12 (so with UCRT, and also on Linux, and also using mpfr 
library) it is

"0x1.fffffffffffffp+511"

It is not required by any standard for the math functions in the C math 
library to be precise (correctly rounded). But still, in this case, the 
correctly rounded value would be returned once Rtools can switch to 
mingw-w64 v12 (which could be no sooner than Rtools46, as mingw-w64 is a 
core component of the toolchain).

A bit of advertising -? I used Martin's Rmpfr package to compute this 
using mpfr.
And there is a related blog post: 
https://blog.r-project.org/2025/04/24/sensitivity-to-c-math-library-and-mingw-w64-v12

Best
Tomas