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