Skip to content

Commit 8313cec

Browse files
committed
Extend the Float trait by some constants and supertraits
1 parent 2c1d7dc commit 8313cec

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/float/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::mem;
2+
use core::ops;
23

34
use super::int::Int;
45

@@ -8,10 +9,23 @@ pub mod pow;
89
pub mod sub;
910

1011
/// Trait for some basic operations on floats
11-
pub trait Float: Sized + Copy {
12+
pub trait Float:
13+
Copy +
14+
PartialEq +
15+
PartialOrd +
16+
ops::AddAssign +
17+
ops::MulAssign +
18+
ops::Add<Output = Self> +
19+
ops::Sub<Output = Self> +
20+
ops::Div<Output = Self> +
21+
ops::Rem<Output = Self> +
22+
{
1223
/// A uint of the same with as the float
1324
type Int: Int;
1425

26+
const ZERO: Self;
27+
const ONE: Self;
28+
1529
/// The bitwidth of the float type
1630
const BITS: u32;
1731

@@ -64,6 +78,9 @@ macro_rules! float_impl {
6478
($ty:ident, $ity:ident, $bits:expr, $significand_bits:expr) => {
6579
impl Float for $ty {
6680
type Int = $ity;
81+
const ZERO: Self = 0.0;
82+
const ONE: Self = 1.0;
83+
6784
const BITS: u32 = $bits;
6885
const SIGNIFICAND_BITS: u32 = $significand_bits;
6986

0 commit comments

Comments
 (0)