Commit 6d4d8686 authored by ZettaScript's avatar ZettaScript

Impls for Float

parent 18069991
......@@ -2,11 +2,13 @@ extern crate maths_traits;
extern crate num_traits;
extern crate rug;
use maths_traits::algebra;
use maths_traits::{algebra,analysis};
use maths_traits::algebra::additive::*;
use maths_traits::algebra::multiplicative::*;
use maths_traits::analysis::{Sign,Signed};
use std::fmt::{Display,Formatter,Result as FmtResult};
use std::{mem,ops};
//use std::ops::{Rem,RemAssign};
const FLOAT_DEFAULT_PREC:u32 = 53;
......@@ -78,7 +80,7 @@ impl num_traits::cast::FromPrimitive for Float {
fn from_f64(n: f64) -> Option<Self> { Some(Float::from(n)) }
}
macro_rules! float_impl {
macro_rules! float_impl_arith {
(
$Imp:ident { $method:ident },
$ImpAssign:ident { $method_assign:ident }
......@@ -165,10 +167,16 @@ impl AddCommutative for Float {}
impl MulAssociative for Float {}
impl MulCommutative for Float {}
float_impl!{ Add { add }, AddAssign {add_assign} }
float_impl!{ Sub { sub }, SubAssign {sub_assign} }
float_impl!{ Mul { mul }, MulAssign {mul_assign} }
float_impl!{ Div { div }, DivAssign {div_assign} }
impl analysis::ordered::AddOrdered for Float {}
impl analysis::ordered::MulOrdered for Float {}
impl analysis::ordered::ArchimedeanProperty for Float {}
float_impl_arith!{ Add { add }, AddAssign {add_assign} }
float_impl_arith!{ Sub { sub }, SubAssign {sub_assign} }
float_impl_arith!{ Mul { mul }, MulAssign {mul_assign} }
float_impl_arith!{ Div { div }, DivAssign {div_assign} }
//float_impl_arith!{ Rem { rem }, RemAssign {rem_assign} }
impl algebra::group_like::additive::Neg for Float
{
......@@ -222,7 +230,7 @@ impl algebra::ring_like::Distributive for Float {}
impl algebra::ring_like::Divisibility for Float {
fn divides(self, _rhs: Self) -> bool {
true//TODO
true//(rhs % self).is_zero()
}
fn divide(self, rhs: Self) -> Option<Self> {
......@@ -244,6 +252,21 @@ impl algebra::ring_like::Divisibility for Float {
}
}
impl analysis::ordered::Sign for Float {
fn signum(self) -> Self {
if self.positive() {Self::one()}
else if self.positive() {-Self::one()}
else {Self::zero()}
}
fn abs(self) -> Self {
if self.non_negative() {self}
else {-self}
}
}
impl algebra::ring_like::NoZeroDivisors for Float {}
#[cfg(test)]
mod tests {
use super::*;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment