rmathlib

Crates.iormathlib
lib.rsrmathlib
version1.1.0
sourcesrc
created_at2024-04-23 14:49:02.441448
updated_at2024-04-29 16:02:33.135984
descriptionA Rust Port of R's C Library of Special Functions
homepagehttps://github.com/tla-org/rmathlib
repositoryhttps://github.com/tla-org/rmathlib
max_upload_size
id1217692
size187,639
Rik Huijzer (rikhuijzer)

documentation

https://docs.rs/rmathlib

README

rmathlib

A Rust port of R's C Library of Special Functions.

Benefits

Some benefits of this port over the native C code are:

  • Support wasm32-unknown-unknown target (avoiding emscripten).
  • Clearer documentation with the help of cargo doc.
  • Easier to read thanks to cargo fmt.
  • Enables Go To Definition (code navigation) when loading this package as a dependency.
  • More clarity about the used compiler and supported Rust versions.

Status

The following functions have been ported:

Distribution Density Probability Quantile Random Generation
Normal dnorm pnorm qnorm
Student's t dt pt, pnt
Beta pbeta
Poisson dpois
Gamma dgamma pgamma

License

The original R code is licensed under the GPL-2.0. Therefore, this port is also licensed under the GPL-2.0.

The GPL-2.0 is known to be a very restrictive license. Each project that includes GPL-2.0 code should also be licensed under the GPL-2.0 ( One exception to this restriction is to use this library only for a small part of the functionality of your project (see, e.g., here). In such cases, your project would be considered not to be a "derivative work" and therefore not subject to the GPL-2.0.

Developer Notes

Some tips for debugging the C code in test/nmath/:

To print from C, set

std::env::set_var("CFLAGS", "-DDEBUG_bratio");

and use --nocapture like so:

$ cargo watch -x 'test -- --nocapture'

When printing inside C, verify that that the numbers are printed correctly. REprintf seems to not always print numbers correctly. To fix that, REprintf can just be replaced with printf (and some \n's).

For example, test the representation via:

double tmp = 1.2;
REprintf("from c: x=%g\n", x);

or

#include <stdio.h>

double tmp = 1.2;
printf("from c: x=%g\n", x);
Commit count: 55

cargo fmt