Skip to content

Commit f3eb94b

Browse files
committed
Ver 0.4.4
- Update dependencies (#48) - Export erfcx from public API - Add max iteration guard to gser/gcf to prevent potential infinite loops - Add input validation to beta() - Clarify misleading comment in faddeeva.rs
1 parent 914d84a commit f3eb94b

8 files changed

Lines changed: 39 additions & 14 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "puruspe"
3-
version = "0.4.3"
3+
version = "0.4.4"
44
authors = ["Axect <axect@outlook.kr>"]
55
description = "Pure Rust Special function library"
66
edition = "2018"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add this to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
puruspe = "0.4.3"
23+
puruspe = "0.4.4"
2424
```
2525

2626
## Example

RELEASES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Ver 0.4.4 (2026-03-17)
2+
3+
- Update dependencies ([#48](https://github.com/Axect/puruspe/pull/48))
4+
- Thanks to [**JSorngard**](https://github.com/JSorngard)
5+
- Export `erfcx` from public API
6+
- Add max iteration guard to `gser`/`gcf` to prevent potential infinite loops
7+
- Add input validation to `beta()`
8+
- Clarify misleading comment in faddeeva.rs
9+
110
# Ver 0.4.3 (2025-11-12)
211

312
- Implement the Gamma function by Toshio Fukushima with very low relative error

src/beta.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ const SWITCH: usize = 3000;
2626
/// # Returns
2727
///
2828
/// The value of the beta function $B(z,w)$
29+
///
30+
/// # Panics
31+
///
32+
/// Panics if `z` ≤ 0 or `w` ≤ 0.
2933
pub fn beta(z: f64, w: f64) -> f64 {
34+
assert!(z > 0f64 && w > 0f64, "Bad args in beta: z and w must be positive");
3035
(ln_gamma(z) + ln_gamma(w) - ln_gamma(z + w)).exp()
3136
}
3237

src/faddeeva.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn faddeeva(re: f64, im: f64) -> (f64, f64) {
243243
let t_next = TAYLOR_COEFFS[idx + 1];
244244
let dz = c64::new(xabs - t, yabs - t_next);
245245

246-
// Something is wrong here...
246+
// Horner's method: loop stops at k=1 (not k=0), matching libcerf
247247
let nk = TILES[i_tile + 1];
248248
res = c64::new(
249249
TAYLOR_COEFFS[(idx as isize + 2 * nk as isize) as usize],

src/gamma.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ pub fn gammq(a: f64, x: f64) -> f64 {
283283

284284
/// Series expansion
285285
fn gser(a: f64, x: f64) -> f64 {
286+
const MAXIT: usize = 10_000;
286287
let gln = ln_gamma(a);
287288
let mut ap = a;
288289
let mut del = 1f64 / a;
289290
let mut sum = 1f64 / a;
290-
loop {
291+
for _ in 0..MAXIT {
291292
ap += 1f64;
292293
del *= x / ap;
293294
sum += del;
@@ -305,18 +306,28 @@ fn gser(a: f64, x: f64) -> f64 {
305306
return sum * log_result.exp();
306307
}
307308
}
309+
// Return best estimate if not fully converged
310+
let log_result = -x + a * x.ln() - gln;
311+
if log_result > 700.0 {
312+
sum * f64::INFINITY
313+
} else if log_result < -700.0 {
314+
0.0
315+
} else {
316+
sum * log_result.exp()
317+
}
308318
}
309319

310320
/// Continued Fraction
311321
fn gcf(a: f64, x: f64) -> f64 {
322+
const MAXIT: usize = 10_000;
312323
let gln = ln_gamma(a);
313324
let mut b = x + 1f64 - a;
314325
let mut c = 1f64 / FPMIN;
315326
let mut d = 1f64 / b;
316327
let mut h = d;
317328
let mut an: f64;
318-
for i in 1.. {
319-
an = -i as f64 * (i as f64 - a);
329+
for i in 1..=MAXIT {
330+
an = -(i as f64) * (i as f64 - a);
320331
b += 2f64;
321332
d = an * d + b;
322333
if d.abs() < FPMIN {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod beta;
1616
pub use beta::{beta, betai, invbetai};
1717

1818
pub mod error;
19-
pub use error::{erf, erfc, inverf, inverfc};
19+
pub use error::{erf, erfc, erfcx, inverf, inverfc};
2020

2121
pub mod dawson;
2222
pub use dawson::dawson;

0 commit comments

Comments
 (0)