From a615055dd6d6a0bd59aa7ba03305388f786306cb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 1 Jul 2013 16:00:59 -0400 Subject: [PATCH] Add the unit_roundoff function. --- src/Misc.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Misc.hs b/src/Misc.hs index 24fd5b7..ddaad6e 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -1,4 +1,5 @@ {-# LANGUAGE RebindableSyntax #-} +{-# LANGUAGE ScopedTypeVariables #-} -- | Stuff for which I'm too lazy to come up with a decent name. module Misc @@ -6,6 +7,7 @@ where import NumericPrelude import Algebra.Field +import Algebra.RealRing import Algebra.ToInteger -- | Partition the interval [@a@, @b@] into @n@ subintervals, which we @@ -35,3 +37,13 @@ partition n a b let xj = a + (k'+1)*h ] where h = (b-a)/(fromIntegral $ toInteger n) + + +-- | Compute the unit roundoff (machine epsilon) for this machine. We +-- find the largest number epsilon such that 1+epsilon <= 1. If you +-- request anything other than a Float or Double from this, expect +-- to wait a while. +-- +unit_roundoff :: forall a. (Algebra.RealRing.C a, Algebra.Field.C a) => a +unit_roundoff = + head [ 1/2^(k-1) | k <- [0..], 1 + 1/(2^k) <= (1::a) ] -- 2.43.2