Fix how we calculate the precision in Unit converter and update GetNumberDigitsWholeNumberPart (#1256)
* Fix 1255 * optimization * spacing
This commit is contained in:
parent
60a7ee3604
commit
75fde82f46
@ -50,7 +50,7 @@ namespace CalcManager::NumberFormattingUtils
|
||||
/// <param name="value">the number</param>
|
||||
unsigned int GetNumberDigitsWholeNumberPart(double value)
|
||||
{
|
||||
return value == 0 ? 1 : (1 + static_cast<unsigned int>(log10(abs(value))));
|
||||
return value == 0 ? 1u : static_cast<unsigned int>(1 + max(0.0, log10(abs(value))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -905,7 +905,8 @@ void UnitConverter::Calculate()
|
||||
{
|
||||
// Fewer digits are needed following the decimal if the number is large,
|
||||
// we calculate the number of decimals necessary based on the number of digits in the integer part.
|
||||
precision = max(0U, max(OPTIMALDIGITSALLOWED, min(MAXIMUMDIGITSALLOWED, currentNumberSignificantDigits)) - numPreDecimal);
|
||||
auto numberDigits = max(OPTIMALDIGITSALLOWED, min(MAXIMUMDIGITSALLOWED, currentNumberSignificantDigits));
|
||||
precision = numberDigits > numPreDecimal ? numberDigits - numPreDecimal : 0;
|
||||
}
|
||||
|
||||
m_returnDisplay = RoundSignificantDigits(returnValue, precision);
|
||||
|
@ -970,6 +970,10 @@ namespace CalculatorManagerTest
|
||||
VERIFY_ARE_EQUAL(digitsCount, 15);
|
||||
digitsCount = GetNumberDigitsWholeNumberPart(324328412837382.232213214324234);
|
||||
VERIFY_ARE_EQUAL(digitsCount, 15);
|
||||
digitsCount = GetNumberDigitsWholeNumberPart(0.032);
|
||||
VERIFY_ARE_EQUAL(digitsCount, 1);
|
||||
digitsCount = GetNumberDigitsWholeNumberPart(0.00000000000000000001);
|
||||
VERIFY_ARE_EQUAL(digitsCount, 1);
|
||||
}
|
||||
|
||||
void CalculatorManagerTest::CalculatorManagerNumberFormattingUtils_RoundSignificantDigits()
|
||||
|
Loading…
Reference in New Issue
Block a user