pow.rs 753 B

123456789101112131415161718192021222324252627282930
  1. macro_rules! pow {
  2. ($intrinsic:ident: $fty:ty, $ity:ident) => {
  3. /// Returns `a` raised to the power `b`
  4. #[cfg_attr(not(test), no_mangle)]
  5. pub extern "C" fn $intrinsic(a: $fty, b: $ity) -> $fty {
  6. let (mut a, mut b) = (a, b);
  7. let recip = b < 0;
  8. let mut r: $fty = 1.0;
  9. loop {
  10. if (b & 1) != 0 {
  11. r *= a;
  12. }
  13. b = sdiv!($ity, b, 2);
  14. if b == 0 {
  15. break;
  16. }
  17. a *= a;
  18. }
  19. if recip {
  20. 1.0 / r
  21. } else {
  22. r
  23. }
  24. }
  25. }
  26. }
  27. pow!(__powisf2: f32, i32);
  28. pow!(__powidf2: f64, i32);