/** * Process flooring command * * @param Number\Number $number * @param Number\PositiveNumber $scale * * @return Number\Number */ public static function process(Number\Number $number, Number\PositiveNumber $scale) { $multiplier = Power::process(Number\Number::create(10), $scale, Number\PositiveNumber::create(0)); $number = Multiplication::process($number, $multiplier, Number\PositiveNumber::create(0)); $operand = Comparison::process($number, Number\Number::create(0), Number\PositiveNumber::create($scale))->getValue() == 1 ? Addition::process($number, Number\PositiveNumber::create(0), Number\PositiveNumber::create(0)) : Subtraction::process($number, Number\PositiveNumber::create(1), Number\PositiveNumber::create(0)); return Division::process($operand, $multiplier, $scale); }
/** * Process ceiling command * * @param Number\Number $number * @param Number\PositiveNumber $precision * @param Number\PositiveNumber $scale * * @return Number\Number */ public static function process(Number\Number $number, Number\PositiveNumber $precision, Number\PositiveNumber $scale) { if (Comparison::process($number, Number\Number::create(0), Number\PositiveNumber::create($scale))->getValue() == 1) { $floored = Flooring::process($number, $precision); $add = Number\PositiveNumber::create(0); if (Comparison::process($number, $floored, Number\PositiveNumber::create($scale))->getValue() == 1) { $add = Comparison::process($precision, Number\Number::create(0), Number\PositiveNumber::create($scale))->getValue() == 1 ? self::getSmallNumber($precision) : Number\PositiveNumber::create(1); } return Addition::process($number, $add, $precision); } return Subtraction::process($number, Number\Number::create(0), $precision); }
/** * Process rounding command * * @param Number\Number $number * @param Number\PositiveNumber $scale * * @return Number\Number */ public static function process(Number\Number $number, Number\PositiveNumber $scale) { $newScale = Addition::process($scale, Number\Number::create(1), Number\PositiveNumber::create(0)); return Comparison::process($number, Number\Number::create(0), Number\PositiveNumber::create($newScale))->getValue() >= 0 ? Addition::process($number, self::getSmallNumber(Number\PositiveNumber::create($scale)), $scale) : Subtraction::process($number, self::getSmallNumber(Number\PositiveNumber::create($scale)), $scale); }