From: Guillaume Marcais Date: 2005-04-05T03:06:44+09:00 Subject: Re: Math.sqrt(NaN) behaves differently on windows and linux On Tue, 2005-04-05 at 02:50 +0900, Berger, Daniel wrote: > From what I'm reading at > http://www.opengroup.org/onlinepubs/009695399/functions/sqrt.html, it > appears that in this case, Windows is, in fact, doing the right thing > (though see below). From the text: > > "For finite values of x < -0, a domain error shall occur, and either a > NaN (if supported), or an implementation-defined value shall be > returned." It seems to me that the the relevant part in the text is: "If x is NaN, a NaN shall be returned." So the *nix implementation is correct and the Windows one is not. > It looks to me like *nix is only returning NaN, but isn't actually > raising an error while Windows is raising an error, but is not returning > NaN. Well, there is a problem here between the way C and Ruby raise error. In C, the eerno variable is set and a specific value is returned. In Ruby, when an error is raised, the call doesn't return and the call stack is traversed to find the next rescue clause. So in Ruby, it will return NaN or raise an error, but never both. Guillaume.