Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 20, 2023
2 parents 140fd1d + b055d99 commit 5e7de94
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 47 deletions.
74 changes: 52 additions & 22 deletions eo-runtime/src/main/eo/org/eolang/negative-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,78 @@
^.eq x > @

# Multiplication of $ and x
[x] > times
[x...] > times
x.at 0 > first!
if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq 0.0
x.eq 0
first.as-bytes.eq (nan.as-bytes)
first.eq 0.0
first.eq 0
nan
if.
x.eq ^
first.eq ^
positive-infinity
^

# Sum of $ and x
[x] > plus
[x...] > plus
positive-infinity.as-bytes > pos-inf-as-bytes!

[acc index terms check-term] > plus-rec
if. > @
index.eq terms.length
acc
if.
check-term
terms.at index
nan
plus-rec
acc
index.plus 1
terms
check-term

[term] > check-term
term > t!
or. > @
not.
t.eq t
t.as-bytes.eq pos-inf-as-bytes

if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq positive-infinity
nan
eq.
x.length > terms-count!
0
^
if.
terms-count.gt 1
plus-rec
^
0
x
check-term
if.
check-term
x.at 0
nan
^

# Negation of $
[] > neg
positive-infinity > @

# Difference between $ and x
[x] > minus
^.plus (x.neg) > @

[x] > not-int
x.as-int > as-integer!
and. > @
as-integer.as-float.lt x
(as-integer.plus 1).as-float.gt x
[x...] > minus
^.plus ((x.at 0).neg) > @

# Quotient of the division of $ by x
[x] > div
[x...] > div
x.at 0 > first!
if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq ^
x.eq positive-infinity
first.as-bytes.eq (nan.as-bytes)
first.eq ^
first.eq positive-infinity
nan
^

Expand Down
80 changes: 61 additions & 19 deletions eo-runtime/src/main/eo/org/eolang/positive-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
+rt jvm org.eolang:eo-runtime:0.0.0
+version 0.0.0

# @todo #1799:30min. Make "+inf" and "-inf" looked like float. Refactor objects
# plus, minus, times, div in +inf and -inf so they are able to process multiple
# arguments
# Positive infinity
[] > positive-infinity
1.0.div 0.0 > @!
Expand Down Expand Up @@ -62,42 +59,87 @@
nan.as-bytes

# Multiplication of $ and x
[x] > times
# @todo #1806:30min. Make positive-infinity.times and negative-infinity.times
# worked with multiple arguments without using objects from eo-collections.
# See positive-infinity.plus and negative-infinity.plus as an example
[x...] > times
x.at 0 > first!
if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq 0.0
x.eq 0
first.as-bytes.eq (nan.as-bytes)
first.eq 0.0
first.eq 0
nan
if.
x.eq negative-infinity
first.eq negative-infinity
negative-infinity
^

# Sum of $ and x
[x] > plus
[x...] > plus
negative-infinity.as-bytes > neg-inf-as-bytes!

[acc index terms check-term] > plus-rec
if. > @
index.eq terms.length
acc
if.
check-term
terms.at index
nan
plus-rec
acc
index.plus 1
terms
check-term

[term] > check-term
term > t!
or. > @
not.
t.eq t
t.as-bytes.eq neg-inf-as-bytes

if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq negative-infinity
nan
eq.
x.length > terms-count!
0
^
if.
terms-count.gt 1
plus-rec
^
0
x
check-term
if.
check-term
x.at 0
nan
^

# Negation of $
[] > neg
negative-infinity > @

# Difference between $ and x
[x] > minus
^.plus (x.neg) > @
# @todo #1806:30min. Make positive-infinity.minus and negative-infinity.minus
# worked with multiple arguments without using objects from eo-collections.
# See positive-infinity.plus and negative-infinity.plus as an example
[x...] > minus
^.plus ((x.at 0).neg) > @

