On Sat, 2004-05-15 at 20:11, Ard Biesheuvel wrote:
[...LONG_MIN / LONG_MAX comparison]
> Hi Timm,
> 
> I think this code is broken on 64-bit archs, as doubles lack the 
> precision to accurately represent a 64-bit long. Also, comparing double 
> values with LONG_[MIN|MAX] is dangerous for the same reason.

Ard, sorry, I don't have any 64-bit machines available to me:) Do you
(or does anybody else) have one?

If so, what does this print?
--------------------------------------------------------------------------
#define LONG_MAX 2147483647L
#define LONG_MIN (- LONG_MAX - 1)

int main(int argc, char* argv)
{
    printf("1) %s\n", (double)LONG_MAX + 1 > LONG_MAX ? "+OK" : "-ERR");
    printf("2) %s\n", (double)LONG_MIN - 1 < LONG_MIN ? "+OK" : "-ERR");
}
--------------------------------------------------------------------------

I thought this code was OK by looking at the following:

Zend/zend_operators.c:#define DVAL_TO_LVAL(d, l) (l) = (d) > LONG_MAX ?
(unsigned long) (d) : (long) (d)

If it's not [OK], what alternatives exist?

- Timm

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to