Skip to content

Commit

Permalink
Replace usage of 'abs()' by 'fabs()'
Browse files Browse the repository at this point in the history
'abs()' is only defined for int's in the standard, but on some platforms works for doubles too
  • Loading branch information
Kanma committed Dec 13, 2024
1 parent ac0b127 commit 4ed5f9f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/gafro/algebra/Multivector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace gafro
template <class T, int... index>
T Algebra<M>::Multivector<T, index...>::norm() const
{
return sqrt(abs(squaredNorm()));
return sqrt(fabs(squaredNorm()));
}

template <class M>
Expand All @@ -348,7 +348,7 @@ namespace gafro
{
T squared_norm = squaredNorm();

return squared_norm > 0 ? sqrt(squared_norm) : -sqrt(abs(squared_norm));
return squared_norm > 0 ? sqrt(squared_norm) : -sqrt(fabs(squared_norm));
}

template <class M>
Expand Down
2 changes: 1 addition & 1 deletion src/gafro/algebra/cga/Circle.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace gafro
{
auto mv = ((*this) * (Scalar<T>(T(-1.0)) * ((*this).dual() | Ei<T>(T(1.0))).evaluate().inverse())).evaluate();

return sqrt(abs((mv * mv).template get<blades::scalar>()));
return sqrt(fabs((mv * mv).template get<blades::scalar>()));
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/gafro/algebra/cga/ConformalGeometricAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace gafro

for (unsigned int k = 0; k < mv.vector().rows(); ++k)
{
if (abs(mv.vector().coeff(k, 0)) < 1e-10)
if (fabs(mv.vector().coeff(k, 0)) < 1e-10)
{
continue;
}
Expand All @@ -59,7 +59,7 @@ namespace gafro
{
ostream << (mv.vector().coeff(k, 0) >= 0 ? " + " : " - ");

ostream << abs(mv.vector().coeff(k, 0));
ostream << fabs(mv.vector().coeff(k, 0));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/gafro/algebra/cga/MotorLogarithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ namespace gafro
switch (blade)
{
case blades::e23:
if (TypeTraits<T>::greaterEqual(abs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
if (TypeTraits<T>::greaterEqual(fabs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
{
return TypeTraits<T>::Zero();
}

return motor.template get<blades::e23>() * TypeTraits<T>::Value(-2.0) * acos(motor.template get<blades::scalar>()) /
(sin(acos(motor.template get<blades::scalar>())) + TypeTraits<T>::Value(1e-10));
case blades::e13:
if (TypeTraits<T>::greaterEqual(abs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
if (TypeTraits<T>::greaterEqual(fabs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
{
return TypeTraits<T>::Zero();
}

return motor.template get<blades::e13>() * TypeTraits<T>::Value(-2.0) * acos(motor.template get<blades::scalar>()) /
(sin(acos(motor.template get<blades::scalar>())) + TypeTraits<T>::Value(1e-10));
case blades::e12:
if (TypeTraits<T>::greaterEqual(abs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
if (TypeTraits<T>::greaterEqual(fabs(motor.template get<blades::scalar>()), TypeTraits<T>::Value(1.0 - 1e-10)))
{
return TypeTraits<T>::Zero();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gafro/algebra/cga/Rotor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace gafro
{
T acos = std::acos(scalar());

if (abs(acos) < 1e-6)
if (fabs(acos) < 1e-6)
{
return Rotor<T>::Generator({ e12(), e13(), e23() });
}
Expand Down
2 changes: 1 addition & 1 deletion src/gafro/algebra/cga/Sphere.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace gafro
template <typename T>
T Sphere<T>::getRadius() const
{
return sqrt(abs(((*this) * Scalar<T>(-1.0 / (this->dual() | Ei<T>(1.0)).template get<blades::scalar>())).evaluate().squaredNorm()));
return sqrt(fabs(((*this) * Scalar<T>(-1.0 / (this->dual() | Ei<T>(1.0)).template get<blades::scalar>())).evaluate().squaredNorm()));
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/gafro/algebra/dqa/DualQuaternionAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ std::ostream &operator<<(std::ostream &ostream, const gafro::dqa::Multivector<do

for (unsigned int k = 0; k < dq.vector().rows(); ++k)
{
if (abs(dq.vector().coeff(k, 0)) < 1e-10)
if (fabs(dq.vector().coeff(k, 0)) < 1e-10)
{
continue;
}
Expand All @@ -95,7 +95,7 @@ std::ostream &operator<<(std::ostream &ostream, const gafro::dqa::Multivector<do
{
ostream << (dq.vector().coeff(k, 0) >= 0 ? " + " : " - ");

ostream << abs(dq.vector().coeff(k, 0));
ostream << fabs(dq.vector().coeff(k, 0));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/gafro/algebra/pga/ProjectiveGeometricAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ std::ostream &operator<<(std::ostream &ostream, const gafro::pga::Multivector<do

for (unsigned int k = 0; k < dq.vector().rows(); ++k)
{
if (abs(dq.vector().coeff(k, 0)) < 1e-10)
if (fabs(dq.vector().coeff(k, 0)) < 1e-10)
{
continue;
}
Expand All @@ -88,7 +88,7 @@ std::ostream &operator<<(std::ostream &ostream, const gafro::pga::Multivector<do
{
ostream << (dq.vector().coeff(k, 0) >= 0 ? " + " : " - ");

ostream << abs(dq.vector().coeff(k, 0));
ostream << fabs(dq.vector().coeff(k, 0));
}
else
{
Expand Down

0 comments on commit 4ed5f9f

Please sign in to comment.