[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How do I say a = inf in Lua?
- From: Rob Hoelz <rob@...>
- Date: Tue, 16 Dec 2008 12:30:55 -0600
"Daniel van Ham Colchete" <firstname.lastname@example.org> wrote:
> Hi yall!
> I've been doing some tests with infinite numbers. I couldn't find a
> reserved keyword for the infinite or minus infinite numbers. But,
> when Lua is using double floatint point as the number type they work.
> I just have to use something I know from the hardware: that 1e309 is
> infinite in double and that -1e309 is minus infinite in double
> precision. Look at some tests:
> > big = 1e309
> > small = -1e309
> > print(big, small)
> inf -inf
> > print ( 0 > big, -1 > big, 1 > big)
> false false false
> > print ( 0 > small, -1 > small, 1 > small)
> true true true
> > print (small > big)
> > print (big > small)
> So, it works the way it should. My question is related to the fact
> that 1e309 is not the most beautiful way of saying "inf". Is there
> any other way? Altough "print(big)" will say "inf" I can't do just
> "big = inf". So, when somebodyelse is reading my code he is going to
> ask: what the fudge is 1e309? Why can't it be 2e309 or 1e308? 1e308
> doesn't work because it is not infinite yet.
> Just a small joke: "Do you know what number is bigger than any other
> number? 1e309". He he, just made this one.
> I searched on Google, PIL and the list archive (since I joined) first.
> Best regards,
> Daniel Colchete
num = tonumber('inf') seems to work fine.