
// Copyright 2019 Shlomi Steinberg
// 

#pragma once

#include <limits>
#include <cmath>
#include "glm.hpp"
#include "common.hpp"

namespace normal_distribution {

// Gaussian PDF
template <typename T>
constexpr auto pdf(T x, T mean, T stdvar) noexcept {
	return stdvar==0 ? 
		(x==mean? std::numeric_limits<T>::infinity() : T(0)) : 
		T(1)/(stdvar*glm::sqrt(T(2)*glm::pi<T>())) * glm::exp(-T(1)/T(2) * sqr((x-mean)/stdvar));
}
// CDF
double cdf(double x) {
   return .5*erfc(-x / glm::sqrt(2));
}

}
