Skip to content
Open
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
28 changes: 24 additions & 4 deletions eo-runtime/src/main/eo/number.eo
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@
# The object rounds down the original `number` to the nearest
# whole `number` that is less than or equal to it
# and returns the result as `org.eolang.number`.
# For non-finite inputs (NaN, ±infinity) the input is returned unchanged.
[] > floor
as-i64.as-number > @
if. > @
is-finite.not
$
if.
trunc.gt $
trunc.minus 1
trunc
as-i64.as-number > trunc
Comment on lines +115 to +124
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1) Find any use of a bare `$` as a value inside method bodies in .eo files.
rg -nP --type-add 'eo:*.eo' --type=eo -C3 '^\s*\$\s*$|[^\w$]\$(\s|$)' eo-runtime/src/main/eo

# 2) Find uses of `^` (parent reference) to see the established idiom for
#    "refer to the enclosing object from inside a method body".
rg -nP --type-add 'eo:*.eo' --type=eo -C3 '(^|[^\w])\^(\.|\s|$)' eo-runtime/src/main/eo | head -n 200

# 3) Surface the exact test objects that rely on floor for non-finite inputs,
#    to confirm they actually invoke `.floor` (and are not shadowed by `.@`):
rg -nP --type-add 'eo:*.eo' --type=eo -C2 'floor' eo-runtime/src/main/eo/positive-infinity.eo eo-runtime/src/main/eo/negative-infinity.eo

Repository: objectionary/eo

Length of output: 23296


Verify that $ refers to the enclosing number, not to the floor method itself.

In EO, ^ is the established pattern for referencing the enclosing parent object in method bodies. The implementation at lines 119 and 121 uses bare $, which is not found elsewhere in the codebase in this style.

Two locations are affected:

  • Line 119 ($ as the non-finite branch result): if $ dataizes through floor.@, this creates a cycle.
  • Line 121 (trunc.gt $): comparing trunc against $ dataizes the floor method rather than the input number.

Tests for negative-infinity.floor and positive-infinity.floor exist (negative-infinity.eo:502–503, positive-infinity.eo:515–516), but they must be confirmed to exercise the floor method correctly. If $ is incorrect, replace it with ^ (or an explicit binding like as-bytes.as-number > original). Verify that nan.floor, positive-infinity.floor, and negative-infinity.floor evaluate correctly on both JVM and eo2js runtimes before merging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eo-runtime/src/main/eo/number.eo` around lines 115 - 124, The floor method is
incorrectly using bare `$` which refers to the method object dataization and can
create cycles; change those `$` references inside the floor body to reference
the enclosing number (use `^` or bind the input to a name like `original` before
transformations) so the non-finite branch returns the original numeric value and
the comparison `trunc.gt` compares against that original number; update
references in the floor implementation (symbols: floor, trunc, is-finite,
as-i64.as-number) and re-run nan.floor, positive-infinity.floor and
negative-infinity.floor tests on both JVM and eo2js to confirm correct behavior.


# Tests that less-than comparison returns true when first number is smaller.
[] +> tests-int-less-true
Expand Down Expand Up @@ -351,26 +359,38 @@
eq. > @
floor.
13.div -5
-2
-3

# Tests that floor of a positive fractional number truncates toward zero.
[] +> tests-floor-positive-fraction
eq. > @
3.7.floor
3

# Tests that floor of a negative fractional number truncates toward zero.
# Tests that floor of a negative fractional number rounds toward -infinity.
[] +> tests-floor-negative-fraction
eq. > @
-3.7.floor
-3
-4

# Tests that floor of a small negative fraction rounds toward -infinity, not zero.
[] +> tests-floor-small-negative-fraction
eq. > @
-0.1.floor
-1

# Tests that floor of a whole number returns the same number.
[] +> tests-floor-of-integer
eq. > @
42.floor
42

# Tests that floor of a negative whole number returns the same number.
[] +> tests-floor-of-negative-integer
eq. > @
-42.floor
-42

# Tests that division result can be less than one.
[] +> tests-div-less-than-one
lt. > @
Expand Down
Loading