# [PATCH] Extend bitwise and modulus operators on 32-bit platforms

- Thread: https://externals.io/message/43371
- Original archive: https://news-web.php.net/php.internals/43371
- Started by Matt Wilmas on 2009-03-16T18:00:30+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #43371 — Matt Wilmas — 2009-03-16T18:00:30+00:00

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

Hi all,

I changed the bitwise and modulus operator functions to [try to] make them 
more consistent with behavior on 64-bit platforms.  By accepting double 
operands and, if necessary, returning a double, their usable range is 
greatly extended without running into overflow issues, etc.  (Of course, at 
some point, double precision would be a problem, but that's not till... the 
trillion range/40-ish bits or so?)  See also Bug #46579 (% integer 
overflow - no error message).

That means anything like this previously only-64-bit code works as expected:

var_dump(((1 << 40) | (1 << 36)) % (10000000000 >> 1));
> float(3231104512)

Fairly straightforward changes after adding a couple macros...  Adding 
zendi_convert_to_double() to the other zendi_* ones seemed to be the easiest 
way to handle things.  And, am I right to assume that most all modern 
compilers have a 64-bit long type?  If not, code is unchanged from before 
(same for 64-bit).

This is mostly independent of whatever is done as far as general "double to 
long conversion," but it does take care of the orginal issue I had. :-) 
http://marc.info/?l=php-internals&m=120799720922202&w=2

Patches:
http://realplain.com/php/64bit_operators.diff
http://realplain.com/php/64bit_operators_5_3.diff

What do you all think?


Thanks,
Matt

---

## #43395 — Hannes Magnusson — 2009-03-18T18:47:22+00:00

URL: https://externals.io/message/43371#43395 · In reply to: #43371

2009/3/16 Matt Wilmas <php_lists@realplain.com>:
> That means anything like this previously only-64-bit code works as expected:
[...]
> What do you all think?

+1

-Hannes
