normal.hpp 692 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2022 Hans Dembinski, Jay Gohil
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_DETAIL_NORMAL_HPP
  7. #define BOOST_HISTOGRAM_DETAIL_NORMAL_HPP
  8. #include <boost/histogram/detail/erf_inv.hpp>
  9. #include <cmath>
  10. namespace boost {
  11. namespace histogram {
  12. namespace detail {
  13. inline double normal_cdf(double x) noexcept {
  14. return std::fma(0.5, std::erf(x / std::sqrt(2)), 0.5);
  15. }
  16. inline double normal_ppf(double p) noexcept {
  17. return std::sqrt(2) * erf_inv(2 * (p - 0.5));
  18. }
  19. } // namespace detail
  20. } // namespace histogram
  21. } // namespace boost
  22. #endif