From 8d527e88168885ab754a039219d0ae682fa4508b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 21 Mar 2019 21:27:36 +0100 Subject: Follow the spec for handling Doubles --- dhall_core/src/core.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'dhall_core/src/core.rs') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 52fc0cf..9f26b65 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -3,15 +3,39 @@ use crate::*; use std::collections::BTreeMap; use std::rc::Rc; -pub type Double = f64; pub type Int = isize; pub type Integer = isize; pub type Natural = usize; +pub type Double = NaiveDouble; /// An empty type #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum X {} +/// Double with bitwise equality +#[derive(Debug, Copy, Clone)] +pub struct NaiveDouble(f64); + +impl PartialEq for NaiveDouble { + fn eq(&self, other: &Self) -> bool { + return self.0.to_bits() == other.0.to_bits(); + } +} + +impl Eq for NaiveDouble {} + +impl From for NaiveDouble { + fn from(x: f64) -> Self { + NaiveDouble(x) + } +} + +impl From for f64 { + fn from(x: NaiveDouble) -> f64 { + x.0 + } +} + /// Constants for a pure type system /// /// The only axiom is: @@ -147,7 +171,7 @@ pub type DhallExpr = ResolvedExpr; pub type SubExpr = Rc>; /// Syntax tree for expressions -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Expr { /// `Const c ~ c` Const(Const), -- cgit v1.2.3