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