File: gmp_setbit_long.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (45 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--TEST--
gmp_setbit() with large index
--EXTENSIONS--
gmp
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
<?php if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); ?>
<?php
    /* This test requires about 8G RAM which likely not to be present on an arbitrary CI. */
    if (!file_exists("/proc/meminfo")) {
        die("skip cannot determine free memory amount.");
    }
    $s = file_get_contents("/proc/meminfo");
    $free = 0;
    if (preg_match(",MemFree:\s+(\d+)\s+kB,", $s, $m)) {
        /* Got amount in kb. */
        $free = $m[1]/1024/1024;
    }
    if ($free < 8) {
        die("skip not enough free RAM.");
    }
?>
--FILE--
<?php

$n = gmp_init("227200");
for($a = 1<<30; $a > 0 && $a < 0x8000000000; $a <<= 2) {
    $i = $a - 1;
    printf("%X\n", $i);
    try {
        gmp_setbit($n, $i, 1);
    } catch (\ValueError $e) {
        echo $e->getMessage() . \PHP_EOL;
    }
}
echo "Done\n";
?>
--EXPECTF--
3FFFFFFF
FFFFFFFF
3FFFFFFFF
FFFFFFFFF
3FFFFFFFFF
gmp_setbit(): Argument #2 ($index) must be less than %d * %d
Done