From: Dennis Ranke Date: 2003-12-24T22:01:53+09:00 Subject: Re: Ruby 1.8.1 preview4 Hi NaHi, > On your ruby, "-0.0" shoud be interpreted 0.0. Gotoken hacked and > told me that if I expect "-0.0" to be interpreted as negative zero > in ruby, > "echo 'main(){double a = 0; a = -a; puts(1/a < 0 ? "n" : "p");}' | > gcc -xc - && ./a.out" > must dump "n". May be "p" on your system? Yes, it's "p". > I can use "-1.0 / (1.0 / 0.0)" instead of "-0.0" for soap4r test. > How does this dump? > > $ ruby -e 'p(-1.0 / (1.0 / 0.0))' -0.0 and '1.0 / (-1.0 / (1.0 / 0.0))' is -Infinity > "float" in XML Schema Datatypes (and SOAP) is a single float. > Ruby's is double. So I try to "narrow"? the given double float > to single with > > d = given_double # e.g. 1.4e-45 > f = (/\A\0*\z/ =~ [d].pack("f")) ? 0.0 : d > sprintf("%.10g", f) # use this as a value of "float" > > Maybe I misunderstand something... > > $ ruby -e 'p([1.4e-45].pack("f"))' > > ? That correctly gives "1.4e-45", while [1.4e-45].pack('f') is "\000\000\000\000". Now, since the double is indeed converted to a single-precision float, this is a known limitation of the Playstation 2 hardware which doesn't support denormalized floats. The smallest (positive, non-zero) normalized float is 2**-126, and all results smaller than that just (silently) underflow to zero. The smallest positive non-zero single-precision float is exactly 2**-149, so you could change your code to: f = (d.abs < 2**-149) ? 0.0 : d >> Yes, and "unknown host" with "ping localhost", so i added localhost to >> my hosts file, which got rid of those errors... ;) > > :) Thanks. > > There shoudl be some architecture/settings where "localhost" is > not defined. But I don't know portable way to test server/client. Well, it seems that I was the only one to stumble across that up to now (and it was easily solved on my side), so I don't really think it is a big issue right now. Oh, it's the 24th... Merry Christmas, everyone :) -- exoticorn/farbrausch