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:
Christopher Haster
2024-11-13 15:21:04 -06:00
parent 5dc9eabbf7
commit 2fa968dd3f
8 changed files with 47 additions and 2 deletions

View File

@@ -120,6 +120,11 @@ class RInt(co.namedtuple('RInt', 'x')):
return self.__class__(self.x * other.x)
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)
def __mod__(self, other):