// Copyright Matt Borland 2025. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MATH_SF_LOGIT_HPP #define BOOST_MATH_SF_LOGIT_HPP #include #include #include #include #include namespace boost { namespace math { template RealType logit(RealType p, const Policy&) { BOOST_MATH_STD_USING using std::atanh; using promoted_real_type = typename policies::evaluation::type; if (p < tools::min_value()) { return -policies::raise_overflow_error("logit", "sub-normals will overflow ln(x/(1-x))", Policy()); } static const RealType crossover {RealType{1}/4}; const auto promoted_p {static_cast(p)}; RealType result {}; if (p > crossover) { result = static_cast(2 * atanh(2 * promoted_p - 1)); } else { result = static_cast(log(promoted_p / (1 - promoted_p))); } return result; } template RealType logit(RealType p) { return logit(p, policies::policy<>()); } } // namespace math } // namespace boost #endif // BOOST_MATH_SF_LOGIT_HPP