# Quotient of the division of $ by x
[x] > div
# @todo #1806:30min. Make positive-infinity.div and negative-infinity.div
# worked with multiple arguments without using objects from eo-collections.
# See positive-infinity.plus and negative-infinity.plus as an example
[x...] > div
x.at 0 > first!
if. > @
or.
x.as-bytes.eq (nan.as-bytes)
x.eq negative-infinity
x.eq ^
first.as-bytes.eq (nan.as-bytes)
first.eq negative-infinity
first.eq ^
nan
^

Expand Down
23 changes: 23 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/negative-infinity-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,29 @@
neg-inf.plus 42.5
$.equal-to neg-inf

[] > negative-infinity-plus-multiple-floats
negative-infinity > neg-inf!
assert-that > @
neg-inf.plus 42.5 22.2 51.5
$.equal-to neg-inf

[] > negative-infinity-plus-multiple-number
negative-infinity > neg-inf!
assert-that > @
neg-inf.plus 42.5 -22 11 -1.2
$.equal-to neg-inf

[] > negative-infinity-plus-multiple-numbers-with-nan
nan > not-a-number!
assert-that > @
(negative-infinity.plus 42 not-a-number 30).as-bytes
$.equal-to not-a-number.as-bytes

[] > negative-infinity-plus-multiple-numbers-with-positive-infinity
assert-that > @
(negative-infinity.plus 42 positive-infinity 30).as-bytes
$.equal-to nan.as-bytes

[] > negative-infinity-plus-positive-int
negative-infinity > neg-inf!
assert-that > @
Expand Down
23 changes: 17 additions & 6 deletions eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,35 @@
pos-inf.plus 42.5
$.equal-to pos-inf

[] > positive-infinity-plus-positive-int
[] > positive-infinity-plus-multiple-floats
positive-infinity > pos-inf!
assert-that > @
pos-inf.plus 42
pos-inf.plus 42.5 -22.5 12.2
$.equal-to pos-inf

[] > positive-infinity-plus-negative-float
[] > positive-infinity-plus-positive-int
positive-infinity > pos-inf!
assert-that > @
pos-inf.plus -42.5
pos-inf.plus 42
$.equal-to pos-inf

[] > positive-infinity-plus-negative-int
[] > positive-infinity-plus-multiple-numbers
positive-infinity > pos-inf!
assert-that > @
pos-inf.plus -42
pos-inf.plus 42 -22.1 30
$.equal-to pos-inf

[] > positive-infinity-plus-multiple-numbers-with-nan
nan > not-a-number!
assert-that > @
(positive-infinity.plus 42 not-a-number 30).as-bytes
$.equal-to not-a-number.as-bytes

[] > positive-infinity-plus-multiple-numbers-with-negative-infinity
assert-that > @
(positive-infinity.plus 42 negative-infinity 30).as-bytes
$.equal-to nan.as-bytes

# Negation
[] > positive-infinity-neg-is-negative-infinity
assert-that > @
Expand Down

4 comments on commit 5e7de94

@0pdd
Copy link

@0pdd 0pdd commented on 5e7de94 Feb 20, 2023

Choose a reason for hiding this comment

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

Puzzle 1799-32659a06 disappeared from eo-runtime/src/main/eo/org/eolang/positive-infinity.eo), that's why I closed #1806. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5e7de94 Feb 20, 2023

Choose a reason for hiding this comment

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

Puzzle 1806-8a1e1fbc discovered in eo-runtime/src/main/eo/org/eolang/positive-infinity.eo) and submitted as #1824. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5e7de94 Feb 20, 2023

Choose a reason for hiding this comment

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

Puzzle 1806-be69b5fb discovered in eo-runtime/src/main/eo/org/eolang/positive-infinity.eo) and submitted as #1825. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5e7de94 Feb 20, 2023

Choose a reason for hiding this comment

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

Puzzle 1806-865a59ed discovered in eo-runtime/src/main/eo/org/eolang/positive-infinity.eo) and submitted as #1826. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.