51    public function __construct(
$result, 
$range_min, 
$range_max, 
$tolerance, 
$unit, 
$formula, 
$points, 
$precision, 
$rating_simple = 
true, 
$rating_sign = 33, 
$rating_value = 34, 
$rating_unit = 33, 
$result_type = 0)
 
   54        #       $this->setRangeMin((is_numeric($range_min)) ? $range_min : NULL); 
   55        #       $this->setRangeMax((is_numeric($range_max)) ? $range_max : NULL); 
   80        if (preg_match_all(
"/(\\\$r\\d+)/ims", 
$formula, $matches)) {
 
   81            foreach ($matches[1] as 
$result) {
 
  101        $resultunits = array();
 
  102        if ($question_id > 0) {
 
  106        include_once 
"./Services/Math/classes/class.ilMath.php";
 
  107        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  109        if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  110            foreach ($matches[1] as $variable) {
 
  111                $varObj  = $variables[$variable];
 
  112                if (!is_object($varObj)) {
 
  115                $value   = $varObj->getBaseValue();
 
  116                $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $value . 
")" . 
"\\1", 
$formula);
 
  120        $math->suppress_errors = 
true;
 
  124        if (is_object($this->
getUnit())) {
 
  130        if ($use_precision == 
true) {
 
  143        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  146        while (
$i < 1000 && !$inRange) {
 
  148            if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  149                foreach ($matches[1] as $variable) {
 
  150                    $varObj = $variables[$variable];
 
  151                    if (!is_object($varObj)) {
 
  154                    $varObj->setRandomValue();
 
  155                    $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $varObj->getBaseValue() . 
")" . 
"\\1", 
$formula);
 
  159            $math->suppress_errors = 
true;
 
  161            $inRange               = (is_numeric(
$result)) ? 
true : 
false;
 
  182        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  185        for (
$i = 0; 
$i < 1000; 
$i++) {
 
  187            if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  188                foreach ($matches[1] as $variable) {
 
  189                    $varObj = $variables[$variable];
 
  190                    if (!is_object($varObj)) {
 
  193                    $varObj->setRandomValue();
 
  194                    $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $varObj->getBaseValue() . 
")" . 
"\\1", 
$formula);
 
  198            $math->suppress_errors = 
true;
 
  207        include_once 
"./Services/Math/classes/class.ilMath.php";
 
  208        if (is_object($this->
getUnit())) {
 
  226        if ($value === 
null || 0 == strlen($value)) {
 
  229        $value=str_replace(
' ', 
'', $value);
 
  231        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  232        include_once 
"./Services/Math/classes/class.ilMath.php";
 
  235        $check_valid_chars = 
true;
 
  237        if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  238            foreach ($matches[1] as $variable) {
 
  239                $varObj = $variables[$variable];
 
  240                if (!is_object($varObj)) {
 
  244                if ($varObj->getUnit() != 
null) {
 
  246                    if ($varObj->getUnit()->getBaseUnit() != -1) { #$this->
getUnit() != NULL)
 
  247                        $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
 
  249                        $tmp_value = $varObj->getValue();
 
  252                    $tmp_value = $varObj->getValue();
 
  255                $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $tmp_value . 
")" . 
"\\1", 
$formula);
 
  260        $math->suppress_errors = 
true;
 
  264        if (is_object($this->
getUnit())) {
 
  268            if ($this->
getUnit()->getBaseUnit() != -1) {
 
  275            if (!(
$unit->getFactor() == 1 && strlen(trim(
$unit->getFactor())) == 1)) {
 
  281        $has_valid_chars = preg_match(
"/^-?([0-9]*)(,|\\.|\\/){0,1}([0-9]*)([eE][\\+|-]([0-9])+)?$/", $value, $matches);
 
  282        if (!$has_valid_chars) {
 
  283            $check_valid_chars = 
false;
 
  285            (isset($matches[2]) && $matches[2] == 
'/') &&
 
  286            (isset($matches[4]) && strtolower($matches[4]) == 
"e") &&
 
  287            (!isset($matches[1]) || !strlen($matches[1]) || !isset($matches[3]) || !strlen($matches[3]) || $matches[3] == 0)) {
 
  288            $check_valid_chars = 
false;
 
  293                if (substr_count($value, 
'.') == 1 || substr_count($value, 
',') == 1) {
 
  295                    $frac_value = str_replace(
',', 
'.', $exp_val);
 
  297                    $frac_value = $value;
 
  302                if (substr_count($value, 
'/') >= 1) {
 
  303                    $check_fraction = 
false;
 
  305                    $check_fraction = 
true;
 
  311                $exp_val = explode(
'/', $value);
 
  312                if (count($exp_val) == 1) {
 
  314                    if (ilMath::_equals($frac_value, $resultWithRespectedUnit, $this->
getPrecision())) {
 
  315                        $check_fraction = 
true;
 
  317                        $check_fraction = 
false;
 
  321                    $frac_value = str_replace(
',', 
'.', $frac_value);
 
  323                    if (ilMath::_equals($frac_value, $resultWithRespectedUnit, $this->
getPrecision())) {
 
  324                        $check_fraction = 
true;
 
  328                        if (!self::isCoprimeFraction($exp_val[0], $exp_val[1])) {
 
  329                            $check_fraction = 
false;
 
  334                if (substr_count($value, 
'.') >= 1 || substr_count($value, 
',') >= 1) {
 
  335                    $check_fraction = 
false;
 
  341                if (substr_count($value, 
'.') == 1 || substr_count($value, 
',') == 1) {
 
  342                    $frac_value = str_replace(
',', 
'.', $value);
 
  343                } elseif (substr_count($value, 
'/') == 1) {
 
  344                    $exp_val = explode(
'/', $value);
 
  347                    $frac_value = $value;
 
  350                $check_fraction = 
true;
 
  354        if (is_object(
$unit)) {
 
  355            if (isset($frac_value)) {
 
  361        if (isset($frac_value)) {
 
  372        if (is_object($this->
getUnit())) {
 
  373            if (is_object(
$unit)) {
 
  374                if (
$unit->getId() != $this->getUnit()->getId()) {
 
  379        return $checkvalue && $checkunit && $check_fraction && $check_valid_chars;
 
  384        include_once 
"./Services/Math/classes/class.ilMath.php";
 
  388        if (($b1 <= $v1) && ($b2 >= $v1)) {
 
  397        if ((($v1 >= 0) && ($v2 >= 0)) || (($v1 <= 0) && ($v2 <= 0))) {
 
  415            include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  416            include_once 
"./Services/Math/classes/class.ilMath.php";
 
  419            if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  420                foreach ($matches[1] as $variable) {
 
  421                    $varObj = $variables[$variable];
 
  422                    if (!is_object($varObj)) {
 
  425                    if ($varObj->getUnit() != 
null) {
 
  427                        if ($varObj->getUnit()->getBaseUnit() != -1) {
 
  428                            $tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
 
  430                            $tmp_value = $varObj->getValue();
 
  433                        $tmp_value = $varObj->getValue();
 
  435                    $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $tmp_value . 
")" . 
"\\1", 
$formula);
 
  440            $math->suppress_errors = 
true;
 
  446                    if ((substr_count($value, 
'.') == 1) || (substr_count($value, 
',') == 1)) {
 
  448                        $frac_value = str_replace(
',', 
'.', $exp_val);
 
  450                        $frac_value = $value;
 
  452                    $check_fraction = 
true;
 
  455                    $exp_val = explode(
'/', $value);
 
  456                    if (count($exp_val) == 1) {
 
  459                            $check_fraction = 
true;
 
  461                            $check_fraction = 
false;
 
  466                            $check_fraction = 
true;
 
  471                    $exp_val = explode(
'/', $value);
 
  472                    if (count($exp_val) == 1) {
 
  473                        $check_fraction = 
false;
 
  476                        if (self::isCoprimeFraction($exp_val[0], $exp_val[1])) {
 
  477                            $check_fraction = 
true;
 
  483                    $check_fraction = 
true;
 
  488            if (is_object($this->
getUnit())) {
 
  490                if ($this->
getUnit()->getBaseUnit() != -1) {
 
  498            if (is_object(
$unit)) {
 
  499                if (isset($frac_value)) {
 
  510            if (is_object($this->
getUnit())) {
 
  511                $base1 = $units[
$unit];
 
  512                if (is_object($base1)) {
 
  513                    $base1 = $units[$base1->getBaseUnit()];
 
  515                $base2 = $units[$this->
getUnit()->getBaseUnit()];
 
  516                if (is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId()) {
 
  528                return array(
"points" => $this->
getPoints());
 
  530                return array(
"points" => 0);
 
  533            include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  534            include_once 
"./Services/Math/classes/class.ilMath.php";
 
  537            if (preg_match_all(
"/(\\\$v\\d+)/ims", 
$formula, $matches)) {
 
  538                foreach ($matches[1] as $variable) {
 
  539                    $varObj  = $variables[$variable];
 
  540                    $formula = preg_replace(
"/\\\$" . substr($variable, 1) . 
"(?![0-9]+)/", 
"(" . $varObj->getBaseValue() . 
")" . 
"\\1", 
$formula);
 
  544            $math->suppress_errors = 
true;
 
  546            if (is_object($this->
getUnit())) {
 
  549            if (is_object(
$unit)) {
 
  564            if (is_object($this->
getUnit())) {
 
  565                $base1 = $units[
$unit];
 
  566                if (is_object($base1)) {
 
  567                    $base1 = $units[$base1->getBaseUnit()];
 
  569                $base2 = $units[$this->
getUnit()->getBaseUnit()];
 
  570                if (is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId()) {
 
  576            $details[
'points'] = $totalpoints;
 
  604        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  606        $math->suppress_errors = 
true;
 
  619            if (is_object($this->
getUnit())) {
 
  620                include_once 
"./Services/Math/classes/class.ilMath.php";
 
  636        include_once 
"./Services/Math/classes/class.EvalMath.php";
 
  638        $math->suppress_errors = 
true;
 
  651            if (is_object($this->
getUnit())) {
 
  652                include_once 
"./Services/Math/classes/class.ilMath.php";
 
  751        $this->result_type = $a_result_type;
 
  786                        FROM il_qpl_qst_fq_res 
  787                        WHERE question_fi = %s 
  789            array(
'integer', 
'text'),
 
  790            array($a_qst_id, $a_result)
 
  795        return $row[
'result_type'];
 
  802        return $gcd == 1 ? true : 
false;
 
  807        $to_string   = (string) $decimal_value;
 
  808        $is_negative = strpos($to_string, 
'-') === 0;
 
  810            $decimal_value = substr($decimal_value, 1);
 
  816        $b = 1 / $decimal_value;
 
  821            $h1 = $a * $h1 + $h2;
 
  824            $k1 = $a * $k1 + $k2;
 
  827        } 
while ((abs($decimal_value - $h1 / $k1) > $decimal_value * 
$tolerance) || ($k1 < 0 || $b < 0));
 
  833            $checkResult = ($h1/$k1);
 
  837            $checkResult = ($h1/$k1)*-1;
 
  839        if ($to_string == $checkResult . 
'' || $checkResult . 
'' == 
$result) {
 
  842            return array($to_string,
$result);
 
  862                        SELECT * FROM il_qpl_qst_fq_res_unit  
  863                        WHERE question_fi = %s 
  871            $this->available_units[
$row[
'result']][] = 
$row[
'unit_fi'] ;
 
An exception for terminatinating execution or to throw for unit testing.
static _mul($left_operand, $right_operand, $scale=50)
static _div($left_operand, $right_operand, $scale=50)
static _sub($left_operand, $right_operand, $scale=50)
static _add($left_operand, $right_operand, $scale=50)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
foreach($_POST as $key=> $value) $res