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

• Subject: Re: Why do some math functions return -0
• From: bb <bblochl@...>
• Date: Mon, 20 Sep 2010 12:31:14 +0200

```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.

```
The Debian repository installs Lua 5.0.3 Copyright (C) 1994-2006 Tecgraf, PUC-Rio and in that version the %-operator is not working:
```~\$ lua
Lua 5.0.3  Copyright (C) 1994-2006 Tecgraf, PUC-Rio
> print(5 % 6)
stdin:1: `)' expected near `%'
>

```
I think that is just an "old" bug and the actual Lua version will do well. The result of Lua is tested by different persons on diefferent machines very often and reproducible with that minus sign. So there is no need for one try more.
```
```
So I tried the expression with JavaScript in the actual firefox browser. There is no minus sign at all!
```Check yourself:

<html><title>Lua-Test-Prog</title>
<head></head><body>
Lua-Test-Prog
<script type="text/javascript">
for (i = 0; i<80;i++) {
document.write("<br>"+i);
r = Math.floor(i / 9);
document.write("&nbsp;&nbsp;&nbsp;r = "+ r);
c = Math.floor(i % 9);
document.write("&nbsp;&nbsp;&nbsp;c = "+ c);
```
//document.write("&nbsp;&nbsp;&nbsp;Math.floor(Math.floor(r/3)*3) = "+ (Math.floor(Math.floor(r / 3) * 3)));
```b = Math.floor(Math.floor(Math.floor(r / 3) * 3) + Math.floor(c / 3));
document.write("&nbsp;&nbsp;&nbsp;b = "+ b);
br = Math.floor(r % 3);
document.write("&nbsp;&nbsp;&nbsp;br = "+ br);
bc = Math.floor(c % 3);
document.write("&nbsp;&nbsp;&nbsp;bc = "+ bc);
}
</script></body></html>

Please draw conclusions yourself.

Reagards BB

```