Current section

Files

Jump to
exboost priv boostnif.c
Raw

priv/boostnif.c

/*
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <strings.h>
#include <erl_nif.h>
#include <boost/math/special_functions.hpp>
#define MAXBUFLEN 1024
static ERL_NIF_TERM _tgamma(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double z;
long double res;
enif_get_double(env, argv[0], &z);
try {
res = boost::math::tgamma((long double)z);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ERL_NIF_TERM _lgamma(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double z;
long double res;
enif_get_double(env, argv[0], &z);
try {
res = boost::math::lgamma((long double)z);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ERL_NIF_TERM _gamma_p(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double a;
double z;
long double res;
enif_get_double(env, argv[0], &a);
enif_get_double(env, argv[1], &z);
try {
res = boost::math::gamma_p((long double)a, (long double)z);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ERL_NIF_TERM _tgamma_lower(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double a;
double z;
long double res;
enif_get_double(env, argv[0], &a);
enif_get_double(env, argv[1], &z);
try {
res = boost::math::tgamma_lower((long double)a, (long double)z);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ERL_NIF_TERM _gamma_p_inv(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double a;
double p;
long double res;
enif_get_double(env, argv[0], &a);
enif_get_double(env, argv[1], &p);
try {
res = boost::math::gamma_p_inv((long double)a, (long double)p);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ERL_NIF_TERM _digamma(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double z;
long double res;
enif_get_double(env, argv[0], &z);
try {
res = boost::math::digamma((long double)z);
return enif_make_double(env, res);
}
catch(boost::exception const& ex) {
return enif_raise_exception(env, enif_make_atom(env,"boostError"));
}
}
static ErlNifFunc nif_funcs[] =
{
{"_tgamma", 1, _tgamma},
{"_lgamma", 1, _lgamma},
{"_gamma_p", 2, _gamma_p},
{"_tgamma_lower", 2, _tgamma_lower},
{"_gamma_p_inv", 2, _gamma_p_inv},
{"_digamma", 1, _digamma}
};
ERL_NIF_INIT(Elixir.Exboost.Math,nif_funcs,NULL,NULL,NULL,NULL)