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