# bug in zend_multiply.h

- Thread: https://externals.io/message/8466
- Original archive: https://news-web.php.net/php.internals/8466
- Started by Ard Biesheuvel on 2004-03-09T15:50:50+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #8466 — Ard Biesheuvel — 2004-03-09T15:50:50+00:00

URL: https://externals.io/message/8466#8466

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
