forked from Imagelibrary/littlefs
scripts: csv.py: Fixed divide-by-zero, return +-inf
This may make some mathematician mad, but these are informative scripts. Returning +-inf is much more useful than erroring when dealing with several hundred rows of results. And hey, if it's good enough for IEEE 754, it's good enough for us :) Also fixed a division operator mismatch in RFrac that was causing problems.
This commit is contained in:
@@ -120,6 +120,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
@@ -121,6 +121,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
@@ -193,7 +198,7 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
|
|||||||
return self.__class__(self.a * other.a, self.b * other.b)
|
return self.__class__(self.a * other.a, self.b * other.b)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
return self.__class__(self.a // other.a, self.b // other.b)
|
return self.__class__(self.a / other.a, self.b / other.b)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
return self.__class__(self.a % other.a, self.b % other.b)
|
return self.__class__(self.a % other.a, self.b % other.b)
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
@@ -207,6 +212,11 @@ class RFloat(co.namedtuple('RFloat', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x / other.x)
|
return self.__class__(self.x / other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
@@ -279,7 +289,7 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
|
|||||||
return self.__class__(self.a * other.a, self.b * other.b)
|
return self.__class__(self.a * other.a, self.b * other.b)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
return self.__class__(self.a // other.a, self.b // other.b)
|
return self.__class__(self.a / other.a, self.b / other.b)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
return self.__class__(self.a % other.a, self.b % other.b)
|
return self.__class__(self.a % other.a, self.b % other.b)
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
@@ -115,6 +115,11 @@ class RInt(co.namedtuple('RInt', 'x')):
|
|||||||
return self.__class__(self.x * other.x)
|
return self.__class__(self.x * other.x)
|
||||||
|
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
|
if not other:
|
||||||
|
if self >= self.__class__(0):
|
||||||
|
return self.__class__(+mt.inf)
|
||||||
|
else:
|
||||||
|
return self.__class__(-mt.inf)
|
||||||
return self.__class__(self.x // other.x)
|
return self.__class__(self.x // other.x)
|
||||||
|
|
||||||
def __mod__(self, other):
|
def __mod__(self, other):
|
||||||
|
|||||||
Reference in New Issue
Block a user