Skip to content

Instantly share code, notes, and snippets.

@shqking
Last active September 29, 2021 19:35
Show Gist options
  • Save shqking/0d55abf8dbaafde4a00ea9304e71f06b to your computer and use it in GitHub Desktop.
Save shqking/0d55abf8dbaafde4a00ea9304e71f06b to your computer and use it in GitHub Desktop.
PHP range.phpt issue: arm64 machine only
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 6345dd4ebb..98997fb493 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2782,6 +2782,7 @@ double_str:
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
for (i = 0, element = low; i < size && element <= high; ++i, element = low + (i * step)) {
+ printf("element %d-th: %.16f\n", i, element);
ZEND_HASH_FILL_SET_DOUBLE(element);
ZEND_HASH_FILL_NEXT();
}
<?php
var_dump( range(1, 2, 0.1) );
echo "Done\n";
?>

test command

./sapi/cli/php ./downsize-range.php

DEBUG mode

element 0-th: 1.0000000000000000
element 1-th: 1.1000000000000001
element 2-th: 1.2000000000000000
element 3-th: 1.3000000000000000
element 4-th: 1.3999999999999999
element 5-th: 1.5000000000000000
element 6-th: 1.6000000000000001
element 7-th: 1.7000000000000002    // different
element 8-th: 1.8000000000000000
element 9-th: 1.8999999999999999    // different
element 10-th: 2.0000000000000000
array(11) {
  [0]=>
  float(1)
  [1]=>
  float(1.1)
  [2]=>
  float(1.2)
  [3]=>
  float(1.3)
  [4]=>
  float(1.4)
  [5]=>
  float(1.5)
  [6]=>
  float(1.6)
  [7]=>
  float(1.7000000000000002)
  [8]=>
  float(1.8)
  [9]=>
  float(1.9)
  [10]=>
  float(2)
}
Done

RELEASE mode

element 0-th: 1.0000000000000000
element 1-th: 1.1000000000000001
element 2-th: 1.2000000000000000
element 3-th: 1.3000000000000000
element 4-th: 1.3999999999999999
element 5-th: 1.5000000000000000
element 6-th: 1.6000000000000001
element 7-th: 1.7000000000000000  // different
element 8-th: 1.8000000000000000
element 9-th: 1.9000000000000001  // different
element 10-th: 2.0000000000000000
array(11) {
  [0]=>
  float(1)
  [1]=>
  float(1.1)
  [2]=>
  float(1.2)
  [3]=>
  float(1.3)
  [4]=>
  float(1.4)
  [5]=>
  float(1.5)
  [6]=>
  float(1.6)
  [7]=>
  float(1.7)
  [8]=>
  float(1.8)
  [9]=>
  float(1.9000000000000001)
  [10]=>
  float(2)
}
Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment