Skip to content

Commit

Permalink
Clarify naming of consts.NUM_CONSTS
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jul 10, 2021
1 parent e331d48 commit 29ca099
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions equator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def printOutput(out):
# No arguments, enter interpreter mode
if len(sys.argv) == 1:
print(f"{consts.NAME} (v{consts.VERSION})")
print(f"by {consts.AUTHOR}")
print("Interpreter Mode")
print("Press Ctrl+C to quit")
try:
Expand Down
6 changes: 4 additions & 2 deletions lib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

NAME = "Equator"
VERSION = "0.5.0"
AUTHOR = "Miguel Guthridge"

# Get 15 decimal places of precision - the max given by sympy
MAX_PRECISION = 14
FRACTION_DENOM_LIMITER = 1_000_000_000

# The minimum of abs(log_10(d)) for exponent to be presented using
# exponent notation
# exponent notation by default
MIN_EXP_LOG = 9

# Operators used to split string
Expand All @@ -27,7 +28,8 @@

NEGATE = "neg"

CONSTANTS = {
# Numeric constants
NUM_CONSTANTS = {
"pi": decimal.Decimal(math.pi),
"e": decimal.Decimal(math.e),
"oo": decimal.Decimal("inf"),
Expand Down
8 changes: 4 additions & 4 deletions lib/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def doFunction(func: str, a):
elif func == "abs":
return sym.Abs(a)
elif func == "deg":
return a * 180 / consts.CONSTANTS["pi"]
return a * 180 / consts.NUM_CONSTANTS["pi"]
elif func == "rad":
return a / 180 * consts.CONSTANTS["pi"]
return a / 180 * consts.NUM_CONSTANTS["pi"]
elif func == consts.NEGATE:
return -a
elif func == "exp":
Expand All @@ -150,8 +150,8 @@ def getConstant(const: str):
Returns:
str: representation of constant if applicable otherwise original str
"""
if const in consts.CONSTANTS:
return str(consts.CONSTANTS[const])
if const in consts.NUM_CONSTANTS:
return str(consts.NUM_CONSTANTS[const])
else:
return const

Expand Down
2 changes: 1 addition & 1 deletion lib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parseToken(word: str, unwrap_symbols=True):
return tokens.Operator(word)
else:
# Parse symbols and constants
if word in consts.CONSTANTS:
if word in consts.NUM_CONSTANTS:
return tokens.Constant(word)
else:
return tokens.Symbol(word)
Expand Down
6 changes: 3 additions & 3 deletions lib/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def asMultipleOf(a: Decimal, b: str):
str | None: a in terms of b or a normally (but None if doing so is unreasonable)
"""
# FIXME: present as pi/3 rather than 1/3*pi
ret = str(Fraction(a / consts.CONSTANTS[b]).limit_denominator(consts.FRACTION_DENOM_LIMITER))
ret = str(Fraction(a / consts.NUM_CONSTANTS[b]).limit_denominator(consts.FRACTION_DENOM_LIMITER))
if ret == "0":
return None
if len(ret) < 10:
Expand All @@ -69,7 +69,7 @@ def asPowerOf(a: Decimal, b: str):
Returns:
str | None: a as a power of b or a normally (but None if doing so is unreasonable)
"""
ret = str(Fraction(math.log(a, consts.CONSTANTS[b])).limit_denominator(consts.FRACTION_DENOM_LIMITER))
ret = str(Fraction(math.log(a, consts.NUM_CONSTANTS[b])).limit_denominator(consts.FRACTION_DENOM_LIMITER))
# Add brackets if it's a fraction
if "/" in ret:
ret = f"({ret})"
Expand Down Expand Up @@ -180,7 +180,7 @@ class Constant(Number):
Stringifies to the name of the constant
"""
def evaluate(self):
return consts.CONSTANTS[self._contents]
return consts.NUM_CONSTANTS[self._contents]

def __str__(self) -> str:
return self._contents
Expand Down

0 comments on commit 29ca099

Please sign in to comment.