Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
MathLib.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Calc\Libs
;
4
5
use
Bitrix\Bizproc\Calc\Arguments
;
6
use
Bitrix\Main\Localization\Loc
;
7
8
class
MathLib
extends
BaseLib
9
{
10
public
function
getFunctions
(): array
11
{
12
return
[
13
'abs'
=> [
14
'args'
=>
true
,
15
'func'
=>
'callAbs'
,
16
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_ABS_DESCRIPTION'
),
17
],
18
'intval'
=> [
19
'args'
=>
true
,
20
'func'
=>
'callIntval'
,
21
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_INTVAL_DESCRIPTION'
),
22
],
23
'floatval'
=> [
24
'args'
=>
true
,
25
'func'
=>
'callFloatval'
,
26
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_FLOATVAL_DESCRIPTION'
),
27
],
28
'min'
=> [
29
'args'
=>
true
,
30
'func'
=>
'callMin'
,
31
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_MIN_DESCRIPTION'
),
32
],
33
'max'
=> [
34
'args'
=>
true
,
35
'func'
=>
'callMax'
,
36
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_MAX_DESCRIPTION'
),
37
],
38
'rand'
=> [
39
'args'
=>
true
,
40
'func'
=>
'callRand'
,
41
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_RAND_DESCRIPTION'
),
42
],
43
'round'
=> [
44
'args'
=>
true
,
45
'func'
=>
'callRound'
,
46
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_ROUND_DESCRIPTION'
),
47
],
48
'ceil'
=> [
49
'args'
=>
true
,
50
'func'
=>
'callCeil'
,
51
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_CEIL_DESCRIPTION'
),
52
],
53
'floor'
=> [
54
'args'
=>
true
,
55
'func'
=>
'callFloor'
,
56
'description'
=>
Loc::getMessage
(
'BIZPROC_CALC_FUNCTION_FLOOR_DESCRIPTION'
),
57
],
58
];
59
}
60
61
public
function
callAbs
(
Arguments
$args)
62
{
63
return
abs((
float
)$args->
getFirstSingle
());
64
}
65
66
public
function
callRound
(
Arguments
$args)
67
{
68
$val = (float)$args->
getFirstSingle
();
69
$precision = (int)$args->
getSecond
();
70
71
return
round($val, $precision);
72
}
73
74
public
function
callCeil
(
Arguments
$args)
75
{
76
return
ceil((
double
)$args->
getFirstSingle
());
77
}
78
79
public
function
callFloor
(
Arguments
$args)
80
{
81
return
floor((
double
)$args->
getFirstSingle
());
82
}
83
84
public
function
callMin
(
Arguments
$args)
85
{
86
$array = array_filter($args->
getFlatArray
(),
static
fn($item) => is_scalar($item));
87
88
return
$array ? min($array) :
false
;
89
}
90
91
public
function
callMax
(
Arguments
$args)
92
{
93
$array = array_filter($args->
getFlatArray
(),
static
fn($item) => is_scalar($item));
94
95
return
$array ? max($array) :
false
;
96
}
97
98
public
function
callRand
(
Arguments
$args)
99
{
100
$min = (int)$args->
getFirstSingle
();
101
$max = (int)$args->
getSecondSingle
();
102
103
if
(!$max || !is_finite($max))
104
{
105
$max = mt_getrandmax();
106
}
107
108
if
($min > $max)
109
{
110
//$args->getParser()->setError('rand(): Argument #2 ($max) must be greater than or equal to argument #1 ($min)');
111
112
return
null
;
113
}
114
115
return
mt_rand($min, $max);
116
}
117
118
public
function
callIntval
(
Arguments
$args)
119
{
120
return
(
int
)$args->
getFirstSingle
();
121
}
122
123
public
function
callFloatval
(
Arguments
$args)
124
{
125
return
(
float
)$args->
getFirstSingle
();
126
}
127
}
Bitrix\Bizproc\Calc\Arguments
Definition
Arguments.php:6
Bitrix\Bizproc\Calc\Arguments\getFlatArray
getFlatArray()
Definition
Arguments.php:33
Bitrix\Bizproc\Calc\Arguments\getSecondSingle
getSecondSingle()
Definition
Arguments.php:65
Bitrix\Bizproc\Calc\Arguments\getSecond
getSecond()
Definition
Arguments.php:57
Bitrix\Bizproc\Calc\Arguments\getFirstSingle
getFirstSingle()
Definition
Arguments.php:49
Bitrix\Bizproc\Calc\Libs\BaseLib
Definition
BaseLib.php:6
Bitrix\Bizproc\Calc\Libs\MathLib
Definition
MathLib.php:9
Bitrix\Bizproc\Calc\Libs\MathLib\getFunctions
getFunctions()
Definition
MathLib.php:10
Bitrix\Bizproc\Calc\Libs\MathLib\callFloor
callFloor(Arguments $args)
Definition
MathLib.php:79
Bitrix\Bizproc\Calc\Libs\MathLib\callIntval
callIntval(Arguments $args)
Definition
MathLib.php:118
Bitrix\Bizproc\Calc\Libs\MathLib\callFloatval
callFloatval(Arguments $args)
Definition
MathLib.php:123
Bitrix\Bizproc\Calc\Libs\MathLib\callMax
callMax(Arguments $args)
Definition
MathLib.php:91
Bitrix\Bizproc\Calc\Libs\MathLib\callRound
callRound(Arguments $args)
Definition
MathLib.php:66
Bitrix\Bizproc\Calc\Libs\MathLib\callAbs
callAbs(Arguments $args)
Definition
MathLib.php:61
Bitrix\Bizproc\Calc\Libs\MathLib\callCeil
callCeil(Arguments $args)
Definition
MathLib.php:74
Bitrix\Bizproc\Calc\Libs\MathLib\callRand
callRand(Arguments $args)
Definition
MathLib.php:98
Bitrix\Bizproc\Calc\Libs\MathLib\callMin
callMin(Arguments $args)
Definition
MathLib.php:84
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Bizproc\Calc\Libs
Definition
ArrayLib.php:3
modules
bizproc
lib
Calc
Libs
MathLib.php
Создано системой
1.10.0