bug in zend_multiply.h

From: Date: Tue, 09 Mar 2004 15:50:50 +0000
Subject: bug in zend_multiply.h
Groups: php.internals 
Request: Send a blank email to internals+get-8466@lists.php.net to get a copy of this message
This code fails on 64-bit archs because it relies on the accuracy of a double to be sufficient to represent LONG_MAX. The patch adresses it by checking for overflow by reversing the calculation instead of casting to a double and back to long. #include "build/php5-cvs/Zend/zend_multiply.h" #define LONG_MIN (1L << (8*sizeof(long)-1)) #define LONG_MAX ~LONG_MIN int main() { long res = 0; double d = 0; int overflow; /* obviously (LONG_MAX-1) * 1 can be represented by a long */ ZEND_SIGNED_MULTIPLY_LONG(LONG_MAX-1,1,res,d,overflow); printf("res: %ld/%.4f, %soverflow\n", result, d, overflow?"":"no "); return 0; } -- Ard

« previous php.internals (#8466) next »