We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8313cec commit 72ed4c8Copy full SHA for 72ed4c8
src/float/pow.rs
@@ -1,11 +1,12 @@
1
use int::Int;
2
+use float::Float;
3
-/// Returns `a` raised to the power `b`
4
-macro_rules! pow {
5
- ($a: expr, $b: expr) => ({
6
- let (mut a, mut b) = ($a, $b);
+trait Pow: Float {
+ /// Returns `a` raised to the power `b`
+ fn pow(self, mut b: i32) -> Self {
7
+ let mut a = self;
8
let recip = b < 0;
- let mut r = 1.0;
9
+ let mut r = Self::ONE;
10
loop {
11
if (b & 1) != 0 {
12
r *= a;
@@ -18,19 +19,22 @@ macro_rules! pow {
18
19
}
20
21
if recip {
- 1.0 / r
22
+ Self::ONE / r
23
} else {
24
r
25
- })
26
+ }
27
28
29
+impl Pow for f32 {}
30
+impl Pow for f64 {}
31
+
32
intrinsics! {
33
pub extern "C" fn __powisf2(a: f32, b: i32) -> f32 {
- pow!(a, b)
34
+ a.pow(b)
35
36
37
pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
38
39
40
0 commit comments