ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Operations.php
Go to the documentation of this file.
1<?php
2
4
7
9{
18 public static function mod($dividend, $divisor)
19 {
20 try {
21 $dividend = Helpers::validateNumericNullBool($dividend);
22 $divisor = Helpers::validateNumericNullBool($divisor);
24 } catch (Exception $e) {
25 return $e->getMessage();
26 }
27
28 if (($dividend < 0.0) && ($divisor > 0.0)) {
29 return $divisor - fmod(abs($dividend), $divisor);
30 }
31 if (($dividend > 0.0) && ($divisor < 0.0)) {
32 return $divisor + fmod($dividend, abs($divisor));
33 }
34
35 return fmod($dividend, $divisor);
36 }
37
48 public static function power($x, $y)
49 {
50 try {
53 } catch (Exception $e) {
54 return $e->getMessage();
55 }
56
57 // Validate parameters
58 if (!$x && !$y) {
59 return Functions::NAN();
60 }
61 if (!$x && $y < 0.0) {
62 return Functions::DIV0();
63 }
64
65 // Return
66 $result = $x ** $y;
67
69 }
70
83 public static function product(...$args)
84 {
85 // Return value
86 $returnValue = null;
87
88 // Loop through arguments
89 foreach (Functions::flattenArray($args) as $arg) {
90 // Is it a numeric value?
91 if (is_numeric($arg)) {
92 if ($returnValue === null) {
93 $returnValue = $arg;
94 } else {
95 $returnValue *= $arg;
96 }
97 } else {
98 return Functions::VALUE();
99 }
100 }
101
102 // Return
103 if ($returnValue === null) {
104 return 0;
105 }
106
107 return $returnValue;
108 }
109
124 public static function quotient($numerator, $denominator)
125 {
126 try {
127 $numerator = Helpers::validateNumericNullSubstitution($numerator, 0);
128 $denominator = Helpers::validateNumericNullSubstitution($denominator, 0);
129 Helpers::validateNotZero($denominator);
130 } catch (Exception $e) {
131 return $e->getMessage();
132 }
133
134 return (int) ($numerator / $denominator);
135 }
136}
$result
An exception for terminatinating execution or to throw for unit testing.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
static validateNumericNullBool($number)
Many functions accept null/false/true argument treated as 0/0/1.
Definition: Helpers.php:27
static validateNotZero($number)
Confirm number != 0.
Definition: Helpers.php:97
static numberOrNan($result)
Return NAN or value depending on argument.
Definition: Helpers.php:125
static validateNumericNullSubstitution($number, $substitute)
Validate numeric, but allow substitute for null.
Definition: Helpers.php:51
static quotient($numerator, $denominator)
QUOTIENT.
Definition: Operations.php:124
$x
Definition: complexTest.php:9
$y
Definition: example_007.php:83