Skip to content

Commit

Permalink
Add precision tracking and upgrading for Float
Browse files Browse the repository at this point in the history
- Fix precision of float formatting
  • Loading branch information
benruijl committed Jun 24, 2024
1 parent 85834c4 commit 537c0bf
Show file tree
Hide file tree
Showing 5 changed files with 598 additions and 119 deletions.
17 changes: 9 additions & 8 deletions src/coefficient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,15 @@ impl CoefficientView<'_> {
let f = f.to_float();
let p = f.prec();
(
f.powf(Rational::new(n2, d2).to_multi_prec_float(p)).into(),
f.powf(&Rational::new(n2, d2).to_multi_prec_float(p)).into(),
Coefficient::one(),
)
}
(&CoefficientView::Float(f), &CoefficientView::Large(r)) => {
let f = f.to_float();
let p = f.prec();
(
f.powf(Rational::from_large(r.to_rat()).to_multi_prec_float(p))
f.powf(&Rational::from_large(r.to_rat()).to_multi_prec_float(p))
.into(),
Coefficient::one(),
)
Expand All @@ -553,7 +553,7 @@ impl CoefficientView<'_> {
let f = f.to_float();
let p = f.prec();
(
Rational::new(n2, d2).to_multi_prec_float(p).powf(f).into(),
Rational::new(n2, d2).to_multi_prec_float(p).powf(&f).into(),
Coefficient::one(),
)
}
Expand All @@ -563,14 +563,15 @@ impl CoefficientView<'_> {
(
Rational::from_large(r.to_rat())
.to_multi_prec_float(p)
.powf(f)
.powf(&f)
.into(),
Coefficient::one(),
)
}
(&CoefficientView::Float(f1), &CoefficientView::Float(f2)) => {
(f1.to_float().powf(f2.to_float()).into(), Coefficient::one())
}
(&CoefficientView::Float(f1), &CoefficientView::Float(f2)) => (
f1.to_float().powf(&f2.to_float()).into(),
Coefficient::one(),
),
_ => {
unimplemented!(
"Power of configuration {:?}^{:?} is not implemented",
Expand Down Expand Up @@ -1374,7 +1375,7 @@ mod test {
);
assert_eq!(
r,
"1.5707963267948966192313216916397514420985846996875529104874722*x+21.472450421034924682062764237715547275896106906504257500510430"
"1.5707963267948966192313216916397514420985846996875529104874722*x+21.472450421034925"
);
}

Expand Down
Loading

0 comments on commit 537c0bf

Please sign in to comment.