lua-users home
lua-l archive

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

On Sun, Sep 19, 2010 at 20:11, KHMan <> wrote:
> On 9/20/2010 4:45 AM, HyperHacker wrote:
>> [snipped all]
>> Note that a number displayed as -0.0000 could also be a  very small
>> negative number rounded to fit the display, e.g.:
>>> =('%f'):format(-0.00000001)
>> -0.000000
>> %f rounds to six places by default. This is the proper meaning of
>> negative zero - a negative value that rounded to zero.
> The last sentence is wrong. No book on computer arithmetic discusses a
> negative zero in such a fashion. Do not mix negative zeros with rounding
> behaviour. It is misleading with respect to the standard use of the
> terminology.
>> It'd probably save you a lot of headache in the future to read up on
>> how floating-point works, as it has a lot of potential pitfalls.
> Ironic.
> --
> Cheers,
> Kein-Hong Man (esq.)
> Kuala Lumpur, Malaysia

Who's Mike?

I apologize for not taking the time to find a machine whose FPU
behaviour differs from mine, and for somehow writing an explanation
that manages to include too little and too much detail at the same
time. I can see how it must be difficult to scroll past a message you
don't feel like reading.

The point of my explanation was to explain why -0 is sometimes
generated and that it's not usually meaningful in computer
applications and safe to ignore, rather than wasting time performing a
deep investigation into why exactly one particular person's system
generates it in one particular situation.

I also took the time to point out that I can't confirm that Lua and/or
this user's system does in fact handle a -0 correctly since my own
system doesn't want to generate one, and that there *are* meanings for
-0 in some situations, such as when displaying a rounded value. (See - this page
also offers more explanation as to why -0 exists.) While it's true
that not all systems *will* display -0 for (or only for) a rounded
negative value, this *is* the intended meaning.

Sent from my toaster.