Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix a bug where tags in data readers were resolved as Vars within syntax quotes, rather than using standard data readers rules (#1129)
* Fix a bug where `keyword` and `symbol` functions did not treat string arguments as potentially namespaced (#1131)
* Fix a bug where `condp` would throw an exception if a result expression was `nil` (#1137)
* Fix a bug where integer division which resulted in an integer would return a `fractions.Fraction` (#1140)

## [v0.3.2]
### Added
Expand Down
4 changes: 3 additions & 1 deletion src/basilisp/lang/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,9 @@ def divide(x: LispNumber, y: LispNumber) -> LispNumber:
@divide.register(int)
def _divide_ints(x: int, y: LispNumber) -> LispNumber:
if isinstance(y, int):
return Fraction(x, y)
frac = Fraction(x, y)
# fractions.Fraction.is_integer() wasn't added until 3.12
return frac.numerator if frac.denominator == 1 else frac
return x / y


Expand Down
18 changes: 18 additions & 0 deletions tests/basilisp/runtime_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fractions
import platform
import sys
from decimal import Decimal
Expand Down Expand Up @@ -599,6 +600,23 @@ def test_not_equals(v1, v2):
assert not runtime.equals(v2, v1)


@pytest.mark.parametrize(
"v1,v2,expected_result,result_type",
[
(3, 3, 1, int),
(3, 1, 3, int),
(3, 1.001, 3 / 1.001, float),
(3000, 1000, 3, int),
(3000, 1001, fractions.Fraction(3000, 1001), fractions.Fraction),
(3001, 1000, fractions.Fraction(3001, 1000), fractions.Fraction),
],
)
def test_divide(v1, v2, expected_result, result_type):
result = runtime.divide(v1, v2)
assert result == expected_result
assert isinstance(result, result_type)


def test_pop_thread_bindings():
with pytest.raises(runtime.RuntimeException):
runtime.pop_thread_bindings()
Expand Down