use std::cmp::Ordering;
use rug::Integer;
use crate::fixed::FixedContext;
use crate::{rfloat::RFloat, Real};
#[derive(Clone, Debug, Default)]
pub struct Exceptions {
pub invalid: bool,
pub overflow: bool,
pub underflow: bool,
pub inexact: bool,
}
#[derive(Clone, Debug)]
pub struct Fixed {
pub(crate) num: RFloat,
pub(crate) flags: Exceptions,
pub(crate) ctx: FixedContext,
}
impl Fixed {
pub fn flags(&self) -> &Exceptions {
&self.flags
}
pub fn ctx(&self) -> &FixedContext {
&self.ctx
}
}
impl Real for Fixed {
fn radix() -> usize {
2
}
fn sign(&self) -> Option<bool> {
self.num.sign()
}
fn exp(&self) -> Option<isize> {
self.num.exp()
}
fn e(&self) -> Option<isize> {
self.num.e()
}
fn n(&self) -> Option<isize> {
self.num.n()
}
fn c(&self) -> Option<Integer> {
self.num.c()
}
fn m(&self) -> Option<Integer> {
self.num.m()
}
fn prec(&self) -> Option<usize> {
self.num.prec()
}
fn is_nar(&self) -> bool {
false
}
fn is_finite(&self) -> bool {
true
}
fn is_infinite(&self) -> bool {
false
}
fn is_zero(&self) -> bool {
self.num.is_zero()
}
fn is_negative(&self) -> Option<bool> {
self.num.is_negative()
}
fn is_numerical(&self) -> bool {
true
}
}
impl From<Fixed> for RFloat {
fn from(val: Fixed) -> Self {
val.num
}
}
impl PartialEq for Fixed {
fn eq(&self, other: &Self) -> bool {
self.num == other.num
}
}
impl PartialOrd for Fixed {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.num.partial_cmp(&other.num)
}
}