1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

//! Information on the properties of the Logarithm function can be found in Abramowitz & Stegun, Chapter 4.

use crate::Value;
use std::mem::MaybeUninit;

/// This routine computes the logarithm of x, \log(x), for x > 0.
#[doc(alias = "gsl_sf_log")]
pub fn log(x: f64) -> f64 {
    unsafe { sys::gsl_sf_log(x) }
}

/// This routine computes the logarithm of x, \log(x), for x > 0.
#[doc(alias = "gsl_sf_log_e")]
pub fn log_e(x: f64) -> (Value, ::types::Result) {
    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let ret = unsafe { sys::gsl_sf_log_e(x, result.as_mut_ptr()) };

    (::Value::from(ret), unsafe { result.assume_init() }.into())
}

/// This routine computes the logarithm of the magnitude of x, \log(|x|), for x \ne 0.
#[doc(alias = "gsl_sf_log_abs")]
pub fn log_abs(x: f64) -> f64 {
    unsafe { sys::gsl_sf_log_abs(x) }
}

/// This routine computes the logarithm of the magnitude of x, \log(|x|), for x \ne 0.
#[doc(alias = "gsl_sf_log_abs_e")]
pub fn log_abs_e(x: f64) -> (Value, ::types::Result) {
    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let ret = unsafe { sys::gsl_sf_log_abs_e(x, result.as_mut_ptr()) };

    (::Value::from(ret), unsafe { result.assume_init() }.into())
}

/// This routine computes the complex logarithm of z = z_r + i z_i.
/// The results are returned as lnr, theta such that \exp(lnr + i \theta) = z_r + i z_i, where \theta lies in the range [-\pi,\pi].
#[doc(alias = "gsl_sf_complex_log_e")]
pub fn complex_log_e(zr: f64, zi: f64) -> (Value, ::types::Result, ::types::Result) {
    let mut lnr = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let mut theta = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let ret = unsafe { sys::gsl_sf_complex_log_e(zr, zi, lnr.as_mut_ptr(), theta.as_mut_ptr()) };

    (
        Value::from(ret),
        unsafe { lnr.assume_init() }.into(),
        unsafe { theta.assume_init() }.into(),
    )
}

/// This routine computes \log(1 + x) for x > -1 using an algorithm that is accurate for small x.
#[doc(alias = "gsl_sf_log_1plusx")]
pub fn log_1plusx(x: f64) -> f64 {
    unsafe { sys::gsl_sf_log_1plusx(x) }
}

/// This routine computes \log(1 + x) for x > -1 using an algorithm that is accurate for small x.
#[doc(alias = "gsl_sf_log_1plusx_e")]
pub fn log_1plusx_e(x: f64) -> (Value, ::types::Result) {
    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let ret = unsafe { sys::gsl_sf_log_1plusx_e(x, result.as_mut_ptr()) };

    (::Value::from(ret), unsafe { result.assume_init() }.into())
}

/// This routine computes \log(1 + x) - x for x > -1 using an algorithm that is accurate for small x.
#[doc(alias = "gsl_sf_log_1plusx_mx")]
pub fn log_1plusx_mx(x: f64) -> f64 {
    unsafe { sys::gsl_sf_log_1plusx_mx(x) }
}

/// This routine computes \log(1 + x) - x for x > -1 using an algorithm that is accurate for small x.
#[doc(alias = "gsl_sf_log_1plusx_mx_e")]
pub fn log_1plusx_mx_e(x: f64) -> (Value, ::types::Result) {
    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
    let ret = unsafe { sys::gsl_sf_log_1plusx_mx_e(x, result.as_mut_ptr()) };

    (::Value::from(ret), unsafe { result.assume_init() }.into())
}