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