summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/gmp.php
blob: dae15975d05dbf4f64d5aa2a9c032e2531b63902 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

namespace Safe;

use Safe\Exceptions\GmpException;

/**
 * Calculates the binomial coefficient C(n, k).
 *
 * @param \GMP|string|int $n Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.
 * @param int $k
 * @return \GMP Returns the binomial coefficient C(n, k).
 * @throws GmpException
 *
 */
function gmp_binomial($n, int $k): \GMP
{
    error_clear_last();
    $result = \gmp_binomial($n, $k);
    if ($result === false) {
        throw GmpException::createFromPhpError();
    }
    return $result;
}


/**
 * Export a GMP number to a binary string
 *
 * @param \GMP|string|int $gmpnumber The GMP number being exported
 * @param int $word_size Default value is 1. The number of bytes in each chunk of binary data. This is mainly used in conjunction with the options parameter.
 * @param int $options Default value is GMP_MSW_FIRST | GMP_NATIVE_ENDIAN.
 * @return string Returns a string.
 * @throws GmpException
 *
 */
function gmp_export($gmpnumber, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string
{
    error_clear_last();
    $result = \gmp_export($gmpnumber, $word_size, $options);
    if ($result === false) {
        throw GmpException::createFromPhpError();
    }
    return $result;
}


/**
 * Import a GMP number from a binary string
 *
 * @param string $data The binary string being imported
 * @param int $word_size Default value is 1. The number of bytes in each chunk of binary data. This is mainly used in conjunction with the options parameter.
 * @param int $options Default value is GMP_MSW_FIRST | GMP_NATIVE_ENDIAN.
 * @return \GMP Returns a GMP number.
 * @throws GmpException
 *
 */
function gmp_import(string $data, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): \GMP
{
    error_clear_last();
    $result = \gmp_import($data, $word_size, $options);
    if ($result === false) {
        throw GmpException::createFromPhpError();
    }
    return $result;
}


/**
 *
 *
 * @param \GMP|string|int $seed The seed to be set for the gmp_random,
 * gmp_random_bits, and
 * gmp_random_range functions.
 *
 * Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.
 * @throws GmpException
 *
 */
function gmp_random_seed($seed): void
{
    error_clear_last();
    $result = \gmp_random_seed($seed);
    if ($result === false) {
        throw GmpException::createFromPhpError();
    }
}