Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More polishing in preparation for release.

  • Loading branch information...
commit 310cabf2335b7d4e698c86eafcbc65327e00c333 1 parent e02f58f
authored August 02, 2010
10  Data/Eq/.leo_shadow/xApproximate.hs
@@ -27,7 +27,7 @@ Two kinds of wrappers are provided by this package.
27 27
 
28 28
 * 'RelativelyApproximateValue' wraps values that are considered to be equal if the absolute difference between the values divided by the average of the absolute values is within the given relative tolerance, /or/ if the absolute value of both values falls within the zero tolerance;  the latter case is checked because otherwise no value, no matter how small, would be approximately equal to zero.
29 29
 
30  
-The tolerance is specified through a type annotation.  One can use any anotation that one wishes as long as the type is an instance of 'AbsoluteTolerance' (for absolute tolerances) and/or 'RelativeTolerance' and 'ZeroTolerance' (for relative tolerances).  For convenience, this package provides the type 'Digits' that allows one to specify the tolerance in terms of the number of digits, making use of type-level natural numbers.  The annotation @Digits n@ sets the tolerance to @10^-n@, so that in the case of the absolute tolerance and the zero tolerance @n@ is the number of decimal places that numbers have to match to be equal to respectively either each other or to zero, and in the case of relative tolerance @n@ is (roughly) the number of leading digits that two numbers have to match in order to be equal to each other.
  30
+The tolerance is specified through a type annotation.  One can use any annotation that one wishes as long as the type is an instance of 'AbsoluteTolerance' (for absolute tolerances) and/or 'RelativeTolerance' and 'ZeroTolerance' (for relative tolerances).  For convenience, this package provides the type 'Digits' that allows one to specify the tolerance in terms of the number of digits, making use of type-level natural numbers.  The annotation @Digits n@ sets the tolerance to @10^-n@, so that in the case of the absolute tolerance and the zero tolerance @n@ is the number of decimal places that numbers have to match to be equal to respectively either each other or to zero, and in the case of relative tolerance @n@ is (roughly) the number of leading digits that two numbers have to match in order to be equal to each other.
31 31
 -- @-node:gcross.20100802173247.1349:<< Module description >>
32 32
 -- @nl
33 33
 -}
@@ -68,7 +68,7 @@ import TypeLevel.NaturalNumber
68 68
 -- @+node:gcross.20100730133924.1263:Types
69 69
 -- @+node:gcross.20100730133924.1264:AbsolutelyApproximateValue
70 70
 {-|
71  
-The newtype 'AbsolutelyApproximateValue' is a wrapper that can contain an arbitrary value tagged with a tolerance; two values are equal to each other if the absolute difference is less than or equal to this tolerance.  The type annotation @absolute_tolerance@, which must be an instance of 'AbsoluteTolerance', specifies the tolerance.  For convenience, one may specify the tolerence using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifes a tolerance of 0.0001).
  71
+The newtype 'AbsolutelyApproximateValue' is a wrapper that can contain an arbitrary value tagged with a tolerance; two values are equal to each other if the absolute difference is less than or equal to this tolerance.  The type annotation @absolute_tolerance@, which must be an instance of 'AbsoluteTolerance', specifies the tolerance.  For convenience, one may specify the tolerance using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifies a tolerance of 0.0001).
72 72
 
73 73
 It is recommended that one use this wrapper by creating aliases, such as
74 74
 
@@ -87,9 +87,9 @@ newtype AbsolutelyApproximateValue absolute_tolerance value =
87 87
 {-|
88 88
 The newtype 'RelativelyApproximateValue' is a wrapper that can contain an arbitrary value tagged with a zero tolerance and a relative tolerance;  two values are equal to each other if their absolute values are both less than or equal to the zero tolerance, or if the absolute difference between them divided by the average of the absolute values is less than or equal to the relative tolerance.
89 89
 
90  
-The type annotation @zero_tolerance@, which must be an instance of 'ZeroTolerance', specifies the tolerance within which a value is considered to be equal to zero.  For convenience, one may specify the tolerence using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifes a tolerance of 0.0001).
  90
+The type annotation @zero_tolerance@, which must be an instance of 'ZeroTolerance', specifies the tolerance within which a value is considered to be equal to zero.  For convenience, one may specify the tolerance using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifies a tolerance of 0.0001).
91 91
 
92  
-The type annotation @relative_tolerance@, which must be an instance of 'RelativeTolerance', specifies the relative tolerance within which two values that are not approximately equal to zero are considered to be equal to each other.  For convenience, as with the zero tolerance, one may specify the relative tolerence using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifes a relative tolerance of 0.0001, so that two values are equal if they agree to the first four leading digits).
  92
+The type annotation @relative_tolerance@, which must be an instance of 'RelativeTolerance', specifies the relative tolerance within which two values that are not approximately equal to zero are considered to be equal to each other.  For convenience, as with the zero tolerance, one may specify the relative tolerance using the type @Digits n@ where @n@ is a type-level natural specifying the number of decimals in the tolerance (i.e., @Digits Four@ specifies a relative tolerance of 0.0001, so that two values are equal if they agree to the first four leading digits).
93 93
 
94 94
 It is recommended that one use this wrapper by creating aliases, such as
95 95
 
@@ -106,7 +106,7 @@ newtype RelativelyApproximateValue zero_tolerance relative_tolerance value =
106 106
 -- @-node:gcross.20100802173247.1297:RelativelyApproximateValue
107 107
 -- @+node:gcross.20100730133924.1267:Digits
108 108
 {-|
109  
-Digits is a type constructor that can be used to specify tolerances using type-level natural numbers.  Annoting a wrapper with the type @Digits n@ specifies that the corresponding tolerance has a numerical value of @10^(-n)@.
  109
+Digits is a type constructor that can be used to specify tolerances using type-level natural numbers.  Annotating a wrapper with the type @Digits n@ specifies that the corresponding tolerance has a numerical value of @10^(-n)@.
110 110
 -}
111 111
 data Digits n
112 112
 -- @-node:gcross.20100730133924.1267:Digits
2  LICENSE
... ...
@@ -1,4 +1,4 @@
1  
-Copyright (c) 2008, Scott E. Dillard
  1
+Copyright (c) 2010, Gregory Crosswhite
2 2
 All rights reserved.
3 3
 
4 4
 Redistribution and use in source and binary forms, with or without modification,
1  approximate-equality.cabal
@@ -5,6 +5,7 @@ License-file:        LICENSE
5 5
 Author:              Gregory Crosswhite
6 6
 Maintainer:          Gregory Crosswhite <gcross@phys.washington.edu>
7 7
 Stability:           Provisional
  8
+Homepage:            http://github.com/gcross/approximate-equality
8 9
 Synopsis:            Newtype wrappers for approximate equality
9 10
 Description:         The purpose of this module is to provide newtype wrappers that allow one to effectively override the equality operator of a value so that it is /approximate/ rather than /exact/.  The wrappers use type annotations to specify the tolerance; the 'Digits' type constructor has been provided for specifying the tolerance using type-level natural numbers.  Instances for all of the classes in the numerical hierarchy have been provided for the wrappers, so the wrapped values can mostly be used in the same way as the original values. (In fact, most of the time one doesn't even have to wrap the starting values, since expressions such as @(1+sqrt 2/3)@ are automatically wrapped thanks to the 'fromIntegral' method of the 'Num' typeclass.) 
10 11
                      See the documentation for Data.Eq.Approximate for more detailed information on how to use this package.

0 notes on commit 310cabf

Please sign in to comment.
Something went wrong with that request. Please try again.