]> git.lizzy.rs Git - rust.git/blob - src/librustc_apfloat/lib.rs
Rollup merge of #52769 - sinkuu:stray_test, r=alexcrichton
[rust.git] / src / librustc_apfloat / lib.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Port of LLVM's APFloat software floating-point implementation from the
12 //! following C++ sources (please update commit hash when backporting):
13 //! <https://github.com/llvm-mirror/llvm/tree/23efab2bbd424ed13495a420ad8641cb2c6c28f9>
14 //!
15 //! * `include/llvm/ADT/APFloat.h` -> `Float` and `FloatConvert` traits
16 //! * `lib/Support/APFloat.cpp` -> `ieee` and `ppc` modules
17 //! * `unittests/ADT/APFloatTest.cpp` -> `tests` directory
18 //!
19 //! The port contains no unsafe code, global state, or side-effects in general,
20 //! and the only allocations are in the conversion to/from decimal strings.
21 //!
22 //! Most of the API and the testcases are intact in some form or another,
23 //! with some ergonomic changes, such as idiomatic short names, returning
24 //! new values instead of mutating the receiver, and having separate method
25 //! variants that take a non-default rounding mode (with the suffix `_r`).
26 //! Comments have been preserved where possible, only slightly adapted.
27 //!
28 //! Instead of keeping a pointer to a configuration struct and inspecting it
29 //! dynamically on every operation, types (e.g. `ieee::Double`), traits
30 //! (e.g. `ieee::Semantics`) and associated constants are employed for
31 //! increased type safety and performance.
32 //!
33 //! On-heap bigints are replaced everywhere (except in decimal conversion),
34 //! with short arrays of `type Limb = u128` elements (instead of `u64`),
35 //! This allows fitting the largest supported significands in one integer
36 //! (`ieee::Quad` and `ppc::Fallback` use slightly less than 128 bits).
37 //! All of the functions in the `ieee::sig` module operate on slices.
38 //!
39 //! # Note
40 //!
41 //! This API is completely unstable and subject to change.
42
43 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
44       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
45       html_root_url = "https://doc.rust-lang.org/nightly/")]
46 #![forbid(unsafe_code)]
47
48 #![feature(try_from)]
49 // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
50 #[allow(unused_extern_crates)]
51 extern crate rustc_cratesio_shim;
52
53 #[macro_use]
54 extern crate bitflags;
55
56 use std::cmp::Ordering;
57 use std::fmt;
58 use std::ops::{Neg, Add, Sub, Mul, Div, Rem};
59 use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
60 use std::str::FromStr;
61
62 bitflags! {
63     /// IEEE-754R 7: Default exception handling.
64     ///
65     /// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
66     #[must_use]
67     pub struct Status: u8 {
68         const OK = 0x00;
69         const INVALID_OP = 0x01;
70         const DIV_BY_ZERO = 0x02;
71         const OVERFLOW = 0x04;
72         const UNDERFLOW = 0x08;
73         const INEXACT = 0x10;
74     }
75 }
76
77 #[must_use]
78 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
79 pub struct StatusAnd<T> {
80     pub status: Status,
81     pub value: T,
82 }
83
84 impl Status {
85     pub fn and<T>(self, value: T) -> StatusAnd<T> {
86         StatusAnd {
87             status: self,
88             value,
89         }
90     }
91 }
92
93 impl<T> StatusAnd<T> {
94     pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> StatusAnd<U> {
95         StatusAnd {
96             status: self.status,
97             value: f(self.value),
98         }
99     }
100 }
101
102 #[macro_export]
103 macro_rules! unpack {
104     ($status:ident|=, $e:expr) => {
105         match $e {
106             $crate::StatusAnd { status, value } => {
107                 $status |= status;
108                 value
109             }
110         }
111     };
112     ($status:ident=, $e:expr) => {
113         match $e {
114             $crate::StatusAnd { status, value } => {
115                 $status = status;
116                 value
117             }
118         }
119     }
120 }
121
122 /// Category of internally-represented number.
123 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
124 pub enum Category {
125     Infinity,
126     NaN,
127     Normal,
128     Zero,
129 }
130
131 /// IEEE-754R 4.3: Rounding-direction attributes.
132 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
133 pub enum Round {
134     NearestTiesToEven,
135     TowardPositive,
136     TowardNegative,
137     TowardZero,
138     NearestTiesToAway,
139 }
140
141 impl Neg for Round {
142     type Output = Round;
143     fn neg(self) -> Round {
144         match self {
145             Round::TowardPositive => Round::TowardNegative,
146             Round::TowardNegative => Round::TowardPositive,
147             Round::NearestTiesToEven | Round::TowardZero | Round::NearestTiesToAway => self,
148         }
149     }
150 }
151
152 /// A signed type to represent a floating point number's unbiased exponent.
153 pub type ExpInt = i16;
154
155 // \c ilogb error results.
156 pub const IEK_INF: ExpInt = ExpInt::max_value();
157 pub const IEK_NAN: ExpInt = ExpInt::min_value();
158 pub const IEK_ZERO: ExpInt = ExpInt::min_value() + 1;
159
160 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
161 pub struct ParseError(pub &'static str);
162
163 /// A self-contained host- and target-independent arbitrary-precision
164 /// floating-point software implementation.
165 ///
166 /// `apfloat` uses significand bignum integer arithmetic as provided by functions
167 /// in the `ieee::sig`.
168 ///
169 /// Written for clarity rather than speed, in particular with a view to use in
170 /// the front-end of a cross compiler so that target arithmetic can be correctly
171 /// performed on the host. Performance should nonetheless be reasonable,
172 /// particularly for its intended use. It may be useful as a base
173 /// implementation for a run-time library during development of a faster
174 /// target-specific one.
175 ///
176 /// All 5 rounding modes in the IEEE-754R draft are handled correctly for all
177 /// implemented operations. Currently implemented operations are add, subtract,
178 /// multiply, divide, fused-multiply-add, conversion-to-float,
179 /// conversion-to-integer and conversion-from-integer. New rounding modes
180 /// (e.g. away from zero) can be added with three or four lines of code.
181 ///
182 /// Four formats are built-in: IEEE single precision, double precision,
183 /// quadruple precision, and x87 80-bit extended double (when operating with
184 /// full extended precision). Adding a new format that obeys IEEE semantics
185 /// only requires adding two lines of code: a declaration and definition of the
186 /// format.
187 ///
188 /// All operations return the status of that operation as an exception bit-mask,
189 /// so multiple operations can be done consecutively with their results or-ed
190 /// together. The returned status can be useful for compiler diagnostics; e.g.,
191 /// inexact, underflow and overflow can be easily diagnosed on constant folding,
192 /// and compiler optimizers can determine what exceptions would be raised by
193 /// folding operations and optimize, or perhaps not optimize, accordingly.
194 ///
195 /// At present, underflow tininess is detected after rounding; it should be
196 /// straight forward to add support for the before-rounding case too.
197 ///
198 /// The library reads hexadecimal floating point numbers as per C99, and
199 /// correctly rounds if necessary according to the specified rounding mode.
200 /// Syntax is required to have been validated by the caller.
201 ///
202 /// It also reads decimal floating point numbers and correctly rounds according
203 /// to the specified rounding mode.
204 ///
205 /// Non-zero finite numbers are represented internally as a sign bit, a 16-bit
206 /// signed exponent, and the significand as an array of integer limbs. After
207 /// normalization of a number of precision P the exponent is within the range of
208 /// the format, and if the number is not denormal the P-th bit of the
209 /// significand is set as an explicit integer bit. For denormals the most
210 /// significant bit is shifted right so that the exponent is maintained at the
211 /// format's minimum, so that the smallest denormal has just the least
212 /// significant bit of the significand set. The sign of zeros and infinities
213 /// is significant; the exponent and significand of such numbers is not stored,
214 /// but has a known implicit (deterministic) value: 0 for the significands, 0
215 /// for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and
216 /// significand are deterministic, although not really meaningful, and preserved
217 /// in non-conversion operations. The exponent is implicitly all 1 bits.
218 ///
219 /// `apfloat` does not provide any exception handling beyond default exception
220 /// handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause
221 /// by encoding Signaling NaNs with the first bit of its trailing significand
222 /// as 0.
223 ///
224 /// Future work
225 /// ===========
226 ///
227 /// Some features that may or may not be worth adding:
228 ///
229 /// Optional ability to detect underflow tininess before rounding.
230 ///
231 /// New formats: x87 in single and double precision mode (IEEE apart from
232 /// extended exponent range) (hard).
233 ///
234 /// New operations: sqrt, nexttoward.
235 ///
236 pub trait Float
237     : Copy
238     + Default
239     + FromStr<Err = ParseError>
240     + PartialOrd
241     + fmt::Display
242     + Neg<Output = Self>
243     + AddAssign
244     + SubAssign
245     + MulAssign
246     + DivAssign
247     + RemAssign
248     + Add<Output = StatusAnd<Self>>
249     + Sub<Output = StatusAnd<Self>>
250     + Mul<Output = StatusAnd<Self>>
251     + Div<Output = StatusAnd<Self>>
252     + Rem<Output = StatusAnd<Self>> {
253     /// Total number of bits in the in-memory format.
254     const BITS: usize;
255
256     /// Number of bits in the significand. This includes the integer bit.
257     const PRECISION: usize;
258
259     /// The largest E such that 2<sup>E</sup> is representable; this matches the
260     /// definition of IEEE 754.
261     const MAX_EXP: ExpInt;
262
263     /// The smallest E such that 2<sup>E</sup> is a normalized number; this
264     /// matches the definition of IEEE 754.
265     const MIN_EXP: ExpInt;
266
267     /// Positive Zero.
268     const ZERO: Self;
269
270     /// Positive Infinity.
271     const INFINITY: Self;
272
273     /// NaN (Not a Number).
274     // FIXME(eddyb) provide a default when qnan becomes const fn.
275     const NAN: Self;
276
277     /// Factory for QNaN values.
278     // FIXME(eddyb) should be const fn.
279     fn qnan(payload: Option<u128>) -> Self;
280
281     /// Factory for SNaN values.
282     // FIXME(eddyb) should be const fn.
283     fn snan(payload: Option<u128>) -> Self;
284
285     /// Largest finite number.
286     // FIXME(eddyb) should be const (but FloatPair::largest is nontrivial).
287     fn largest() -> Self;
288
289     /// Smallest (by magnitude) finite number.
290     /// Might be denormalized, which implies a relative loss of precision.
291     const SMALLEST: Self;
292
293     /// Smallest (by magnitude) normalized finite number.
294     // FIXME(eddyb) should be const (but FloatPair::smallest_normalized is nontrivial).
295     fn smallest_normalized() -> Self;
296
297     // Arithmetic
298
299     fn add_r(self, rhs: Self, round: Round) -> StatusAnd<Self>;
300     fn sub_r(self, rhs: Self, round: Round) -> StatusAnd<Self> {
301         self.add_r(-rhs, round)
302     }
303     fn mul_r(self, rhs: Self, round: Round) -> StatusAnd<Self>;
304     fn mul_add_r(self, multiplicand: Self, addend: Self, round: Round) -> StatusAnd<Self>;
305     fn mul_add(self, multiplicand: Self, addend: Self) -> StatusAnd<Self> {
306         self.mul_add_r(multiplicand, addend, Round::NearestTiesToEven)
307     }
308     fn div_r(self, rhs: Self, round: Round) -> StatusAnd<Self>;
309     /// IEEE remainder.
310     // This is not currently correct in all cases.
311     fn ieee_rem(self, rhs: Self) -> StatusAnd<Self> {
312         let mut v = self;
313
314         let status;
315         v = unpack!(status=, v / rhs);
316         if status == Status::DIV_BY_ZERO {
317             return status.and(self);
318         }
319
320         assert!(Self::PRECISION < 128);
321
322         let status;
323         let x = unpack!(status=, v.to_i128_r(128, Round::NearestTiesToEven, &mut false));
324         if status == Status::INVALID_OP {
325             return status.and(self);
326         }
327
328         let status;
329         let mut v = unpack!(status=, Self::from_i128(x));
330         assert_eq!(status, Status::OK); // should always work
331
332         let status;
333         v = unpack!(status=, v * rhs);
334         assert_eq!(status - Status::INEXACT, Status::OK); // should not overflow or underflow
335
336         let status;
337         v = unpack!(status=, self - v);
338         assert_eq!(status - Status::INEXACT, Status::OK); // likewise
339
340         if v.is_zero() {
341             status.and(v.copy_sign(self)) // IEEE754 requires this
342         } else {
343             status.and(v)
344         }
345     }
346     /// C fmod, or llvm frem.
347     fn c_fmod(self, rhs: Self) -> StatusAnd<Self>;
348     fn round_to_integral(self, round: Round) -> StatusAnd<Self>;
349
350     /// IEEE-754R 2008 5.3.1: nextUp.
351     fn next_up(self) -> StatusAnd<Self>;
352
353     /// IEEE-754R 2008 5.3.1: nextDown.
354     ///
355     /// *NOTE* since nextDown(x) = -nextUp(-x), we only implement nextUp with
356     /// appropriate sign switching before/after the computation.
357     fn next_down(self) -> StatusAnd<Self> {
358         (-self).next_up().map(|r| -r)
359     }
360
361     fn abs(self) -> Self {
362         if self.is_negative() { -self } else { self }
363     }
364     fn copy_sign(self, rhs: Self) -> Self {
365         if self.is_negative() != rhs.is_negative() {
366             -self
367         } else {
368             self
369         }
370     }
371
372     // Conversions
373     fn from_bits(input: u128) -> Self;
374     fn from_i128_r(input: i128, round: Round) -> StatusAnd<Self> {
375         if input < 0 {
376             Self::from_u128_r(input.wrapping_neg() as u128, -round).map(|r| -r)
377         } else {
378             Self::from_u128_r(input as u128, round)
379         }
380     }
381     fn from_i128(input: i128) -> StatusAnd<Self> {
382         Self::from_i128_r(input, Round::NearestTiesToEven)
383     }
384     fn from_u128_r(input: u128, round: Round) -> StatusAnd<Self>;
385     fn from_u128(input: u128) -> StatusAnd<Self> {
386         Self::from_u128_r(input, Round::NearestTiesToEven)
387     }
388     fn from_str_r(s: &str, round: Round) -> Result<StatusAnd<Self>, ParseError>;
389     fn to_bits(self) -> u128;
390
391     /// Convert a floating point number to an integer according to the
392     /// rounding mode. In case of an invalid operation exception,
393     /// deterministic values are returned, namely zero for NaNs and the
394     /// minimal or maximal value respectively for underflow or overflow.
395     /// If the rounded value is in range but the floating point number is
396     /// not the exact integer, the C standard doesn't require an inexact
397     /// exception to be raised. IEEE-854 does require it so we do that.
398     ///
399     /// Note that for conversions to integer type the C standard requires
400     /// round-to-zero to always be used.
401     ///
402     /// The *is_exact output tells whether the result is exact, in the sense
403     /// that converting it back to the original floating point type produces
404     /// the original value. This is almost equivalent to result==Status::OK,
405     /// except for negative zeroes.
406     fn to_i128_r(self, width: usize, round: Round, is_exact: &mut bool) -> StatusAnd<i128> {
407         let status;
408         if self.is_negative() {
409             if self.is_zero() {
410                 // Negative zero can't be represented as an int.
411                 *is_exact = false;
412             }
413             let r = unpack!(status=, (-self).to_u128_r(width, -round, is_exact));
414
415             // Check for values that don't fit in the signed integer.
416             if r > (1 << (width - 1)) {
417                 // Return the most negative integer for the given width.
418                 *is_exact = false;
419                 Status::INVALID_OP.and(-1 << (width - 1))
420             } else {
421                 status.and(r.wrapping_neg() as i128)
422             }
423         } else {
424             // Positive case is simpler, can pretend it's a smaller unsigned
425             // integer, and `to_u128` will take care of all the edge cases.
426             self.to_u128_r(width - 1, round, is_exact).map(
427                 |r| r as i128,
428             )
429         }
430     }
431     fn to_i128(self, width: usize) -> StatusAnd<i128> {
432         self.to_i128_r(width, Round::TowardZero, &mut true)
433     }
434     fn to_u128_r(self, width: usize, round: Round, is_exact: &mut bool) -> StatusAnd<u128>;
435     fn to_u128(self, width: usize) -> StatusAnd<u128> {
436         self.to_u128_r(width, Round::TowardZero, &mut true)
437     }
438
439     fn cmp_abs_normal(self, rhs: Self) -> Ordering;
440
441     /// Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
442     fn bitwise_eq(self, rhs: Self) -> bool;
443
444     // IEEE-754R 5.7.2 General operations.
445
446     /// Implements IEEE minNum semantics. Returns the smaller of the 2 arguments if
447     /// both are not NaN. If either argument is a NaN, returns the other argument.
448     fn min(self, other: Self) -> Self {
449         if self.is_nan() {
450             other
451         } else if other.is_nan() {
452             self
453         } else if other.partial_cmp(&self) == Some(Ordering::Less) {
454             other
455         } else {
456             self
457         }
458     }
459
460     /// Implements IEEE maxNum semantics. Returns the larger of the 2 arguments if
461     /// both are not NaN. If either argument is a NaN, returns the other argument.
462     fn max(self, other: Self) -> Self {
463         if self.is_nan() {
464             other
465         } else if other.is_nan() {
466             self
467         } else if self.partial_cmp(&other) == Some(Ordering::Less) {
468             other
469         } else {
470             self
471         }
472     }
473
474     /// IEEE-754R isSignMinus: Returns true if and only if the current value is
475     /// negative.
476     ///
477     /// This applies to zeros and NaNs as well.
478     fn is_negative(self) -> bool;
479
480     /// IEEE-754R isNormal: Returns true if and only if the current value is normal.
481     ///
482     /// This implies that the current value of the float is not zero, subnormal,
483     /// infinite, or NaN following the definition of normality from IEEE-754R.
484     fn is_normal(self) -> bool {
485         !self.is_denormal() && self.is_finite_non_zero()
486     }
487
488     /// Returns true if and only if the current value is zero, subnormal, or
489     /// normal.
490     ///
491     /// This means that the value is not infinite or NaN.
492     fn is_finite(self) -> bool {
493         !self.is_nan() && !self.is_infinite()
494     }
495
496     /// Returns true if and only if the float is plus or minus zero.
497     fn is_zero(self) -> bool {
498         self.category() == Category::Zero
499     }
500
501     /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
502     /// denormal.
503     fn is_denormal(self) -> bool;
504
505     /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
506     fn is_infinite(self) -> bool {
507         self.category() == Category::Infinity
508     }
509
510     /// Returns true if and only if the float is a quiet or signaling NaN.
511     fn is_nan(self) -> bool {
512         self.category() == Category::NaN
513     }
514
515     /// Returns true if and only if the float is a signaling NaN.
516     fn is_signaling(self) -> bool;
517
518     // Simple Queries
519
520     fn category(self) -> Category;
521     fn is_non_zero(self) -> bool {
522         !self.is_zero()
523     }
524     fn is_finite_non_zero(self) -> bool {
525         self.is_finite() && !self.is_zero()
526     }
527     fn is_pos_zero(self) -> bool {
528         self.is_zero() && !self.is_negative()
529     }
530     fn is_neg_zero(self) -> bool {
531         self.is_zero() && self.is_negative()
532     }
533
534     /// Returns true if and only if the number has the smallest possible non-zero
535     /// magnitude in the current semantics.
536     fn is_smallest(self) -> bool {
537         Self::SMALLEST.copy_sign(self).bitwise_eq(self)
538     }
539
540     /// Returns true if and only if the number has the largest possible finite
541     /// magnitude in the current semantics.
542     fn is_largest(self) -> bool {
543         Self::largest().copy_sign(self).bitwise_eq(self)
544     }
545
546     /// Returns true if and only if the number is an exact integer.
547     fn is_integer(self) -> bool {
548         // This could be made more efficient; I'm going for obviously correct.
549         if !self.is_finite() {
550             return false;
551         }
552         self.round_to_integral(Round::TowardZero).value.bitwise_eq(
553             self,
554         )
555     }
556
557     /// If this value has an exact multiplicative inverse, return it.
558     fn get_exact_inverse(self) -> Option<Self>;
559
560     /// Returns the exponent of the internal representation of the Float.
561     ///
562     /// Because the radix of Float is 2, this is equivalent to floor(log2(x)).
563     /// For special Float values, this returns special error codes:
564     ///
565     ///   NaN -> \c IEK_NAN
566     ///   0   -> \c IEK_ZERO
567     ///   Inf -> \c IEK_INF
568     ///
569     fn ilogb(self) -> ExpInt;
570
571     /// Returns: self * 2<sup>exp</sup> for integral exponents.
572     fn scalbn_r(self, exp: ExpInt, round: Round) -> Self;
573     fn scalbn(self, exp: ExpInt) -> Self {
574         self.scalbn_r(exp, Round::NearestTiesToEven)
575     }
576
577     /// Equivalent of C standard library function.
578     ///
579     /// While the C standard says exp is an unspecified value for infinity and nan,
580     /// this returns INT_MAX for infinities, and INT_MIN for NaNs (see `ilogb`).
581     fn frexp_r(self, exp: &mut ExpInt, round: Round) -> Self;
582     fn frexp(self, exp: &mut ExpInt) -> Self {
583         self.frexp_r(exp, Round::NearestTiesToEven)
584     }
585 }
586
587 pub trait FloatConvert<T: Float>: Float {
588     /// Convert a value of one floating point type to another.
589     /// The return value corresponds to the IEEE754 exceptions. *loses_info
590     /// records whether the transformation lost information, i.e. whether
591     /// converting the result back to the original type will produce the
592     /// original value (this is almost the same as return value==Status::OK,
593     /// but there are edge cases where this is not so).
594     fn convert_r(self, round: Round, loses_info: &mut bool) -> StatusAnd<T>;
595     fn convert(self, loses_info: &mut bool) -> StatusAnd<T> {
596         self.convert_r(Round::NearestTiesToEven, loses_info)
597     }
598 }
599
600 macro_rules! float_common_impls {
601     ($ty:ident<$t:tt>) => {
602         impl<$t> Default for $ty<$t> where Self: Float {
603             fn default() -> Self {
604                 Self::ZERO
605             }
606         }
607
608         impl<$t> ::std::str::FromStr for $ty<$t> where Self: Float {
609             type Err = ParseError;
610             fn from_str(s: &str) -> Result<Self, ParseError> {
611                 Self::from_str_r(s, Round::NearestTiesToEven).map(|x| x.value)
612             }
613         }
614
615         // Rounding ties to the nearest even, by default.
616
617         impl<$t> ::std::ops::Add for $ty<$t> where Self: Float {
618             type Output = StatusAnd<Self>;
619             fn add(self, rhs: Self) -> StatusAnd<Self> {
620                 self.add_r(rhs, Round::NearestTiesToEven)
621             }
622         }
623
624         impl<$t> ::std::ops::Sub for $ty<$t> where Self: Float {
625             type Output = StatusAnd<Self>;
626             fn sub(self, rhs: Self) -> StatusAnd<Self> {
627                 self.sub_r(rhs, Round::NearestTiesToEven)
628             }
629         }
630
631         impl<$t> ::std::ops::Mul for $ty<$t> where Self: Float {
632             type Output = StatusAnd<Self>;
633             fn mul(self, rhs: Self) -> StatusAnd<Self> {
634                 self.mul_r(rhs, Round::NearestTiesToEven)
635             }
636         }
637
638         impl<$t> ::std::ops::Div for $ty<$t> where Self: Float {
639             type Output = StatusAnd<Self>;
640             fn div(self, rhs: Self) -> StatusAnd<Self> {
641                 self.div_r(rhs, Round::NearestTiesToEven)
642             }
643         }
644
645         impl<$t> ::std::ops::Rem for $ty<$t> where Self: Float {
646             type Output = StatusAnd<Self>;
647             fn rem(self, rhs: Self) -> StatusAnd<Self> {
648                 self.c_fmod(rhs)
649             }
650         }
651
652         impl<$t> ::std::ops::AddAssign for $ty<$t> where Self: Float {
653             fn add_assign(&mut self, rhs: Self) {
654                 *self = (*self + rhs).value;
655             }
656         }
657
658         impl<$t> ::std::ops::SubAssign for $ty<$t> where Self: Float {
659             fn sub_assign(&mut self, rhs: Self) {
660                 *self = (*self - rhs).value;
661             }
662         }
663
664         impl<$t> ::std::ops::MulAssign for $ty<$t> where Self: Float {
665             fn mul_assign(&mut self, rhs: Self) {
666                 *self = (*self * rhs).value;
667             }
668         }
669
670         impl<$t> ::std::ops::DivAssign for $ty<$t> where Self: Float {
671             fn div_assign(&mut self, rhs: Self) {
672                 *self = (*self / rhs).value;
673             }
674         }
675
676         impl<$t> ::std::ops::RemAssign for $ty<$t> where Self: Float {
677             fn rem_assign(&mut self, rhs: Self) {
678                 *self = (*self % rhs).value;
679             }
680         }
681     }
682 }
683
684 pub mod ieee;
685 pub mod ppc;