[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Detect negative zero (was Re: Infinity as index)
- From: "Liam Devine" <liamdevine@...>
- Date: Thu, 24 Apr 2014 18:27:47 +0100
On 24/04/14 17:15, Dirk Laurie wrote:
>
> The hardest test of all is to distinguish between 0 and -0.
> If you can improve on the following, please post.
>
> if x==0 and 1/x>0 then -- x is 0
> if x==0 and 1/x<0 then -- x is -0
>
binary32 small endian
$lua53 -e"local a = -0. print( (function(x) return x == 0 and
tostring(x):byte(1) == 45 end)(a))"
true
$ lua53 -e"local a = 0. print( (function(x) return x == 0 and
tostring(x):byte(1) == 45 end)(a))"
false
--
Liam
Attachment:
signature.asc
Description: OpenPGP digital signature