Skip to content

Commit

Permalink
fix math function for percent
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Di Martino committed Jan 19, 2024
1 parent da6dd91 commit 5e6d1b5
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 31 deletions.
54 changes: 27 additions & 27 deletions include/units/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3606,7 +3606,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> exp(const dimensionlessUnit x) noexcept
{
return std::exp(x.value());
return std::exp(x.raw());
}

/**
Expand All @@ -3621,7 +3621,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> log(const dimensionlessUnit x) noexcept
{
return std::log(x.value());
return std::log(x.raw());
}

/**
Expand All @@ -3635,7 +3635,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> log10(const dimensionlessUnit x) noexcept
{
return std::log10(x.value());
return std::log10(x.raw());
}

/**
Expand Down Expand Up @@ -3669,7 +3669,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> exp2(const dimensionlessUnit x) noexcept
{
return std::exp2(x.value());
return std::exp2(x.raw());
}

/**
Expand All @@ -3683,7 +3683,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> expm1(const dimensionlessUnit x) noexcept
{
return std::expm1(x.value());
return std::expm1(x.raw());
}

/**
Expand All @@ -3698,7 +3698,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> log1p(const dimensionlessUnit x) noexcept
{
return std::log1p(x.value());
return std::log1p(x.raw());
}

/**
Expand All @@ -3712,7 +3712,7 @@ namespace units
template<class dimensionlessUnit, std::enable_if_t<traits::is_dimensionless_unit_v<dimensionlessUnit>, int> = 0>
dimensionless<detail::floating_point_promotion_t<typename dimensionlessUnit::underlying_type>> log2(const dimensionlessUnit x) noexcept
{
return std::log2(x.value());
return std::log2(x.raw());
}

//----------------------------------
Expand All @@ -3737,7 +3737,7 @@ namespace units
constexpr auto sqrt(const UnitType& value) noexcept -> unit<traits::strong_t<square_root<typename units::traits::unit_traits<UnitType>::conversion_factor>>,
detail::floating_point_promotion_t<typename units::traits::unit_traits<UnitType>::underlying_type>, linear_scale>
{
return decltype(units::sqrt(value))(sqrt(value.value()));
return decltype(units::sqrt(value))(sqrt(value.raw()));
}

/**
Expand All @@ -3754,7 +3754,7 @@ namespace units
detail::floating_point_promotion_t<std::common_type_t<UnitTypeLhs, UnitTypeRhs>> hypot(const UnitTypeLhs& x, const UnitTypeRhs& y)
{
using CommonUnit = decltype(units::hypot(x, y));
return CommonUnit(std::hypot(CommonUnit(x).value(), CommonUnit(y).value()));
return CommonUnit(std::hypot(CommonUnit(x).raw(), CommonUnit(y).raw()));
}

//----------------------------------
Expand All @@ -3771,7 +3771,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
detail::floating_point_promotion_t<UnitType> ceil(const UnitType x) noexcept
{
return detail::floating_point_promotion_t<UnitType>(std::ceil(x.value()));
return detail::floating_point_promotion_t<UnitType>(std::ceil(x.raw()));
}

/**
Expand All @@ -3784,7 +3784,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
detail::floating_point_promotion_t<UnitType> floor(const UnitType x) noexcept
{
return detail::floating_point_promotion_t<UnitType>(std::floor(x.value()));
return detail::floating_point_promotion_t<UnitType>(std::floor(x.raw()));
}

/**
Expand All @@ -3799,7 +3799,7 @@ namespace units
detail::floating_point_promotion_t<std::common_type_t<UnitTypeLhs, UnitTypeRhs>> fmod(const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept
{
using CommonUnit = decltype(units::fmod(numer, denom));
return CommonUnit(std::fmod(CommonUnit(numer).value(), CommonUnit(denom).value()));
return CommonUnit(std::fmod(CommonUnit(numer).raw(), CommonUnit(denom).raw()));
}

/**
Expand All @@ -3813,7 +3813,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
detail::floating_point_promotion_t<UnitType> trunc(const UnitType x) noexcept
{
return detail::floating_point_promotion_t<UnitType>(std::trunc(x.value()));
return detail::floating_point_promotion_t<UnitType>(std::trunc(x.raw()));
}

/**
Expand All @@ -3827,7 +3827,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
detail::floating_point_promotion_t<UnitType> round(const UnitType x) noexcept
{
return detail::floating_point_promotion_t<UnitType>(std::round(x.value()));
return detail::floating_point_promotion_t<UnitType>(std::round(x.raw()));
}

//----------------------------------
Expand All @@ -3846,14 +3846,14 @@ namespace units
template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t<traits::is_unit_v<UnitTypeLhs> && traits::is_unit_v<UnitTypeRhs>, int> = 0>
detail::floating_point_promotion_t<UnitTypeLhs> copysign(const UnitTypeLhs x, const UnitTypeRhs y) noexcept
{
return detail::floating_point_promotion_t<UnitTypeLhs>(std::copysign(x.value(), y.value())); // no need for conversion to get the correct sign.
return detail::floating_point_promotion_t<UnitTypeLhs>(std::copysign(x.raw(), y.raw())); // no need for conversion to get the correct sign.
}

/// Overload to copy the sign from a raw double
template<class UnitTypeLhs, typename T, std::enable_if_t<std::is_arithmetic_v<T> && traits::is_unit_v<UnitTypeLhs>, int> = 0>
detail::floating_point_promotion_t<UnitTypeLhs> copysign(const UnitTypeLhs x, const T& y) noexcept
{
return detail::floating_point_promotion_t<UnitTypeLhs>(std::copysign(x.value(), y));
return detail::floating_point_promotion_t<UnitTypeLhs>(std::copysign(x.raw(), y));
}

//----------------------------------
Expand All @@ -3872,7 +3872,7 @@ namespace units
detail::floating_point_promotion_t<std::common_type_t<UnitTypeLhs, UnitTypeRhs>> fdim(const UnitTypeLhs x, const UnitTypeRhs y) noexcept
{
using CommonUnit = decltype(units::fdim(x, y));
return CommonUnit(std::fdim(CommonUnit(x).value(), CommonUnit(y).value()));
return CommonUnit(std::fdim(CommonUnit(x).raw(), CommonUnit(y).raw()));
}

/**
Expand All @@ -3887,7 +3887,7 @@ namespace units
detail::floating_point_promotion_t<std::common_type_t<UnitTypeLhs, UnitTypeRhs>> fmax(const UnitTypeLhs x, const UnitTypeRhs y) noexcept
{
using CommonUnit = decltype(units::fmax(x, y));
return CommonUnit(std::fmax(CommonUnit(x).value(), CommonUnit(y).value()));
return CommonUnit(std::fmax(CommonUnit(x).raw(), CommonUnit(y).raw()));
}

/**
Expand All @@ -3903,7 +3903,7 @@ namespace units
detail::floating_point_promotion_t<std::common_type_t<UnitTypeLhs, UnitTypeRhs>> fmin(const UnitTypeLhs x, const UnitTypeRhs y) noexcept
{
using CommonUnit = decltype(units::fmin(x, y));
return CommonUnit(std::fmin(CommonUnit(x).value(), CommonUnit(y).value()));
return CommonUnit(std::fmin(CommonUnit(x).raw(), CommonUnit(y).raw()));
}

//----------------------------------
Expand All @@ -3920,7 +3920,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
detail::floating_point_promotion_t<UnitType> fabs(const UnitType x) noexcept
{
return detail::floating_point_promotion_t<UnitType>(std::fabs(x.value()));
return detail::floating_point_promotion_t<UnitType>(std::fabs(x.raw()));
}

/**
Expand All @@ -3933,7 +3933,7 @@ namespace units
template<class UnitType, std::enable_if_t<traits::is_unit_v<UnitType>, int> = 0>
UnitType abs(const UnitType x) noexcept
{
return UnitType(std::abs(x.value()));
return UnitType(std::abs(x.raw()));
}

/**
Expand All @@ -3956,7 +3956,7 @@ namespace units
-> std::common_type_t<decltype(detail::floating_point_promotion_t<UnitTypeLhs>(x) * detail::floating_point_promotion_t<UnitMultiply>(y)), UnitAdd>
{
using CommonUnit = decltype(units::fma(x, y, z));
return CommonUnit(std::fma(x.value(), y.value(), CommonUnit(z).value()));
return CommonUnit(std::fma(x.raw(), y.raw(), CommonUnit(z).raw()));
}

//----------------------------
Expand All @@ -3966,31 +3966,31 @@ namespace units
template<typename UnitType, typename = std::enable_if_t<units::traits::is_unit_v<UnitType>>>
inline bool isnan(const UnitType& x) noexcept
{
return std::isnan(x.value());
return std::isnan(x.raw());
}

template<typename UnitType, typename = std::enable_if_t<units::traits::is_unit_v<UnitType>>>
inline bool isinf(const UnitType& x) noexcept
{
return std::isinf(x.value());
return std::isinf(x.raw());
}

template<typename UnitType, typename = std::enable_if_t<units::traits::is_unit_v<UnitType>>>
inline bool isfinite(const UnitType& x) noexcept
{
return std::isfinite(x.value());
return std::isfinite(x.raw());
}

template<typename UnitType, typename = std::enable_if_t<units::traits::is_unit_v<UnitType>>>
inline bool isnormal(const UnitType& x) noexcept
{
return std::isnormal(x.value());
return std::isnormal(x.raw());
}

template<typename UnitTypeLhs, typename UnitTypeRhs, typename = std::enable_if_t<units::traits::is_same_dimension_unit_v<UnitTypeLhs, UnitTypeRhs>>>
inline bool isunordered(const UnitTypeLhs& lhs, const UnitTypeRhs& rhs) noexcept
{
return std::isunordered(lhs.value(), rhs.value());
return std::isunordered(lhs.raw(), rhs.raw());
}

} // end namespace units
Expand Down
Loading

0 comments on commit 5e6d1b5

Please sign in to comment.