Modulo strangeness?


  while($in > $num) {
    echo $in." ".($in % $num)."<br />";
	$in = floor($in / $num);
  }

$num = 62.
Fed in 13037446423978.


13037446423978 1  //Okay.... no? This should be... 8?
210281393935 -7 //Wait, whut? Modulus on 2 positives = negative???
3391635386 -32 //Uhm... no? Got the right division, but no.
54703796 18
882319 59
14230 32
229 43

i’m… at a loss. Ideas?

PHP_INT_MAX I would guess. :wink:

64bit System:


<?php
$start = PHP_INT_MAX;
$divisor = 62;

while($start > $divisor){
  echo $start, ' ', ($start % $divisor), PHP_EOL;
  $start = floor($start / $divisor);
}

/*
  9223372036854775807 7
  1.4876406511056E+17 44
  2.399420405009E+15 8
  38700329113049 5
  624198856662 34
  10067723494 0
  162382637 49
  2619074 8
  42243 21
  681 61
*/


<?php
$start = 13037446423978;
$divisor = 62;

while($start > $divisor){
  echo $start, ' ', ($start % $divisor), PHP_EOL;
  $start = floor($start / $divisor);
}

/*
  13037446423978 8
  210281393935 3
  3391635386 34
  54703796 18
  882319 59
  14230 32
  229 43
*/

32bit System:


<?php
$start = PHP_INT_MAX;
$divisor = 62;

while($start > $divisor){
  echo $start, ' ', ($start % $divisor), PHP_EOL;
  $start = floor($start / $divisor);
}

/*
  2147483647 1
  34636833 37
  558658 38
  9010 20
  145 21
*/


<?php
$start = 13037446423978;
$divisor = 62;

while($start > $divisor){
  echo $start, ' ', ($start % $divisor), PHP_EOL;
  $start = floor($start / $divisor);
}

/*
  13037446423978 -46
  210281393935 -7
  3391635386 -32
  54703796 18
  882319 59
  14230 32
  229 43
*/