fix over.core.m.compare_float
This commit is contained in:
parent
8d700f5ff1
commit
5dfd55673c
1 changed files with 4 additions and 11 deletions
15
core/m.py
15
core/m.py
|
@ -1,34 +1,27 @@
|
|||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import sys
|
||||
|
||||
class compare_float:
|
||||
"""
|
||||
Sets .lt, .eq or .gt iff A is less than, equal (within epsilon) or greather than B.
|
||||
Sets .lt, .eq or .gt iff A is less than, equal or greather than B.
|
||||
"""
|
||||
|
||||
def __init__(self, A, B, epsilon=sys.float_info.epsilon):
|
||||
def __init__(self, A, B, epsilon=1e-12):
|
||||
self.lt = False
|
||||
self.le = True
|
||||
self.eq = False
|
||||
self.ge = True
|
||||
self.gt = False
|
||||
|
||||
if A < B:
|
||||
if A < (B - epsilon):
|
||||
self.lt = True
|
||||
self.le = True
|
||||
self.ge = False
|
||||
elif A > B:
|
||||
elif A > (B + epsilon):
|
||||
self.gt = True
|
||||
self.le = False
|
||||
self.ge = True
|
||||
|
||||
if abs(A - B) < epsilon:
|
||||
self.eq = True
|
||||
else:
|
||||
self.le = False
|
||||
self.ge = False
|
||||
|
||||
# convenience
|
||||
self.less = self.lt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue