cgmath/num.rs
1// Copyright 2013-2014 The CGMath Developers. For a full listing of the authors,
2// refer to the Cargo.toml file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use approx;
17
18use std::fmt;
19use std::ops::*;
20
21use num_traits::{Float, Num, NumCast};
22
23/// Base numeric types with partial ordering
24pub trait BaseNum:
25 Copy
26 + Clone
27 + fmt::Debug
28 + Num
29 + NumCast
30 + PartialOrd
31 + AddAssign
32 + SubAssign
33 + MulAssign
34 + DivAssign
35 + RemAssign
36{
37}
38
39impl<T> BaseNum for T where
40 T: Copy
41 + Clone
42 + fmt::Debug
43 + Num
44 + NumCast
45 + PartialOrd
46 + AddAssign
47 + SubAssign
48 + MulAssign
49 + DivAssign
50 + RemAssign
51{
52}
53
54/// Base floating point types
55pub trait BaseFloat:
56 BaseNum
57 + Float
58 + approx::AbsDiffEq<Epsilon = Self>
59 + approx::RelativeEq<Epsilon = Self>
60 + approx::UlpsEq<Epsilon = Self>
61{
62}
63
64impl<T> BaseFloat for T where
65 T: BaseNum
66 + Float
67 + approx::AbsDiffEq<Epsilon = Self>
68 + approx::RelativeEq<Epsilon = Self>
69 + approx::UlpsEq<Epsilon = Self>
70{
71}