Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(#4950): moved sqrt from real.eo to a separate object with tests#4959

Merged
yegor256 merged 2 commits into
objectionary:masterfrom
eshabakhov:#4950
Apr 1, 2026
Merged

feat(#4950): moved sqrt from real.eo to a separate object with tests#4959
yegor256 merged 2 commits into
objectionary:masterfrom
eshabakhov:#4950

Conversation

@eshabakhov
Copy link
Copy Markdown
Contributor

@eshabakhov eshabakhov commented Mar 27, 2026

Summary

This PR solves #4950

Changes

  • removed sqrt and tests from real.eo
  • added sqrt in sqrt.eo with tests
  • fixed EOreal$EOsqrt.java to EOsqrt.java

Summary by CodeRabbit

  • Refactor

    • Moved the square-root operation into a dedicated module and updated its invocation/parameter handling for clearer usage.
  • Tests

    • Added comprehensive sqrt test coverage: zero, integers, floats, fractional values, negative inputs, NaN, infinities, and numeric-accuracy checks.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f42b417-22a5-4aae-9698-88c281c351c3

📥 Commits

Reviewing files that changed from the base of the PR and between 46bf590 and ec89435.

📒 Files selected for processing (1)
  • eo-runtime/src/main/eo/ms/sqrt.eo
🚧 Files skipped from review as they are similar to previous changes (1)
  • eo-runtime/src/main/eo/ms/sqrt.eo

📝 Walkthrough

Walkthrough

The sqrt atom was extracted from ms/real into a new ms/sqrt EO module (with tests), and the Java runtime atom was added/renamed to EOsqrt with a named num input slot and updated lambda() behavior.

Changes

Cohort / File(s) Summary
Removal from real
eo-runtime/src/main/eo/ms/real.eo
Removed exported sqrt atom and deleted all sqrt-related tests.
New module & tests
eo-runtime/src/main/eo/ms/sqrt.eo
Added standalone sqrt EO module defining [num] > sqrt ? with comprehensive correctness and edge-case tests (zero, perfect squares, fractions, tolerance checks, NaN, infinities, negative inputs).
Java runtime atom
eo-runtime/src/main/java/org/eolang/EOms/EOsqrt.java
Added/renamed Java atom class EOsqrt (@XmirObject(oname="sqrt")), introduced public no-arg constructor exposing a "num" slot, and updated lambda() to read from "num", convert to number, apply Math.sqrt, and wrap result.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped from real to a brand new square,
Roots now live in their own little lair,
Tests lined up, precise and spry,
Java renamed with a cheerful sigh,
I nibble bugs and boundware beware.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving sqrt from real.eo to a separate object with tests, matching the file-level changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@eshabakhov eshabakhov changed the title #4950: move sqrt from real.eo to a separate object with tests feat(#4950): move sqrt from real.eo to a separate object with tests Mar 27, 2026
@eshabakhov eshabakhov changed the title feat(#4950): move sqrt from real.eo to a separate object with tests feat(#4950): moved sqrt from real.eo to a separate object with tests Mar 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 30, 2026

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 182.666 182.578 -0.088 -0.05% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 0.088 ms/op (0.05%)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
eo-runtime/src/main/eo/ms/sqrt.eo (1)

44-77: Extract epsilon into a single constant for tolerance checks.

0.00000000001 is duplicated in three tests. Centralizing it improves maintainability and avoids drift.

Proposed refactor
 [num] > sqrt ?
+  [] > epsilon
+    0.00000000001
+
   # Tests that square root of zero equals zero.
   [] +> tests-sqrt-check-zero-input
     lt. +> @
       abs
         real
           minus.
             0
             sqrt 0
-      0.00000000001
+      epsilon
@@
   [] +> tests-sqrt-check-float-input
     lt. +> @
       abs
         real
           minus.
             2
             sqrt 4
-      0.00000000001
+      epsilon
@@
   [] +> tests-sqrt-check-int-input
     lt. +> @
       abs
         real
           minus.
             9
             sqrt 81
-      0.00000000001
+      epsilon
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eo-runtime/src/main/eo/ms/sqrt.eo` around lines 44 - 77, Create a single
named constant for the tolerance (epsilon) and use it in all three tests instead
of the repeated literal; specifically add a top-level constant (e.g., epsilon)
and replace the numeric literal 0.00000000001 in tests-sqrt-check-zero-input,
tests-sqrt-check-float-input, and tests-sqrt-check-int-input with that constant
so the tolerance is centralized and easy to adjust.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@eo-runtime/src/main/eo/ms/sqrt.eo`:
- Around line 59-70: Update the test names and comments so they accurately
describe the inputs being tested: change the comment and test identifier
tests-sqrt-check-float-input to something like
tests-sqrt-check-exact-square-float (or tests-sqrt-check-exact-square) if it
verifies sqrt 4 == 2, and either rename tests-sqrt-check-int-input to
tests-sqrt-check-noninteger-input if you intend it to test a non-integer case
(e.g., sqrt 2 with a tolerance) or rename it to
tests-sqrt-check-exact-square-int if it also checks an exact-square integer;
update the surrounding comment text to match the chosen intent so test reports
are not misleading and the identifiers (tests-sqrt-check-float-input,
tests-sqrt-check-int-input) clearly reflect the actual assertions.

---

Nitpick comments:
In `@eo-runtime/src/main/eo/ms/sqrt.eo`:
- Around line 44-77: Create a single named constant for the tolerance (epsilon)
and use it in all three tests instead of the repeated literal; specifically add
a top-level constant (e.g., epsilon) and replace the numeric literal
0.00000000001 in tests-sqrt-check-zero-input, tests-sqrt-check-float-input, and
tests-sqrt-check-int-input with that constant so the tolerance is centralized
and easy to adjust.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 998a45d1-7266-4627-8acf-acbcdc1cc8f8

📥 Commits

Reviewing files that changed from the base of the PR and between 808f35b and 46bf590.

📒 Files selected for processing (3)
  • eo-runtime/src/main/eo/ms/real.eo
  • eo-runtime/src/main/eo/ms/sqrt.eo
  • eo-runtime/src/main/java/org/eolang/EOms/EOsqrt.java
💤 Files with no reviewable changes (1)
  • eo-runtime/src/main/eo/ms/real.eo
🚧 Files skipped from review as they are similar to previous changes (1)
  • eo-runtime/src/main/java/org/eolang/EOms/EOsqrt.java

Comment thread eo-runtime/src/main/eo/ms/sqrt.eo Outdated
@eshabakhov
Copy link
Copy Markdown
Contributor Author

@yegor256 check this please

@yegor256 yegor256 merged commit 4cb0d56 into objectionary:master Apr 1, 2026
25 checks passed
@0crat
Copy link
Copy Markdown

0crat commented Apr 1, 2026

@eshabakhov Thanks for the contribution! You've earned +12 points for this: +16 as a basis, +0.05 points per hit-of-code (168 hits = +8.4 points, capped at +16), and -4 for exceeding 100 hits-of-code. Please keep them coming! Your running score is +68; don't forget to check your Zerocracy account too.

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