real_bessel/lib.rs
1#![warn(missing_docs, clippy::all, clippy::pedantic)]
2#![allow(clippy::many_single_char_names)]
3//! Real-valued Bessel functions of the first and second kinds.
4//!
5//! This crate provides `j0`, `j1`, `jn`, `y0`, `y1` and `yn` for integer
6//! orders and real (`f64`) arguments.
7//!
8//! ## Return types
9//!
10//! The **J functions** (`j0`, `j1`, `jn`) are real-valued for all real x and
11//! return `f64` directly.
12//!
13//! The **Y functions** (`y0`, `y1`, `yn`) are real-valued only for positive x.
14//! For `x < 0` they return `Err(`[`BesselError::NegativeInputForYFunction`]`)`
15//! rather than a complex result.
16//!
17//! ## Special cases shared by all functions
18//!
19//! | Input | J functions | Y functions |
20//! |-------|------------|-------------|
21//! | `NaN` | `NaN` | `Ok(NaN)` |
22//! | `+∞` | `0.0` | `Ok(0.0)` |
23//! | `x < 0` | real result | `Err(…)` |
24//! | `x = 0` | `j0 → 1`, `j1/jn → 0` | `Ok(−∞)` |
25//!
26//! If you need complex arguments, non-integer orders, or other Bessel
27//! varieties (I, K, H), see the
28//! [`amos-bessel-rs`](https://crates.io/crates/amos-bessel-rs) crate.
29//!
30//! ## Example
31//!
32//! ```
33//! use real_bessel::j0;
34//!
35//! let result = j0(1.0);
36//! assert!((result - 0.7651976865579612).abs() < 1e-10);
37//! ```
38
39#![cfg_attr(not(feature = "std"), no_std)]
40
41mod types;
42pub use types::BesselError;
43
44mod prelude {
45 pub use core::convert::Into;
46 pub use core::iter::Iterator;
47 pub use core::result::Result;
48 pub use num::Float;
49}
50
51mod j0;
52mod j1;
53mod jn;
54pub use j0::j0;
55pub use j0::y0;
56pub use j1::j1;
57pub use j1::y1;
58pub use jn::jn;
59pub use jn::yn;
60
61#[allow(clippy::cast_precision_loss)]
62pub(crate) const TWO_M13: f64 = 1.0 / (1 << 13) as f64; // 2**-13 0x3f20000000000000
63#[allow(clippy::cast_precision_loss)]
64pub(crate) const TWO_M27: f64 = 1.0 / (1 << 27) as f64; // 2**-27 0x3e40000000000000
65#[allow(clippy::cast_precision_loss)]
66pub(crate) const TWO_M29: f64 = 1.0 / (1 << 29) as f64; // 2**-29
67#[allow(clippy::cast_precision_loss)]
68pub(crate) const TWO_M54: f64 = 1.0 / (1_u64 << 54) as f64; // 2**-54 0x3c90000000000000
69#[allow(clippy::cast_precision_loss)]
70pub(crate) const TWO_129: f64 = 6.805_647_338_418_77e38; // 2**129 0x4800000000000000
71#[allow(clippy::cast_precision_loss)]
72pub(crate) const TWO_302: f64 = 8.148_143_905_337_944e90; // 2**302 0x52D0000000000000