| 
4 | 4 | //! a struct named `Operation` that implements [`MpOp`].  | 
5 | 5 | 
  | 
6 | 6 | use std::cmp::Ordering;  | 
7 |  | -use std::ffi::{c_int, c_long};  | 
8 | 7 | 
 
  | 
9 |  | -use gmp_mpfr_sys::mpfr::rnd_t;  | 
10 | 8 | use rug::Assign;  | 
11 | 9 | pub use rug::Float as MpFloat;  | 
12 | 10 | use rug::az::{self, Az};  | 
13 |  | -use rug::float::Round;  | 
14 | 11 | use rug::float::Round::Nearest;  | 
15 | 12 | use rug::ops::{PowAssignRound, RemAssignRound};  | 
16 | 13 | 
 
  | 
@@ -401,28 +398,20 @@ macro_rules! impl_op_for_ty {  | 
401 | 398 |             }  | 
402 | 399 | 
 
  | 
403 | 400 |             impl MpOp for crate::op::[<remquo $suffix>]::Routine {  | 
404 |  | -                type MpTy = (MpFloat, MpFloat, MpFloat);  | 
 | 401 | +                type MpTy = (MpFloat, MpFloat);  | 
405 | 402 | 
 
  | 
406 | 403 |                 fn new_mp() -> Self::MpTy {  | 
407 | 404 |                     (  | 
408 | 405 |                         new_mpfloat::<Self::FTy>(),  | 
409 | 406 |                         new_mpfloat::<Self::FTy>(),  | 
410 |  | -                        new_mpfloat::<Self::FTy>()  | 
411 | 407 |                     )  | 
412 | 408 |                 }  | 
413 | 409 | 
 
  | 
414 | 410 |                 fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {  | 
415 | 411 |                     this.0.assign(input.0);  | 
416 | 412 |                     this.1.assign(input.1);  | 
417 |  | -                    let (ord, ql) = mpfr_remquo(&mut this.2, &this.0, &this.1, Nearest);  | 
418 |  | - | 
419 |  | -                    // `remquo` integer results are sign-magnitude representation. Transfer the  | 
420 |  | -                    // sign bit from the long result to the int result.  | 
421 |  | -                    let clear = !(1 << (c_int::BITS - 1));  | 
422 |  | -                    let sign = ((ql >> (c_long::BITS - 1)) as i32) << (c_int::BITS - 1);  | 
423 |  | -                    let q = (ql as i32) & clear | sign;  | 
424 |  | - | 
425 |  | -                    (prep_retval::<Self::FTy>(&mut this.2, ord), q)  | 
 | 413 | +                    let (ord, q) = this.0.remainder_quo31_round(&this.1, Nearest);  | 
 | 414 | +                    (prep_retval::<Self::FTy>(&mut this.0, ord), q)  | 
426 | 415 |                 }  | 
427 | 416 |             }  | 
428 | 417 | 
 
  | 
@@ -547,24 +536,3 @@ impl MpOp for crate::op::nextafterf::Routine {  | 
547 | 536 |         unimplemented!("nextafter does not yet have a MPFR operation");  | 
548 | 537 |     }  | 
549 | 538 | }  | 
550 |  | - | 
551 |  | -/// `rug` does not provide `remquo` so this exposes `mpfr_remquo`. See rug#76.  | 
552 |  | -fn mpfr_remquo(r: &mut MpFloat, x: &MpFloat, y: &MpFloat, round: Round) -> (Ordering, c_long) {  | 
553 |  | -    let r = r.as_raw_mut();  | 
554 |  | -    let x = x.as_raw();  | 
555 |  | -    let y = y.as_raw();  | 
556 |  | -    let mut q: c_long = 0;  | 
557 |  | - | 
558 |  | -    let round = match round {  | 
559 |  | -        Round::Nearest => rnd_t::RNDN,  | 
560 |  | -        Round::Zero => rnd_t::RNDZ,  | 
561 |  | -        Round::Up => rnd_t::RNDU,  | 
562 |  | -        Round::Down => rnd_t::RNDD,  | 
563 |  | -        Round::AwayZero => rnd_t::RNDA,  | 
564 |  | -        _ => unreachable!(),  | 
565 |  | -    };  | 
566 |  | - | 
567 |  | -    // SAFETY: mutable and const pointers are valid and do not alias, by Rust's rules.  | 
568 |  | -    let ord = unsafe { gmp_mpfr_sys::mpfr::remquo(r, &mut q, x, y, round) };  | 
569 |  | -    (ord.cmp(&0), q)  | 
570 |  | -}  | 
0 commit comments