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