]> git.lizzy.rs Git - rust.git/blob - src/librustc_apfloat/ppc.rs
rustc_apfloat: stub IEEE & PPC implementations.
[rust.git] / src / librustc_apfloat / ppc.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 use {ieee, Category, ExpInt, Float, Round, ParseError, StatusAnd};
12
13 use std::cmp::Ordering;
14 use std::fmt;
15 use std::ops::Neg;
16
17 #[must_use]
18 #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
19 pub struct DoubleFloat<F>(F, F);
20 pub type DoubleDouble = DoubleFloat<ieee::Double>;
21
22 // These are legacy semantics for the Fallback, inaccrurate implementation of
23 // IBM double-double, if the accurate DoubleDouble doesn't handle the
24 // operation. It's equivalent to having an IEEE number with consecutive 106
25 // bits of mantissa and 11 bits of exponent.
26 //
27 // It's not equivalent to IBM double-double. For example, a legit IBM
28 // double-double, 1 + epsilon:
29 //
30 //   1 + epsilon = 1 + (1 >> 1076)
31 //
32 // is not representable by a consecutive 106 bits of mantissa.
33 //
34 // Currently, these semantics are used in the following way:
35 //
36 //   DoubleDouble -> (Double, Double) ->
37 //   DoubleDouble's Fallback -> IEEE operations
38 //
39 // FIXME: Implement all operations in DoubleDouble, and delete these
40 // semantics.
41 // FIXME(eddyb) This shouldn't need to be `pub`, it's only used in bounds.
42 pub struct FallbackS<F>(F);
43 type Fallback<F> = ieee::IeeeFloat<FallbackS<F>>;
44 impl<F: Float> ieee::Semantics for FallbackS<F> {
45     // Forbid any conversion to/from bits.
46     const BITS: usize = 0;
47     const PRECISION: usize = F::PRECISION * 2;
48     const MAX_EXP: ExpInt = F::MAX_EXP as ExpInt;
49     const MIN_EXP: ExpInt = F::MIN_EXP as ExpInt + F::PRECISION as ExpInt;
50 }
51
52 float_common_impls!(DoubleFloat<F>);
53
54 impl<F: Float> Neg for DoubleFloat<F> {
55     type Output = Self;
56     fn neg(self) -> Self {
57         panic!("NYI Neg::neg");
58     }
59 }
60
61 #[allow(unused)]
62 impl<F: Float> fmt::Display for DoubleFloat<F> {
63     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64         panic!("NYI Display::fmt");
65     }
66 }
67
68 #[allow(unused)]
69 impl<F: Float> Float for DoubleFloat<F> {
70     const BITS: usize = F::BITS * 2;
71     const PRECISION: usize = Fallback::<F>::PRECISION;
72     const MAX_EXP: ExpInt = Fallback::<F>::MAX_EXP;
73     const MIN_EXP: ExpInt = Fallback::<F>::MIN_EXP;
74
75     const ZERO: Self = DoubleFloat(F::ZERO, F::ZERO);
76
77     const INFINITY: Self = DoubleFloat(F::INFINITY, F::ZERO);
78
79     // FIXME(eddyb) remove when qnan becomes const fn.
80     const NAN: Self = DoubleFloat(F::NAN, F::ZERO);
81
82     fn qnan(payload: Option<u128>) -> Self {
83         panic!("NYI qnan")
84     }
85
86     fn snan(payload: Option<u128>) -> Self {
87         panic!("NYI snan")
88     }
89
90     fn largest() -> Self {
91         panic!("NYI largest")
92     }
93
94     const SMALLEST: Self = DoubleFloat(F::SMALLEST, F::ZERO);
95
96     fn smallest_normalized() -> Self {
97         panic!("NYI smallest_normalized")
98     }
99
100     fn add_r(self, rhs: Self, round: Round) -> StatusAnd<Self> {
101         panic!("NYI add_r")
102     }
103
104     fn mul_r(self, rhs: Self, round: Round) -> StatusAnd<Self> {
105         panic!("NYI mul_r")
106     }
107
108     fn mul_add_r(self, multiplicand: Self, addend: Self, round: Round) -> StatusAnd<Self> {
109         panic!("NYI mul_add_r")
110     }
111
112     fn div_r(self, rhs: Self, round: Round) -> StatusAnd<Self> {
113         panic!("NYI div_r")
114     }
115
116     fn c_fmod(self, rhs: Self) -> StatusAnd<Self> {
117         panic!("NYI c_fmod")
118     }
119
120     fn round_to_integral(self, round: Round) -> StatusAnd<Self> {
121         panic!("NYI round_to_integral")
122     }
123
124     fn next_up(self) -> StatusAnd<Self> {
125         panic!("NYI next_up")
126     }
127
128     fn from_bits(input: u128) -> Self {
129         panic!("NYI from_bits")
130     }
131
132     fn from_u128_r(input: u128, round: Round) -> StatusAnd<Self> {
133         panic!("NYI from_u128_r")
134     }
135
136     fn from_str_r(s: &str, round: Round) -> Result<StatusAnd<Self>, ParseError> {
137         panic!("NYI from_str_r")
138     }
139
140     fn to_bits(self) -> u128 {
141         panic!("NYI to_bits")
142     }
143
144     fn to_u128_r(self, width: usize, round: Round, is_exact: &mut bool) -> StatusAnd<u128> {
145         panic!("NYI to_u128_r");
146     }
147
148     fn cmp_abs_normal(self, rhs: Self) -> Ordering {
149         panic!("NYI cmp_abs_normal")
150     }
151
152     fn bitwise_eq(self, rhs: Self) -> bool {
153         panic!("NYI bitwise_eq")
154     }
155
156     fn is_negative(self) -> bool {
157         panic!("NYI is_negative")
158     }
159
160     fn is_denormal(self) -> bool {
161         panic!("NYI is_denormal")
162     }
163
164     fn is_signaling(self) -> bool {
165         panic!("NYI is_signaling")
166     }
167
168     fn category(self) -> Category {
169         panic!("NYI category")
170     }
171
172     fn get_exact_inverse(self) -> Option<Self> {
173         panic!("NYI get_exact_inverse")
174     }
175
176     fn ilogb(self) -> ExpInt {
177         panic!("NYI ilogb")
178     }
179
180     fn scalbn_r(self, exp: ExpInt, round: Round) -> Self {
181         panic!("NYI scalbn")
182     }
183
184     fn frexp_r(self, exp: &mut ExpInt, round: Round) -> Self {
185         panic!("NYI frexp")
186     }
187 }