Skip to content

Commit

Permalink
exact abs
Browse files Browse the repository at this point in the history
  • Loading branch information
bksaiki committed Oct 9, 2023
1 parent fe343fd commit ccff825
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/real/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use crate::{
ops::{RoundedAdd, RoundedMul, RoundedNeg, RoundedSub},
ops::{RoundedAdd, RoundedMul, RoundedNeg, RoundedSub, RoundedAbs},
rfloat::RFloat,
Real, RoundingContext,
};
Expand All @@ -22,6 +22,17 @@ impl RoundedNeg for RealContext {
}
}

impl RoundedAbs for RealContext {
fn abs<N: Real>(&self, src: &N) -> Self::Rounded {
let src = self.round(src); // convert (exactly) to RFloat
match src {
RFloat::Real(_, exp, c) => RFloat::Real(false, exp, c),
RFloat::Infinite(_) => RFloat::Infinite(false),
RFloat::Nan => RFloat::Nan,
}
}
}

impl RoundedAdd for RealContext {
fn add<N1, N2>(&self, src1: &N1, src2: &N2) -> Self::Rounded
where
Expand Down

0 comments on commit ccff825

Please sign in to comment.