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