diff --git a/math.c b/math.c index a09d605..90d5ce0 100644 --- a/math.c +++ b/math.c @@ -777,6 +777,30 @@ math_erfc(VALUE obj, VALUE x) /* * call-seq: + * Math.normcdf(x) -> Float + * + * Calculates cumulative distribution function (CDF) of the standard normal distribution for +x+. + * + * Domain: (-INFINITY, INFINITY) + * + * Codomain: (0.0, 1.0) + * + * Math.normcdf(0) #=> 0.5 + * + */ + +static VALUE +math_normcdf(VALUE obj, VALUE x) +{ + double d0, d; + Need_Float(x); + d0 = RFLOAT_VALUE(x); + d = 0.5 * (1.0 + erf(d0 / sqrt(2))); + return DBL2NUM(d); +} + +/* + * call-seq: * Math.gamma(x) -> Float * * Calculates the gamma function of x. @@ -1010,6 +1034,8 @@ Init_Math(void) rb_define_module_function(rb_mMath, "erf", math_erf, 1); rb_define_module_function(rb_mMath, "erfc", math_erfc, 1); + rb_define_module_function(rb_mMath, "normcdf", math_normcdf, 1); + rb_define_module_function(rb_mMath, "gamma", math_gamma, 1); rb_define_module_function(rb_mMath, "lgamma", math_lgamma, 1); }