Skip to content

Commit

Permalink
Add comments about edge cases in the implementation of the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JSorngard committed Dec 27, 2024
1 parent 65d455f commit 52795e5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/dw0c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use crate::{
rational::{rational_7_over_7, rational_8_over_7},
};

// This is an implementation of the approximation of the principal
// branch of the Lambert W function
// with 50 bits of accuracy from Fukushima's paper.
// It returns f64::NAN if the input is negative or NAN,
// and f64::INFINITY if the input is positive infinity.

/// zc = z + 1/e
pub fn dw0c(zc: f64) -> f64 {
if zc < 0.0 || zc.is_nan() {
Expand Down
6 changes: 6 additions & 0 deletions src/dwm1c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use crate::{
rational::rational_7_over_7,
};

// This is an implementation of the approximation of the secondary
// branch of the Lambert W function
// with 50 bits of accuracy from Fukushima's paper.
// It returns f64::NAN if the input is negative, NAN, or larger than or equal to 0.
// It returns f64::INFINITY if the input is positive infinity.

/// zc = z + 1/e
pub fn dwm1c(z: f64, zc: f64) -> f64 {
if zc < 0.0 {
Expand Down
6 changes: 6 additions & 0 deletions src/sw0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use crate::{
rational::{rational_3_over_3, rational_4_over_3},
};

// This is an implementation of the approximation of the principal
// branch of the Lambert W function
// with 24 bits of accuracy from Fukushima's paper.
// It returns f64::NAN if the input is negative or NAN,
// and f64::INFINITY if the input is positive infinity.

pub fn sw0(z: f64) -> f64 {
if z < NEG_INV_E || z.is_nan() {
f64::NAN
Expand Down
6 changes: 6 additions & 0 deletions src/sw0f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use crate::{

const NEG_INV_E: f32 = Z0 as f32;

// This is an implementation of the approximation of the principal
// branch of the Lambert W function
// with 25 bits of accuracy from Fukushima's paper.
// It returns f32::NAN if the input is negative or NAN,
// and f32::INFINITY if the input is positive infinity.

pub fn sw0f(z: f32) -> f32 {
if z < NEG_INV_E || z.is_nan() {
f32::NAN
Expand Down
6 changes: 6 additions & 0 deletions src/swm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use crate::{
rational::rational_3_over_3,
};

// This is an implementation of the approximation of the secondary
// branch of the Lambert W function
// with 24 bits of accuracy from Fukushima's paper.
// It returns f64::NAN if the input is negative, NAN, or larger than or equal to 0.
// It returns f64::INFINITY if the input is positive infinity.

pub fn swm1(z: f64) -> f64 {
if z < NEG_INV_E {
f64::NAN
Expand Down
6 changes: 6 additions & 0 deletions src/swm1f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ use crate::{
const INV_SQRT_E: f32 = X0 as f32;
const NEG_INV_E: f32 = Z0 as f32;

// This is an implementation of the approximation of the secondary
// branch of the Lambert W function
// with 24 bits of accuracy from Fukushima's paper.
// It returns f32::NAN if the input is negative, NAN, or larger than or equal to 0.
// It returns f32::INFINITY if the input is positive infinity.

pub fn swm1f(z: f32) -> f32 {
if z < NEG_INV_E {
f32::NAN
Expand Down

0 comments on commit 52795e5

Please sign in to comment.