Skip to content
/ Kinda Public

reinventing the wheel on floating number comparison

License

Notifications You must be signed in to change notification settings

schmamps/Kinda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kinda

About

Kinda is a pythonic library for comparing floating point values with Python operator functions.

Installation

Kinda is available as a package.

pip install kinda

Comparison

Equality

>>> import kinda
>>> # a == b
>>> kinda.eq(1.0000, 1.0000)
True
>>> # a != b
>>> kinda.eq(0.9999, 1.0001)
False

Tolerances

All functions take the same arguments and defaults of math.isclose() and make use the native function when available.

The keyword arguments listed below are for reference. Refer to the math module documentation for more detailed information.

  • abs_tol: absolute difference (bigger - smaller))
  • rel_tol: difference coefficient (bigger * rel_tol)
>>> import kinda
>>> # reduce absolute precision
>>> kinda.eq(0.9999, 1.0001, abs_tol=0.0002)
True
>>> # reduce relative precision to 5%
>>> kinda.eq(1.0000, 1.0500, rel_tol=0.05)
True
>>> # reduce relative precision to 1%
>>> kinda.eq(1.0000, 1.0500, rel_tol=0.01)
False

Inequality

>>> import kinda
>>> [kinda.ne(0.9999, 1.0001), kinda.ne(1.0000, 1.0000)]
[True, False]

Less/Greater Than

>>> import kinda
>>> # [a < b, a > b]
>>> [kinda.lt(1.0000, 1.0001), kinda.gt(1.0001, 1.0000)]
[True, True]

Less/Greater Than or Equal To

>>> import kinda
>>> kinda.le(1.0000, 1.0001) and kinda.ge(1.0000, 1.0001)
[True, False]
>>> kinda.le(1.0000, 1.0000) and kinda.ge(1.0000, 1.0000)
[True, True]
>>> kinda.le(1.0000, 0.9999) and kinda.ge(1.0000, 0.9999)
[False, True]

About

reinventing the wheel on floating number comparison

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages