Skip to content

feat(stdlib): improve numeric parity across Int, Long, Float, and Double#1534

Merged
eriksvedang merged 4 commits intocarp-lang:masterfrom
sqrew:stdlib-numeric-parity
Apr 28, 2026
Merged

feat(stdlib): improve numeric parity across Int, Long, Float, and Double#1534
eriksvedang merged 4 commits intocarp-lang:masterfrom
sqrew:stdlib-numeric-parity

Conversation

@sqrew
Copy link
Copy Markdown
Contributor

@sqrew sqrew commented Apr 15, 2026

This PR improves consistency and completeness across the numeric modules in the Carp standard library.

Changes:

  • Interfaces: Added sign and pi interfaces to core.
  • Predicates: Added positive? and negative? to Int, Long, Float, and Double.
  • Long Module Parity: Added clamp, sign, zero, and add-ref to the Long module.
  • Implementations: Registered numeric types as implementations of the new sign and pi interfaces.
  • Documentation: Added docstrings for all new functions.
  • Tests: Integrated 35 new test cases into the existing numeric math test suites (test/int_math.carp, etc.).

Disclaimer: This PR was built with the assistance of Gemini (an AI assistant) working in collaboration with @sqrew to improve the Carp standard library consistency.

sqrew added 2 commits April 14, 2026 20:31
- Added positive? and negative? predicates to Int, Long, Float, Double
- Added clamp, sign, zero, and add-ref to Long
- Integrated tests into int_math.carp, long_math.carp, float_math.carp, and double_math.carp
- Added 'sign' and 'pi' interfaces to core
- Implemented 'positive?' and 'negative?' predicates for all numeric types
- Added 'clamp', 'sign', 'zero', and 'add-ref' to Long
- Registered numeric types as implementations of new interfaces
- Integrated 35 new test cases into existing math test suites
Comment thread core/Interfaces.carp Outdated

(definterface sign (Fn [a] a))

(definterface pi a)
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 pi interface already exists (look at line 42 in the same file).

Comment thread core/Double.carp Outdated
(implements tan Double.tan)
(implements tanh Double.tanh)
(implements sign Double.sign)
(implements pi Double.pi)
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.

Duplicate, already there.

Comment thread core/Float.carp Outdated
(implements tan Float.tan)
(implements tanh Float.tanh)
(implements sign Float.sign)
(implements pi Float.pi)
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.

Duplicate, already there.

Comment thread test/long_math.carp
(assert-equal test 10l (clamp 0l 10l 11l) "clamp works as expected III")
(assert-equal test 1l (sign 5l) "sign works as expected I")
(assert-equal test -1l (sign -5l) "sign works as expected II")
(assert-equal test 0l (sign 0l) "sign works as expected III")
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.

While we’re in there, can we add a Long.add-ref test?

- Remove duplicate 'pi' and 'copy' implementations in Float and Double
- Add test case for Long.add-ref in test/long_math.carp
Comment thread core/Interfaces.carp Outdated

(definterface sign (Fn [a] a))

(definterface pi a)
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.

Duplicate interface definition. Declared above in the same file.

- Removed duplicate pi interface definition in Interfaces.carp.
- Restored missing pi implementations in Double.carp and Float.carp.
- Verified Long.add-ref test and other parity features.
- All 190+ numeric tests passing.
@eriksvedang eriksvedang merged commit 28c7421 into carp-lang:master Apr 28, 2026
4 checks passed
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.

3 participants