lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great John Hind once stated:
> If Egor's comment about Lua not requiring the IEEE standard but working 
> with any underlying float implementation is right, then Dirk's Glossary 
> is misleading in that the behaviour of zero and infinity would not 
> necessarily be as defined, even if Lua forces conformity with respect to 
> NaN (although a non-IEEE float implementation might not support NaN at 
> all).

  I have access to a system that has floating point math, but not IEEE 754
(having been implemented before the 1985 standard).  It's a software
implementation for the 6809 written by Microsoft [1].  Any division by 0
results in a runtime error ("?/0 ERROR"), unlike IEEE 754 [2].  A too large
value results again in a runtime error ("?OV ERROR") unlike IEEE 754 [3].

  The likelyhood of anyone coming into contact with a non-IEEE 754 floating
point system is very nearly nil these days (with the exception of legacy
systems where floating point was implemented prior to 1985, like the VAX
[4]).  So while Lua can work with non-IEEE 754 floating point, there very
well might be code out there that won't work on such a system.

> Should 0 // 0 result in NaN? (It results in an Error "attempt to divide 
> by zero" in the implementation I have to hand). Here is where it is 
> important to know that NaN is a value of number-float subtype rather 
> than number type. Might it be better (or at least more consistent) if 
> Lua trapped NaN after resolving an expression and raised the same error?

  IEEE 754 has verbiage about trapping NaNs but most systems (in my
experience) has such behavior disabled (allowable by the standard).  If you
are really concerned about it, you can enable such traps [5].

  -spc

[1]	The Tandy Color Computer.  Microsoft provided the built in BASIC.

[2]	x/0 where x != 0 results in +inf or -inf, depending upon the sign
	of x.  0/0 results in NaN.

[3]	Which ends up in either +inf or -inf.

[4]	The only system I can think where one might actually be able to
	compile and use Lua today.

[5]	Consult your systems manual for instructions on which functions to
	call.  These would be C functions, by the way.