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