Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make panic free in transcendental.rs #21

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
8 changes: 4 additions & 4 deletions src/transcendental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ where

let operand = D::from(operand);
if operand < D::from_num(1) {
let inverse = D::from_num(1).checked_div(operand).unwrap();
let inverse = D::from_num(1).checked_div(operand).ok_or(())?;
return Ok(-log2_inner::<D, D>(inverse));
};
return Ok(log2_inner::<D, D>(operand));
Expand Down Expand Up @@ -240,11 +240,11 @@ where
};
let neg = operand < ZERO;
if neg {
operand = -operand;
operand = operand.checked_neg().ok_or(())?;
};

let operand = D::from(operand);
let mut result = operand + D::from_num(1);
let mut result = operand.checked_add(D::from_num(1)).ok_or(())?;
let mut term = operand;

for i in 2..D::frac_nbits() {
Expand Down Expand Up @@ -317,7 +317,7 @@ where
}

/// power with integer exponend
pub fn powi<S,D>(operand: S, exponent: i32) -> Result<D, ()>
pub fn powi<S, D>(operand: S, exponent: i32) -> Result<D, ()>
where
S: Fixed + PartialOrd<ConstType>,
D: Fixed + PartialOrd<ConstType> + From<S> + From<ConstType>,
Expand Down
Loading