From: Kristof Bastiaensen Date: 2004-09-02T05:40:23+09:00 Subject: Re: invisible Infinity On Thu, 02 Sep 2004 05:08:44 +0900, Mohammad Khan wrote: > On Wed, 2004-09-01 at 15:55, Kristof Bastiaensen wrote: >> On Thu, 02 Sep 2004 04:25:57 +0900, Mohammad Khan wrote: >> >> > On Wed, 2004-09-01 at 15:22, Mohammad Khan wrote: >> >> 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. >> > >> > I meant, >> > If I am wrong, correct me please. >> > >> > >> I am not sure if this is what you meant, but Infinity is not a string: >> >> (10.0/0).class >> => Float >> >> (10.0/0).to_s.class >> => String > > irb(main):001:0> a = 10.0/0 > => Infinity > irb(main):002:0> b = -20.0/0 > => -Infinity > > I said, Infinity and -Infinity is just a String representation of Float, > not a Constant. > So it is not what you meant then :-) It wasn't clear to me you where talking about irb output. Sorry for the confusion. > regards > Mohammad > > >> Regards, >> KB