Skip to content

Automatic arithmetic promotion#588

Merged
jeaye merged 13 commits into
jank-lang:mainfrom
shantanu-sardesai:issues/359-auto-promotion
Dec 18, 2025
Merged

Automatic arithmetic promotion#588
jeaye merged 13 commits into
jank-lang:mainfrom
shantanu-sardesai:issues/359-auto-promotion

Conversation

@shantanu-sardesai

@shantanu-sardesai shantanu-sardesai commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

Initial work at arithmetic promotion. The PR still requires tests but I'm creating this so that I can get some early feedback, especially on the overflow detection logic.

Requires a repoint.


Resolves #359, resolves #604.

@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch from 82e1d75 to 19d08bc Compare November 14, 2025 12:11
@shantanu-sardesai shantanu-sardesai marked this pull request as draft November 14, 2025 12:34
@shantanu-sardesai

Copy link
Copy Markdown
Contributor Author

I'll also aim to add missing Clojure test suite test cases for some of the arithmetic promotion operators.

@shantanu-sardesai

shantanu-sardesai commented Nov 14, 2025

Copy link
Copy Markdown
Contributor Author

Interestingly enough it looks like Clojure doesn't seem to support automatic arithmetic promotion from a java.lang.Double to java.math.BigDecimal, although I've yet to receive confirmation on whether that is really the case or not. Anyone with more information or interested in the topic can follow or chime in on the discussion here.

@shantanu-sardesai

Copy link
Copy Markdown
Contributor Author

Interestingly enough it looks like Clojure doesn't seem to support automatic arithmetic promotion from a java.lang.Double to java.math.BigDecimal, although I've yet to receive confirmation on whether that is really the case or not. Anyone with more information or interested in the topic can follow or chime in on the discussion here.

Seems like Clojure intentionally chooses to not promote to BigDecimal since the promotion is to account for scale and Decimal is large enough.

@shantanu-sardesai shantanu-sardesai marked this pull request as ready for review November 25, 2025 18:16

@jeaye jeaye left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. CI is failing, though.

@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch from f78df29 to 22fd3dd Compare December 1, 2025 14:24
@shantanu-sardesai

Copy link
Copy Markdown
Contributor Author

CI fails due to: jank-lang/clojure-test-suite#828 (comment).

@shantanu-sardesai

shantanu-sardesai commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

I've commented the Clojure test suite test cases for these operators, the CI passes now.

@shantanu-sardesai shantanu-sardesai force-pushed the issues/359-auto-promotion branch from 22fd3dd to 9a39ef7 Compare December 2, 2025 15:07
@jeaye jeaye merged commit 443365a into jank-lang:main Dec 18, 2025
15 checks passed
@jeaye

jeaye commented Dec 18, 2025

Copy link
Copy Markdown
Member

Nice work!

@shantanu-sardesai shantanu-sardesai deleted the issues/359-auto-promotion branch December 19, 2025 02:41
E-A-Griffin pushed a commit to E-A-Griffin/jank that referenced this pull request Jan 14, 2026
* Port `inc'`

* Port `dec'`

* Port `+'`

* Port `-'`

* Port `*'`

* Move `inc'` & `dec'` to LLVM overflow checks

* Add missing cases

* Remove promotion support for `jank::runtime::real` values

After discussing with the Clojure core team we found out that Clojure
intentionally chooses not to support automatic promotion for `real`
values to `big_decimal`.

- Clojure Q/A:
https://ask.clojure.org/index.php/14752/support-for-automatic-promotion-to-bigdecimal-in-etc.
- Slack thread:
https://clojurians.slack.com/archives/C053AK3F9/p1762684740564009.

* Port `num`

Resolves jank-lang#604.

* Enable `+'` tests

* Enable `*'` tests

* Disable blocked tests

* Enable the `ratio_qmark` tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numeric operators misbehave when in unary position Add support for promoting arithmetic

2 participants