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