lua-users home
lua-l archive

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


David Manura wrote:
> $ lua
> Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> > =math.max(0/0),math.min(0/0)
> nan     nan
> > =math.max(0/0,1),math.min(0/0,1)
> nan     nan
> > =math.max(1,0/0),math.min(1,0/0)
> 1       1
> 
> Is that behavior defined?  Should it be defined?

I've discovered that, too, while reimplementing it. I doubt it
would be useful in practice to have "perfect" NaN propagation
semantics for min/max. It needs extra effort in software to do
these checks -- with little payoff.

Even the hardware designers from Intel/AMD haven't bothered to
add the functionality. The SSE2 minsd/maxsd just propagate the
2nd operand if any operand is NaN:
  minsd(1, NaN) = maxsd(1, NaN) = NaN
  minsd(NaN, 1) = maxsd(NaN, 1) = 1

Few programs rely on perfect NaN propagation. This takes extra
care and mandates hand-crafted conditionals, anyway. IMHO a small
remark in the manual would suffice.

--Mike