rune/core/object/
float.rsuse super::{CloneIn, IntoObject};
use crate::core::gc::{Block, GcHeap, GcState, Trace};
use crate::NewtypeMarkable;
use macro_attr_2018::macro_attr;
use newtype_derive_2018::*;
use rune_macros::Trace;
use std::fmt::{Debug, Display};
macro_attr! {
#[derive(PartialEq, NewtypeDeref!, NewtypeMarkable!, Trace)]
pub(crate) struct LispFloat(GcHeap<f64>);
}
impl LispFloat {
pub fn new(float: f64, constant: bool) -> Self {
LispFloat(GcHeap::new(float, constant))
}
}
impl Trace for f64 {
fn trace(&self, _: &mut GcState) {}
}
impl Eq for LispFloat {}
impl<'new> CloneIn<'new, &'new LispFloat> for LispFloat {
fn clone_in<const C: bool>(&self, bk: &'new Block<C>) -> super::Gc<&'new Self> {
(**self).into_obj(bk)
}
}
impl Display for LispFloat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let float = **self;
if float.fract() == 0.0_f64 {
write!(f, "{float:.1}")
} else {
write!(f, "{float}")
}
}
}
impl Debug for LispFloat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{self}")
}
}