lua-users home
lua-l archive

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


David Kastrup schrieb:
Tony Finch <dot@dotat.at> writes:

On 20 Sep 2010, at 09:18, David Kastrup <dak@gnu.org> wrote:


    Tony Finch <dot@dotat.at> writes:
It can happen if the rounding mode is towards negative
        infinity.
Please point out the line in question where this would apply.


There are lots of subtractions in the code.

Hogwash.  Here is the code again:

order = 3
elements = order * order
size = elements * elements

for i = 0, (size - 1) do
	r = math.floor(i / elements)
	c = math.floor(i % elements)
	b = math.floor(math.floor(math.floor(r / order) * order) +
math.floor(c / order))
	br = math.floor(r % order)
	bc = math.floor(c % order)
	print(string.format("i:%f r: %f c: %f b:%f br:%f bc:%f", i, r,
c,  b, br, bc))
end

The only subtraction is (size-1), and that is 80 rather than 0-.

It would be nice if you could try to help instead of flaming.

Being helpful is easier when you actually read what you are replying to.

I found in the listing of the output of the code under question in the mail from mjmogo@gmail.com at 19.09.2010 18:45 from the first line:

i:0.000000 r:0.000000 c:-0.000000 b:0.000000 br:-0.000000 bc:-0.000000

That does mean that c = math.floor(0 % 9)
was giving -0.000000
and br = math.floor(-0.000000 % 3)
was giving -0.000000
and bc = math.floor(-0.000000 % 9)
was giving -0.000000
on a Mac OS X 10.4.11 with lua 5.1.2, compiled in 2007.

In the meantime I installed version Lua 5.1.3 Copyright (C) 1994-2008 Lua.org, PUC-Rio on my Debian lenny and tried that expressions:
~$ lua
Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(math.floor(0 % 9))
0
> math.floor(-0.000000 % 3)
> print(math.floor(-0.000000 % 3))
0
> print(math.floor(0 % 9))
0
> print(math.floor(-0.000000 % 3))
0
> print(math.floor(-0.000000 % 9))
0
>

Obviously the simplest solution is tu update to Lua version 5.1.3 . But if you like to goad each other go ahead!

Regards BB