Skip to content

Commit 3d11cdb

Browse files
committed
Fix radical strings
1 parent 2bb8243 commit 3d11cdb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

tests/tivars.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ def test_exact_matrix(self):
435435
self.assertEqual(test_matrix.matrix(), test_array)
436436
self.assertEqual(list(iter(test_matrix)), [entry for row in test_array for entry in row])
437437

438+
self.assertEqual(str(test_matrix), string := "[[3π, 3√10], [1/2, (4√5+2√3)/7]]")
439+
self.assertEqual(f"{test_matrix:t}", "[[3π,3sqrt(10)][1n/d2,(4sqrt(5)+2sqrt(3))n/d7]]")
440+
441+
test_matrix.clear()
442+
test_matrix.load_string(string)
443+
self.assertEqual(test_matrix.matrix(), test_array)
444+
438445

439446
class SettingsTests(unittest.TestCase):
440447
def test_window(self):

tivars/types/real.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __format__(self, format_spec: str) -> str:
7474
case _:
7575
if format_spec.endswith("t"):
7676
spec = "" if format_spec == "t" else format_spec[:-1] + "f"
77-
return squash(re.sub(r"(√\d*)", r"sqrt(\1)", replacer(format(self, spec), {"-": "~", "/": "n/d"})))
77+
return squash(re.sub(r"√(\d*)", r"sqrt(\1)", replacer(format(self, spec), {"-": "~", "/": "n/d"})))
7878

7979
try:
8080
return format(self.decimal(), format_spec)

0 commit comments

Comments
 (0)