Hi Timm,

I have an old Alpha PWS433 running FreeBSD which I use for this kind of stuff.

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

Use this for portability

#define LONG_MIN (1L << 8*sizeof(long)-1)
#define LONG_MAX ~LONG_MIN


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"); }

1) -ERR 2) -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)

The problem in your code wasn't the comparison per se, but the conversion from long to double and back. You will lose accuracy by doing that. The value you're converting started out as a long, didn't it ?


If it didn't, and you're converting a double of unknown magnitude, the accuracy wasn't there in the first place, and you can just test if it is strictly smaller than LONG_MAX.

--
Ard

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



Reply via email to