Skip to content

Commit

Permalink
STYLE: Replace NumericTraits<double>::OneValue() calls by 1.0
Browse files Browse the repository at this point in the history
Aims to improve code readability (assuming that most programmers know
that the type of the floating point literal `1.0` is `double`, according
to the C++ Standard).
  • Loading branch information
N-Dekker authored and hjmjohnson committed Jan 26, 2022
1 parent 5bb2a8c commit 7182b61
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkVersor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ Versor<T>::Set(const VectorType & axis)
throw exception;
}

const ValueType cosangle2 = std::sqrt(NumericTraits<double>::OneValue() - sinangle2 * sinangle2);
const ValueType cosangle2 = std::sqrt(1.0 - sinangle2 * sinangle2);

m_X = axis[0];
m_Y = axis[1];
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkCompensatedSummationTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CompensatedSummationTest2Associate
itk::CompensatedSummation<double> compensatedSum;
for (DomainType::IndexValueType i = subdomain[0]; i <= subdomain[1]; ++i)
{
double value = itk::NumericTraits<double>::OneValue() / 7;
double value = 1.0 / 7;
this->m_PerThreadCompensatedSum[threadId].AddElement(value);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/test/itkMathTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ main(int, char *[])
}

// Test comparison values of different types
if (itk::Math::NotExactlyEquals(itk::NumericTraits<float>::OneValue(), itk::NumericTraits<double>::OneValue()) ||
itk::Math::NotExactlyEquals(itk::NumericTraits<double>::OneValue(), static_cast<float>(1)))
if (itk::Math::NotExactlyEquals(itk::NumericTraits<float>::OneValue(), 1.0) ||
itk::Math::NotExactlyEquals(1.0, static_cast<float>(1)))
{
std::cout << __FILE__ << " " << __LINE__ << " " << f << " == " << d << std::endl;
testPassStatus = EXIT_FAILURE;
Expand All @@ -633,8 +633,8 @@ main(int, char *[])
FloatRepresentationD oneExact;
FloatRepresentationD oneAlmost;

oneExact.asFloat = itk::NumericTraits<double>::OneValue();
oneAlmost.asFloat = itk::NumericTraits<double>::OneValue();
oneExact.asFloat = 1.0;
oneAlmost.asFloat = 1.0;
oneAlmost.asInt += 1;

// Very close values should be AlmostEqual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ CenteredSimilarity2DTransform<TParametersValueType>::GetInverse(Self * inverse)
return false;
}
inverse->SetCenter(this->GetCenter()); // inverse have the same center
inverse->SetScale(NumericTraits<double>::OneValue() / this->GetScale());
inverse->SetScale(1.0 / this->GetScale());
inverse->SetAngle(-this->GetAngle());
inverse->SetTranslation(-(this->GetInverseMatrix() * this->GetTranslation()));
return true;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Transform/include/itkScaleTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ScaleTransform<TParametersValueType, NDimensions>::GetInverse(Self * inverse) co
inverse->SetFixedParameters(this->GetFixedParameters());
for (unsigned int i = 0; i < SpaceDimension; ++i)
{
inverse->m_Scale[i] = NumericTraits<double>::OneValue() / m_Scale[i];
inverse->m_Scale[i] = 1.0 / m_Scale[i];
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Similarity2DTransform<TParametersValueType>::GetInverse(Self * inverse) const
return false;
}
inverse->SetCenter(this->GetCenter()); // inverse have the same center
inverse->SetScale(NumericTraits<double>::OneValue() / this->GetScale());
inverse->SetScale(1.0 / this->GetScale());
inverse->SetAngle(-this->GetAngle());
inverse->SetTranslation(-(this->GetInverseMatrix() * this->GetTranslation()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ MultipleValuedVnlCostFunctionAdaptor::SetScales(const ScalesType & scales)
itkGenericExceptionMacro("ERROR: Scales must have value greater than epsilon! Scale[" << i
<< "] = " << scales[i]);
}
m_InverseScales[i] = NumericTraits<double>::OneValue() / scales[i];
m_InverseScales[i] = 1.0 / scales[i];
}
m_ScalesInitialized = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Numerics/Optimizers/src/itkOptimizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Optimizer::SetScales(const ScalesType & scales)
{
itkExceptionMacro("ERROR: Scales must have value greater than epsilon! Scale[" << i << "] = " << m_Scales[i]);
}
m_InverseScales[i] = NumericTraits<double>::OneValue() / m_Scales[i];
m_InverseScales[i] = 1.0 / m_Scales[i];
}
m_ScalesInitialized = true;
this->Modified();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SingleValuedVnlCostFunctionAdaptor::SetScales(const ScalesType & scales)
itkGenericExceptionMacro("ERROR: Scales must have value greater than epsilon! Scale[" << i
<< "] = " << scales[i]);
}
m_InverseScales[i] = NumericTraits<double>::OneValue() / scales[i];
m_InverseScales[i] = 1.0 / scales[i];
}
m_ScalesInitialized = true;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Numerics/Statistics/include/itkHistogram.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,13 @@ Histogram<TMeasurement, TFrequencyContainer>::Quantile(unsigned int dimension, d
{
n = size - 1;
InstanceIdentifier m = NumericTraits<InstanceIdentifier>::ZeroValue();
p_n = NumericTraits<double>::OneValue();
p_n = 1.0;
do
{
f_n = this->GetFrequency(n, dimension);
cumulated += f_n;
p_n_prev = p_n;
p_n = NumericTraits<double>::OneValue() - cumulated / totalFrequency;
p_n = 1.0 - cumulated / totalFrequency;
n--;
m++;
} while (m < size && p_n > p);
Expand Down

0 comments on commit 7182b61

Please sign in to comment.