/** * Returns a QuantityValue representing the given amount, automatically assuming * a level of uncertainty based on the digits given. * * The upper and lower bounds are determined automatically from the given * digits by increasing resp. decreasing the least significant digit. * E.g. "+0.01" would have upperBound "+0.02" and lowerBound "+0.01", * while "-100" would have upperBound "-99" and lowerBound "-101". * * @param DecimalValue $amount The quantity * @param string $unit The quantity's unit (use "1" for unit-less quantities) * @param int $exponent Decimal exponent to apply * * @return QuantityValue */ private function newUncertainQuantityFromDigits(DecimalValue $amount, $unit = '1', $exponent = 0) { $math = new DecimalMath(); if ($amount->getSign() === '+') { $upperBound = $math->bump($amount); $lowerBound = $math->slump($amount); } else { $upperBound = $math->slump($amount); $lowerBound = $math->bump($amount); } $amount = $this->decimalParser->applyDecimalExponent($amount, $exponent); $lowerBound = $this->decimalParser->applyDecimalExponent($lowerBound, $exponent); $upperBound = $this->decimalParser->applyDecimalExponent($upperBound, $exponent); return new QuantityValue($amount, $unit, $upperBound, $lowerBound); }
/** * @dataProvider applyDecimalExponentProvider */ public function testApplyDecimalExponent(DecimalValue $decimal, $exponent, DecimalValue $expectedDecimal) { $parser = new DecimalParser(); $actualDecimal = $parser->applyDecimalExponent($decimal, $exponent); $this->assertSame($expectedDecimal->getValue(), $actualDecimal->getValue()); }