ekmett / rounded

MPFR bindings for Haskell
http://hackage.haskell.org/package/rounded
BSD 3-Clause "New" or "Revised" License
33 stars 13 forks source link

Additional special functions #31

Open davidsd opened 5 years ago

davidsd commented 5 years ago

MPFR includes several useful special functions that would be nice to add, see: https://tspiteri.gitlab.io/gmp-mpfr-sys/mpfr/MPFR-Interface.html . For example, I recently needed the incomplete gamma function mpfr_gamma_inc which is available in MPFR >=4.0. Which versions of MPFR is this package trying to maintain compatibility with?

By the way, to assist users in adding functions with the ffi, it would be nice to either expose Numeric.Rounded.Internal, or expose the functions unary and binary in that module.

claudeha commented 5 years ago

I think it would be nice to still work with MPFR 3.1, as Debian Stretch (current stable, for a few more months) still has MPFR 3.1.5.

Perhaps CPP can be used for conditionally binding newer functionality where available? https://www.mpfr.org/mpfr-current/mpfr.html#index-MPFR_005fVERSION

Found this page for tracking changes: https://abi-laboratory.pro/?view=timeline&l=mpfr

claudeha commented 5 years ago

These are the functions currently foreign imported (minus mpfr_ and const_ strings)

abs acos acosh add asin asinh atan atan2 atanh catalan ceil clear cmp
cmp_ld cos cosh div equal_p euler exp expm1 floor free_str get_d get_ld
get_ld_2exp get_str get_z get_z_2exp greaterequal_p greater_p inf_p
init2 lessequal_p lessgreater_p less_p log log1p log2 max min modf mul
nan_p neg nextabove nextbelow pi rint set set_d set_ld set_q set_sj
set_z set_z_2exp sgn signbit sin sinh sqrt sub tan tanh trunc zero_p

This indeed misses a large amount of the MPFR API: https://www.mpfr.org/mpfr-current/mpfr.html#Function-and-Type-Index_fn_letter-M

I generated the list by:

git grep foreign | cut -d\  -f 5 |
sed "s/mpfr_//" | sed "s/wrapped_//" | sed "s/__g//" | sed "s/const_//" |
sort -u | tr -d \" | tr "\n" " " && echo
claudeha commented 5 years ago

Perhaps CPP can be used for conditionally binding newer functionality where available?

On second thoughts, not a good idea to change exposed API conditionally, may lead to unusual build failures.

Exposing unary/binary is not something I really want to do, because they unsafePerformIO.

These are the functions currently foreign imported

Here's an updated list, from code to be pushed shortly:

abs acos acosh add agm ai asin asinh atan atan2 atanh catalan cbrt
ceil clear cmp cmp_ld copysign cos cosh cot coth csc csch digamma dim 
div eint equal_p erf erfc euler exp exp10 exp2 expm1 fits_intmax_p fits_sint_p
fits_slong_p fits_sshort_p fits_uintmax_p fits_uint_p fits_ulong_p fits_ushort_p
floor fmod frac free_str gamma  get_d get_ld get_ld_2exp get_str 
get_z get_z_2exp greaterequal_p greater_p hypot inf_p init2 integer_p j0 j1 
lessequal_p lessgreater_p less_p li2 lngamma log log10 log1p log2 max min 
modf mul nan_p neg nextabove nextbelow number_p pi pow rec_sqrt regular_p 
rint rint_ceil rint_floor rint_round rint_roundeven rint_trunc sec sech set set_d 
set_ld set_q set_sj set_z set_z_2exp sgn signbit sin sin_cos sinh sinh_cosh sqr 
sqrt sub tan tanh trunc unordered_p y0 y1 zero_p zeta 

There is code for beta and gamma_inc but it's currently disabled because new in MPFR 4.0...

claudeha commented 5 years ago

I think a reasonable course of action is to keep rounded-0.x on MPFR 3.1+ and rounded-1.x on MPFR 4.0+, and backport any bugfixes as required...