From: Mohammad Khan Date: 2004-09-02T04:22:35+09:00 Subject: Re: invisible Infinity If you take a look in numeric.c /* * call-seq: * flt.to_s => string * * Returns a string containing a representation of self. As well as a * fixed or exponential form of the number, the call may return * ``NaN'', ``Infinity'', and * ``-Infinity''. */ static VALUE flo_to_s(flt) VALUE flt; { char buf[32]; char *fmt = "%.15g"; double value = RFLOAT(flt)->value; double avalue, d1, d2; if (isinf(value)) return rb_str_new2(value < 0 ? "-Infinity" : "Infinity"); else if(isnan(value)) return rb_str_new2("NaN"); avalue = fabs(value); if (avalue == 0.0) { fmt = "%.1f"; } else if (avalue < 1.0e-3) { d1 = avalue; while (d1 < 1.0) d1 *= 10.0; d1 = modf(d1, &d2); if (d1 == 0) fmt = "%.1e"; } else if (avalue >= 1.0e15) { d1 = avalue; while (d1 > 10.0) d1 /= 10.0; d1 = modf(d1, &d2); if (d1 == 0) fmt = "%.1e"; else fmt = "%.16e"; } else if ((d1 = modf(value, &d2)) == 0) { fmt = "%.1f"; } sprintf(buf, fmt, value); return rb_str_new2(buf); } Infinity and -Infinity is String and it is just a representation. It is definitely, not a Constant. I am wrong, correct me please. -- Mohammad On Wed, 2004-09-01 at 15:05, Brian Schroeder wrote: > On Wed, 01 Sep 2004 18:05:43 +0000, gabriele renzi wrote: > > > Hi gurus and nubys, > > > > I wonder, if you divide a Float by zero, you get Infinity: > > >> a=10.0/0 > > => Infinity > > > > > > and you can even write code using Infinity like: > > >> 0.upto(a) do |x| p x end > > 0 > > 1 > > 2 > > 3 > > .. > > > > but if you try to access it directly you can't: > > >> Infinity > > NameError: uninitialized constant Infinity > > from (irb):4 > > > > Should we be able to access Infinity directly? It seem a strange > > unexplicable behaviour to me, that it exists but is not normally > > accessible. > > > I also was surprised, that Infinity is no predefined constant, as I used > it in some algorithm where I needed to fill an Array with infinity, then > iteratively reducing the values. In these cases infinity is much better > than nil as a special value because it can be compared. > > So I declared 1.0/0.0 as Infinity and ready. But I regard it as against > the pols. > > Greetings, > > Brian -- Mohammad Khan Legal Computer Solutions, Inc.