Skip to content

Commit

Permalink
Merge branch 'float_to_neg_exp' of git://github.com/WaffleLapkin/type…
Browse files Browse the repository at this point in the history
…num into WaffleLapkin-float_to_neg_exp
  • Loading branch information
paholg committed Mar 12, 2021
2 parents 932263f + 841b7a3 commit 72f4f52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ version.
- [changed] Allowed calling `assert_type_eq` and `assert_type` at top level.
- [added] Marker trait `Zero` for `Z0`, `U0`, and `B0`.

- [added] Implementation of `Pow` trait for f32 and f64 with negative exponent

### 1.12.0 (2020-04-13)
- [added] Feature `force_unix_path_separator` to support building without Cargo.
- [added] Greatest common divisor operator `Gcd` with alias `Gcf`.
Expand Down
15 changes: 15 additions & 0 deletions src/type_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ macro_rules! impl_pow_f {
acc
}
}

impl<U: Unsigned + NonZero> Pow<NInt<U>> for $t {
type Output = $t;

fn powi(self, _: NInt<U>) -> Self::Output {
<$t as Pow<PInt<U>>>::powi(self, PInt::new()).recip()
}
}
};
}

Expand Down Expand Up @@ -229,6 +237,7 @@ fn pow_test() {

let u0 = U0::new();
let u3 = U3::new();
let n3 = N3::new();

macro_rules! check {
($x:ident) => {
Expand All @@ -244,6 +253,12 @@ fn pow_test() {

assert!((<$f as Pow<P3>>::powi(*$x, p3) - $x * $x * $x).abs() < ::core::$f::EPSILON);
assert!((<$f as Pow<U3>>::powi(*$x, u3) - $x * $x * $x).abs() < ::core::$f::EPSILON);

if *$x == 0.0 {
assert!(<$f as Pow<N3>>::powi(*$x, n3).is_infinite());
} else {
assert!((<$f as Pow<N3>>::powi(*$x, n3) - 1. / $x / $x / $x).abs() < ::core::$f::EPSILON);
}
};
}

Expand Down

0 comments on commit 72f4f52

Please sign in to comment.