Return to Snippet

Revision: 68592
at January 23, 2015 20:44 by kosenko


Initial Code
module Circa (
  circaEq,
  picoEq, nanoEq, microEq, milliEq, centiEq, deciEq, uniEq,
  (~=)
  ) where

circaEq :: (Fractional t, Ord t) => t -> t -> t -> Bool
circaEq t x y = abs (x - y) < t

picoEq :: (Fractional t, Ord t) => t -> t -> Bool
picoEq = circaEq 1e-12
infix 4 `picoEq`

nanoEq :: (Fractional t, Ord t) => t -> t -> Bool
nanoEq = circaEq 1e-9
infix 4 `nanoEq`

microEq :: (Fractional t, Ord t) => t -> t -> Bool
microEq = circaEq 1e-6
infix 4 `microEq`

milliEq :: (Fractional t, Ord t) => t -> t -> Bool
milliEq = circaEq 1e-3
infix 4 `milliEq`

centiEq :: (Fractional t, Ord t) => t -> t -> Bool
centiEq = circaEq 1e-2
infix 4 `centiEq`

deciEq :: (Fractional t, Ord t) => t -> t -> Bool
deciEq = circaEq 1e-1
infix 4 `deciEq`

uniEq :: (Fractional t, Ord t) => t -> t -> Bool
uniEq = circaEq 1
infix 4 `uniEq`

(~=) :: (Fractional t, Ord t) => t -> t -> Bool
(~=) = picoEq
infix 4 ~=

Initial URL

                                

Initial Description
This module provides a couple of functions and an operator to compare approximately fractional numbers.

Initial Title
Circa comparison of fractional numbers

Initial Tags

                                

Initial Language
Haskell