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