Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 8 additions & 9 deletions src/airy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::bindings;
use crate::utils::c_complex64_nan;
use num_complex::Complex;
use std::os::raw::c_int;

Expand Down Expand Up @@ -53,10 +52,10 @@ impl AiryArg for Complex<f64> {

#[inline(always)]
fn airy(self) -> (Self::Output, Self::Output, Self::Output, Self::Output) {
let mut ai = c_complex64_nan();
let mut bi = c_complex64_nan();
let mut ad = c_complex64_nan();
let mut bd = c_complex64_nan();
let mut ai = bindings::complex_nan();
let mut bi = bindings::complex_nan();
let mut ad = bindings::complex_nan();
let mut bd = bindings::complex_nan();

unsafe {
bindings::airy_1(self.into(), &mut ai, &mut bi, &mut ad, &mut bd);
Expand All @@ -66,10 +65,10 @@ impl AiryArg for Complex<f64> {

#[inline(always)]
fn airye(self) -> (Self::Output, Self::Output, Self::Output, Self::Output) {
let mut ai = c_complex64_nan();
let mut bi = c_complex64_nan();
let mut ad = c_complex64_nan();
let mut bd = c_complex64_nan();
let mut ai = bindings::complex_nan();
let mut bi = bindings::complex_nan();
let mut ad = bindings::complex_nan();
let mut bd = bindings::complex_nan();

unsafe {
bindings::airye_1(self.into(), &mut ai, &mut bi, &mut ad, &mut bd);
Expand Down
16 changes: 9 additions & 7 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
#![allow(non_camel_case_types)]
#![allow(dead_code)]

use num_complex::Complex;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

pub(crate) use root::xsf_wrapper::*;

impl root::std::complex<f64> {
pub(crate) fn new(re: f64, im: f64) -> Self {
unsafe { complex__new(re, im) }
}
}

impl From<Complex<f64>> for root::std::complex<f64> {
fn from(z: Complex<f64>) -> Self {
impl From<num_complex::Complex<f64>> for root::std::complex<f64> {
fn from(z: num_complex::Complex<f64>) -> Self {
Self::new(z.re, z.im)
}
}

impl From<root::std::complex<f64>> for Complex<f64> {
impl From<root::std::complex<f64>> for num_complex::Complex<f64> {
fn from(z: root::std::complex<f64>) -> Self {
let mut re: f64 = 0.0;
let mut im: f64 = 0.0;
Expand All @@ -32,6 +28,11 @@ impl From<root::std::complex<f64>> for Complex<f64> {
}
}

#[inline(always)]
pub(crate) fn complex_nan() -> root::std::complex<f64> {
root::std::complex::new(f64::NAN, f64::NAN)
}

macro_rules! xsf_impl {
($name:ident, ($($param:ident: $type:ty),*), $docs:expr) => {
#[doc = $docs]
Expand All @@ -41,4 +42,5 @@ macro_rules! xsf_impl {
};
}

pub(crate) use root::xsf_wrapper::*;
pub(crate) use xsf_impl;
13 changes: 6 additions & 7 deletions src/fresnel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::bindings;
use crate::utils::c_complex64_nan;
use num_complex::Complex;

mod sealed {
Expand Down Expand Up @@ -34,8 +33,8 @@ impl FresnelArg for Complex<f64> {

#[inline(always)]
fn fresnel(self) -> (Self::Output, Self::Output) {
let mut fs = c_complex64_nan();
let mut fc = c_complex64_nan();
let mut fs = bindings::complex_nan();
let mut fc = bindings::complex_nan();

unsafe {
bindings::fresnel_1(self.into(), &mut fs, &mut fc);
Expand Down Expand Up @@ -91,8 +90,8 @@ pub fn fresnel<T: FresnelArg>(z: T) -> (T::Output, T::Output) {
/// - [`fresnel`] - Standard Fresnel integrals
/// - [`modified_fresnel_minus`] - Modified Fresnel negative integrals
pub fn modified_fresnel_plus(x: f64) -> (Complex<f64>, Complex<f64>) {
let mut fp = c_complex64_nan();
let mut kp = c_complex64_nan();
let mut fp = bindings::complex_nan();
let mut kp = bindings::complex_nan();
unsafe {
bindings::modified_fresnel_plus(x, &mut fp, &mut kp);
}
Expand Down Expand Up @@ -120,8 +119,8 @@ pub fn modified_fresnel_plus(x: f64) -> (Complex<f64>, Complex<f64>) {
/// - [`fresnel`] - Standard Fresnel integrals
/// - [`modified_fresnel_plus`] - Modified Fresnel positive integrals
pub fn modified_fresnel_minus(x: f64) -> (Complex<f64>, Complex<f64>) {
let mut fm = c_complex64_nan();
let mut km = c_complex64_nan();
let mut fm = bindings::complex_nan();
let mut km = bindings::complex_nan();
unsafe {
bindings::modified_fresnel_minus(x, &mut fm, &mut km);
}
Expand Down
9 changes: 4 additions & 5 deletions src/kelvin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::bindings;
use crate::bindings::xsf_impl;
use crate::utils::c_complex64_nan;
use num_complex::Complex;

xsf_impl!(ber, (x: f64), "Kelvin function `ber`");
Expand All @@ -24,10 +23,10 @@ xsf_impl!(keip, (x: f64), "Derivative of the Kelvin function `kei`");
/// - *Be*': Derivative of the Kelvin function [`berp`] + *i* [`beip`]
/// - *Ke*': Derivative of the Kelvin function [`kerp`] + *i* [`keip`]
pub fn kelvin(x: f64) -> (Complex<f64>, Complex<f64>, Complex<f64>, Complex<f64>) {
let mut be = c_complex64_nan();
let mut ke = c_complex64_nan();
let mut bep = c_complex64_nan();
let mut kep = c_complex64_nan();
let mut be = bindings::complex_nan();
let mut ke = bindings::complex_nan();
let mut bep = bindings::complex_nan();
let mut kep = bindings::complex_nan();
unsafe {
bindings::kelvin(x, &mut be, &mut ke, &mut bep, &mut kep);
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod bindings;
mod utils;

#[cfg(test)]
mod test_utils;
Expand Down
9 changes: 4 additions & 5 deletions src/sici.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::bindings;
use crate::utils::c_complex64_nan;
use num_complex::Complex;

mod sealed {
Expand Down Expand Up @@ -48,8 +47,8 @@ impl SiciArg for Complex<f64> {

#[inline(always)]
fn sici(self) -> (Self::Output, Self::Output) {
let mut si = c_complex64_nan();
let mut ci = c_complex64_nan();
let mut si = bindings::complex_nan();
let mut ci = bindings::complex_nan();

unsafe {
bindings::sici_1(self.into(), &mut si, &mut ci);
Expand All @@ -59,8 +58,8 @@ impl SiciArg for Complex<f64> {

#[inline(always)]
fn shichi(self) -> (Self::Output, Self::Output) {
let mut shi = c_complex64_nan();
let mut chi = c_complex64_nan();
let mut shi = bindings::complex_nan();
let mut chi = bindings::complex_nan();

unsafe {
bindings::shichi_1(self.into(), &mut shi, &mut chi);
Expand Down
6 changes: 0 additions & 6 deletions src/utils.rs

This file was deleted.

Loading