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