Skip to content

Commit

Permalink
reorganize fn order; fix init import
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Mar 5, 2024
1 parent 6966a2d commit fe291b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion fixedpointmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

from .fixed_point import FixedPoint
from .fixed_point_integer_math import FixedPointIntegerMath
from .fixed_point_math import *
from .fixed_point_math import clip, exp, isclose, maximum, minimum, sqrt
66 changes: 33 additions & 33 deletions fixedpointmath/fixed_point_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,6 @@
# pylint: disable=invalid-name


def maximum(x: NUMERIC, y: NUMERIC) -> NUMERIC:
"""Compare the two inputs and return the greater value.
If the first argument equals the second, return the first.
"""
if isinstance(x, FixedPoint) and x.is_nan():
return x
if isinstance(y, FixedPoint) and y.is_nan():
return y
if x >= y:
return x
return y


def minimum(x: NUMERIC, y: NUMERIC) -> NUMERIC:
"""Compare the two inputs and return the lesser value.
If the first argument equals the second, return the first.
"""
if isinstance(x, FixedPoint) and x.is_nan():
return x
if isinstance(y, FixedPoint) and y.is_nan():
return y
if x <= y:
return x
return y


def clip(x: NUMERIC, low: NUMERIC, high: NUMERIC) -> NUMERIC:
"""Clip the input, x, to be within (min, max), inclusive"""
if low > high:
Expand All @@ -58,11 +30,6 @@ def exp(x: NUMERIC) -> NUMERIC:
return type(x)(math.exp(x))


def sqrt(x: NUMERIC) -> NUMERIC:
"""Performs sqrt(x)"""
return type(x)(math.sqrt(x))


def isclose(a: NUMERIC, b: NUMERIC, abs_tol: NUMERIC = FixedPoint("0.0")) -> bool:
"""Checks `abs(a-b) <= abs_tol`.
Ignores relative tolerance since FixedPoint should be accurate regardless of scale.
Expand Down Expand Up @@ -97,3 +64,36 @@ def isclose(a: NUMERIC, b: NUMERIC, abs_tol: NUMERIC = FixedPoint("0.0")) -> boo
):
raise ValueError("Input abs_tol must be finite.")
return abs(a - b) <= abs_tol


def maximum(x: NUMERIC, y: NUMERIC) -> NUMERIC:
"""Compare the two inputs and return the greater value.
If the first argument equals the second, return the first.
"""
if isinstance(x, FixedPoint) and x.is_nan():
return x
if isinstance(y, FixedPoint) and y.is_nan():
return y
if x >= y:
return x
return y


def minimum(x: NUMERIC, y: NUMERIC) -> NUMERIC:
"""Compare the two inputs and return the lesser value.
If the first argument equals the second, return the first.
"""
if isinstance(x, FixedPoint) and x.is_nan():
return x
if isinstance(y, FixedPoint) and y.is_nan():
return y
if x <= y:
return x
return y


def sqrt(x: NUMERIC) -> NUMERIC:
"""Performs sqrt(x)"""
return type(x)(math.sqrt(x))

0 comments on commit fe291b0

Please sign in to comment.