Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ unsafe extern "C" {
// boost/math/ccmath/sqrt.hpp
pub fn math_ccmath_sqrt(x: f64) -> f64;

// boost/math/special_functions/acosh.hpp
pub fn math_acosh(x: f64) -> f64;
// boost/math/special_functions/asinh.hpp
pub fn math_asinh(x: f64) -> f64;
// boost/math/special_functions/atanh.hpp
pub fn math_atanh(x: f64) -> f64;

// boost/math/special_functions/airy.hpp
pub fn math_airy_ai(x: f64) -> f64;
pub fn math_airy_ai_prime(x: f64) -> f64;
Expand Down
11 changes: 7 additions & 4 deletions src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@
//! - [x] [`sinc_pi`]
//! - [x] [`sinhc_pi`]
//!
//! <h4>Inverse Hyperbolic Functions</h4>
//! ### Inverse Hyperbolic Functions
//!
//! - [ ] `acosh`
//! - [ ] `asinh`
//! - [ ] `atanh`
//! - [x] [`acosh`]
//! - [x] [`asinh`]
//! - [x] [`atanh`]
//!
//! ### Owen's T Function
//!
Expand All @@ -239,7 +239,10 @@
pub mod ccmath;
mod special_functions;

pub use special_functions::acosh::*;
pub use special_functions::airy::*;
pub use special_functions::asinh::*;
pub use special_functions::atanh::*;
pub use special_functions::bessel::*;
pub use special_functions::beta::*;
pub use special_functions::binomial::*;
Expand Down
24 changes: 24 additions & 0 deletions src/math/special_functions/acosh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! boost/math/special_functions/acosh.hpp

use crate::ffi;

/// Inverse hyperbolic cosine function *cosh<sup>-1</sup>(x)*
///
/// *cosh<sup>-1</sup>(x) = ln(x + (x<sup>2</sup> - 1)<sup>1/2</sup>)*
///
/// Corresponds to `boost::math::acosh` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/inv_hyper/acosh.html>
pub fn acosh(x: f64) -> f64 {
unsafe { ffi::math_acosh(x) }
}

#[cfg(test)]
mod tests {
use crate::math::acosh;

#[test]
fn test_acosh() {
assert_eq!(acosh(1.0), 0.0);
assert_relative_eq!(acosh(2.0), 1.316_957_896_924_816_8);
}
}
25 changes: 25 additions & 0 deletions src/math/special_functions/asinh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! boost/math/special_functions/asinh.hpp

use crate::ffi;

/// Inverse hyperbolic sine function *sinh<sup>-1</sup>(x)*
///
/// *sinh<sup>-1</sup>(x) = ln(x + (x<sup>2</sup> + 1)<sup>1/2</sup>)*
///
/// Corresponds to `boost::math::asinh` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/inv_hyper/asinh.html>
pub fn asinh(x: f64) -> f64 {
unsafe { ffi::math_asinh(x) }
}

#[cfg(test)]
mod tests {
use crate::math::asinh;

#[test]
fn test_asinh() {
assert_eq!(asinh(0.0), 0.0);
assert_relative_eq!(asinh(0.5), 0.481_211_825_059_603_47);
assert_relative_eq!(asinh(1.0), 0.881_373_587_019_543);
}
}
25 changes: 25 additions & 0 deletions src/math/special_functions/atanh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! boost/math/special_functions/atanh.hpp

use crate::ffi;

/// Inverse hyperbolic sine function *tanh<sup>-1</sup>(x)*
///
/// *tanh<sup>-1</sup>(x) = ln(x + (x<sup>2</sup> + 1)<sup>1/2</sup>)*
///
/// Corresponds to `boost::math::atanh` in C++.
/// <https://boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/inv_hyper/atanh.html>
pub fn atanh(x: f64) -> f64 {
unsafe { ffi::math_atanh(x) }
}

#[cfg(test)]
mod tests {
use crate::math::atanh;

#[test]
fn test_atanh() {
assert_eq!(atanh(0.0), 0.0);
assert_relative_eq!(atanh(0.5), 0.549_306_144_334_054_9);
assert_eq!(atanh(1.0), f64::INFINITY);
}
}
3 changes: 3 additions & 0 deletions src/math/special_functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub mod acosh;
pub mod airy;
pub mod asinh;
pub mod atanh;
pub mod bessel;
pub mod beta;
pub mod binomial;
Expand Down
24 changes: 17 additions & 7 deletions wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

#include <boost/math/ccmath/sqrt.hpp>

#include <boost/math/special_functions/acosh.hpp>
#include <boost/math/special_functions/airy.hpp>
#include <boost/math/special_functions/asinh.hpp>
#include <boost/math/special_functions/atanh.hpp>
#include <boost/math/special_functions/bessel.hpp>
#include <boost/math/special_functions/beta.hpp>
#include <boost/math/special_functions/binomial.hpp>
Expand Down Expand Up @@ -109,13 +112,12 @@ extern "C" {
// boost/math/ccmath/sqrt.hpp
double math_ccmath_sqrt(double x) { return ccmath::sqrt(x); }

// boost/math/special_functions/bessel.hpp
double math_cyl_bessel_j(double nu, double x) { return cyl_bessel_j(nu, x); }
double math_cyl_neumann(double nu, double x) { return cyl_neumann(nu, x); }
double math_cyl_bessel_i(double nu, double x) { return cyl_bessel_i(nu, x); }
double math_cyl_bessel_k(double nu, double x) { return cyl_bessel_k(nu, x); }
double math_sph_bessel(unsigned n, double x) { return sph_bessel(n, x); }
double math_sph_neumann(unsigned n, double x) { return sph_neumann(n, x); }
// boost/math/special_functions/acosh.hpp
double math_acosh(double x) { return acosh(x); }
// boost/math/special_functions/asinh.hpp
double math_asinh(double x) { return asinh(x); }
// boost/math/special_functions/atanh.hpp
double math_atanh(double x) { return atanh(x); }

// boost/math/special_functions/airy.hpp
double math_airy_ai(double x) { return airy_ai(x); }
Expand All @@ -125,6 +127,14 @@ double math_airy_bi(double x) { return airy_bi(x); }
double math_airy_bi_prime(double x) { return airy_bi_prime(x); }
double math_airy_bi_zero(int m) { return airy_bi_zero<double>(m); }

// boost/math/special_functions/bessel.hpp
double math_cyl_bessel_j(double nu, double x) { return cyl_bessel_j(nu, x); }
double math_cyl_neumann(double nu, double x) { return cyl_neumann(nu, x); }
double math_cyl_bessel_i(double nu, double x) { return cyl_bessel_i(nu, x); }
double math_cyl_bessel_k(double nu, double x) { return cyl_bessel_k(nu, x); }
double math_sph_bessel(unsigned n, double x) { return sph_bessel(n, x); }
double math_sph_neumann(unsigned n, double x) { return sph_neumann(n, x); }

// boost/math/special_functions/beta.hpp
double math_beta(double a, double b) { return beta(a, b); }
double math_beta_(double a, double b, double x) { return beta(a, b, x); }
Expand Down
Loading