From b1f5d91aafb2e96bd65fd9ab13a5b18f889fba92 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Fri, 17 Feb 2023 18:42:45 +0300 Subject: [PATCH 1/3] try --- .../main/eo/org/eolang/positive-infinity.eo | 177 +++++++++++++----- 1 file changed, 130 insertions(+), 47 deletions(-) diff --git a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo index cc755ae5df..86a130149d 100644 --- a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo +++ b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ++alias org.eolang.collections.list +architect yegor256@gmail.com +home https://github.com/objectionary/eo +package org.eolang @@ -30,16 +31,6 @@ [] > positive-infinity 1.0.div 0.0 > @! - # Tests that $ = x - [x] > eq - eq. > @ - ^.as-bytes - x.as-bytes - - # Tests that $ ≠ x - [x] > neq - (^.eq x).not > @ - # Tests that $ < x [x] > lt FALSE > @ @@ -63,57 +54,149 @@ nan.as-bytes # Multiplication of $ and x - [x] > times + [x...] > times + ^.as-bytes > pos-inf-as-bytes! + + negative-infinity > neg-inf! + neg-inf.as-bytes > neg-inf-as-bytes! + + nan > not-a-number! + not-a-number.as-bytes > nan-as-bytes! + + 0.0.as-bytes > zero-as-bytes! + + reduced. > res-bytes! + list + x + pos-inf-as-bytes + [acc-as-bytes num] + if. > @ + or. + acc-as-bytes.eq nan-as-bytes + eq. + num.as-bytes > num-as-bytes! + zero-as-bytes + num-as-bytes.eq nan-as-bytes + nan-as-bytes + if. + acc-as-bytes.eq neg-inf-as-bytes + if. + num-as-bytes.eq neg-inf-as-bytes + pos-inf-as-bytes + neg-inf-as-bytes + if. + num-as-bytes.eq neg-inf-as-bytes + neg-inf-as-bytes + pos-inf-as-bytes + if. > @ - or. - x.as-bytes.eq (nan.as-bytes) - x.eq 0.0 - x.eq 0 - nan + res-bytes.eq nan-as-bytes + not-a-number if. - x.eq negative-infinity - negative-infinity + res-bytes.eq pos-inf-as-bytes ^ + neg-inf # Sum of $ and x - [x] > plus + [x...] > plus + ^ > pos-inf! + pos-inf.as-bytes > pos-inf-as-bytes! + + negative-infinity.as-bytes > neg-inf-as-bytes! + + nan > not-a-number! + not-a-number.as-bytes > nan-as-bytes! + + x.length > x-length! + + [acc-as-bytes nums index] > rec-plus + if. > @ + index.eq x-length + acc-as-bytes + [] + (nums.at index).as-bytes > num-as-bytes! + if. > @ + or. + acc-as-bytes.eq nan-as-bytes + num-as-bytes.eq nan-as-bytes + num-as-bytes.eq neg-inf-as-bytes + nan-as-bytes + rec-plus + pos-inf-as-bytes + nums + index.plus 1 + if. > @ - or. - x.as-bytes.eq (nan.as-bytes) - x.eq negative-infinity - nan - ^ + eq. + rec-plus + pos-inf-as-bytes + x + 0 + nan-as-bytes + not-a-number + pos-inf # Negation of $ [] > neg negative-infinity > @ - # Sign of $ (-1.0, 0.0, or 1.0) - [] > signum - 1.0 > @ - # Difference between $ and x - [x] > minus - ^.plus (x.neg) > @ + [x...] > minus + ^ > pos-inf! + pos-inf.as-bytes > pos-inf-as-bytes! + + negative-infinity.as-bytes > neg-inf-as-bytes! + + nan > not-a-number! + not-a-number.as-bytes > nan-as-bytes! + + reduced. > res-bytes! + list + x + pos-inf-as-bytes + [acc-as-bytes num] + if. > @ + or. + acc-as-bytes.eq nan-as-bytes + eq. + num.neg.as-bytes > num-neg-as-bytes! + neg-inf-as-bytes + num-neg-as-bytes.eq nan-as-bytes + nan-as-bytes + pos-inf-as-bytes - # Quotient of the division of $ by x - [x] > div if. > @ - or. - x.as-bytes.eq (nan.as-bytes) - x.eq negative-infinity - x.eq ^ - nan + res-bytes.eq nan-as-bytes + not-a-number ^ - # Converts this to bytes - [] > as-bytes - ^.@.as-bytes > @ - - # Converts this to int - [] > as-int - error "You can not convert positive infinity to int" > @ + # Quotient of the division of $ by x + [x...] > div + ^ > pos-inf! + pos-inf.as-bytes > pos-inf-as-bytes! + + negative-infinity.as-bytes > neg-inf-as-bytes! + + nan > not-a-number! + not-a-number.as-bytes > nan-as-bytes! + + reduced. > res-bytes! + list + x + pos-inf-as-bytes + [acc-as-bytes num] + if. > @ + or. + acc-as-bytes.eq nan-as-bytes + eq. + num.as-bytes > num-as-bytes! + pos-inf-as-bytes + num-as-bytes.eq neg-inf-as-bytes + num-as-bytes.eq nan-as-bytes + nan-as-bytes + pos-inf-as-bytes - # Converts this to string - [] > as-string - "+∞" > @ + if. > @ + res-bytes.eq nan-as-bytes + not-a-number + ^ From 8c57e9a937aebc967c0c1e4ccf5b6cef3e47a77b Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Sat, 18 Feb 2023 23:09:16 +0300 Subject: [PATCH 2/3] Last --- .../main/eo/org/eolang/negative-infinity.eo | 74 ++++--- .../main/eo/org/eolang/positive-infinity.eo | 181 ++++++------------ .../eo/org/eolang/negative-infinity-tests.eo | 23 +++ .../eo/org/eolang/positive-infinity-tests.eo | 23 ++- 4 files changed, 153 insertions(+), 148 deletions(-) diff --git a/eo-runtime/src/main/eo/org/eolang/negative-infinity.eo b/eo-runtime/src/main/eo/org/eolang/negative-infinity.eo index ab7be4e5c8..96b46a1cba 100644 --- a/eo-runtime/src/main/eo/org/eolang/negative-infinity.eo +++ b/eo-runtime/src/main/eo/org/eolang/negative-infinity.eo @@ -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 ^ diff --git a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo index 780d4e3cc6..9b887b8357 100644 --- a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo +++ b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo @@ -58,150 +58,91 @@ x.as-bytes nan.as-bytes + # @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 # Multiplication of $ and x [x...] > times - ^.as-bytes > pos-inf-as-bytes! - - negative-infinity > neg-inf! - neg-inf.as-bytes > neg-inf-as-bytes! - - nan > not-a-number! - not-a-number.as-bytes > nan-as-bytes! - - 0.0.as-bytes > zero-as-bytes! - - reduced. > res-bytes! - list - x - pos-inf-as-bytes - [acc-as-bytes num] - if. > @ - or. - acc-as-bytes.eq nan-as-bytes - eq. - num.as-bytes > num-as-bytes! - zero-as-bytes - num-as-bytes.eq nan-as-bytes - nan-as-bytes - if. - acc-as-bytes.eq neg-inf-as-bytes - if. - num-as-bytes.eq neg-inf-as-bytes - pos-inf-as-bytes - neg-inf-as-bytes - if. - num-as-bytes.eq neg-inf-as-bytes - neg-inf-as-bytes - pos-inf-as-bytes - + x.at 0 > first! if. > @ - res-bytes.eq nan-as-bytes - not-a-number + or. + first.as-bytes.eq (nan.as-bytes) + first.eq 0.0 + first.eq 0 + nan if. - res-bytes.eq pos-inf-as-bytes + first.eq negative-infinity + negative-infinity ^ - neg-inf # Sum of $ and x [x...] > plus - ^ > pos-inf! - pos-inf.as-bytes > pos-inf-as-bytes! - negative-infinity.as-bytes > neg-inf-as-bytes! - nan > not-a-number! - not-a-number.as-bytes > nan-as-bytes! - - x.length > x-length! - - [acc-as-bytes nums index] > rec-plus + [acc index terms check-term] > plus-rec if. > @ - index.eq x-length - acc-as-bytes - [] - (nums.at index).as-bytes > num-as-bytes! - if. > @ - or. - acc-as-bytes.eq nan-as-bytes - num-as-bytes.eq nan-as-bytes - num-as-bytes.eq neg-inf-as-bytes - nan-as-bytes - rec-plus - pos-inf-as-bytes - nums - index.plus 1 + 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. > @ eq. - rec-plus - pos-inf-as-bytes - x + x.length > terms-count! + 0 + ^ + if. + terms-count.gt 1 + plus-rec + ^ 0 - nan-as-bytes - not-a-number - pos-inf + x + check-term + if. + check-term + x.at 0 + nan + ^ # Negation of $ [] > neg negative-infinity > @ + # @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 # Difference between $ and x [x...] > minus - ^ > pos-inf! - pos-inf.as-bytes > pos-inf-as-bytes! - - negative-infinity.as-bytes > neg-inf-as-bytes! - - nan > not-a-number! - not-a-number.as-bytes > nan-as-bytes! - - reduced. > res-bytes! - list - x - pos-inf-as-bytes - [acc-as-bytes num] - if. > @ - or. - acc-as-bytes.eq nan-as-bytes - eq. - num.neg.as-bytes > num-neg-as-bytes! - neg-inf-as-bytes - num-neg-as-bytes.eq nan-as-bytes - nan-as-bytes - pos-inf-as-bytes - - if. > @ - res-bytes.eq nan-as-bytes - not-a-number - ^ + ^.plus ((x.at 0).neg) > @ + # @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 # Quotient of the division of $ by x [x...] > div - ^ > pos-inf! - pos-inf.as-bytes > pos-inf-as-bytes! - - negative-infinity.as-bytes > neg-inf-as-bytes! - - nan > not-a-number! - not-a-number.as-bytes > nan-as-bytes! - - reduced. > res-bytes! - list - x - pos-inf-as-bytes - [acc-as-bytes num] - if. > @ - or. - acc-as-bytes.eq nan-as-bytes - eq. - num.as-bytes > num-as-bytes! - pos-inf-as-bytes - num-as-bytes.eq neg-inf-as-bytes - num-as-bytes.eq nan-as-bytes - nan-as-bytes - pos-inf-as-bytes - + x.at 0 > first! if. > @ - res-bytes.eq nan-as-bytes - not-a-number + or. + first.as-bytes.eq (nan.as-bytes) + first.eq negative-infinity + first.eq ^ + nan ^ + + # Converts this to bytes + [] > as-bytes + ^.@.as-bytes > @ diff --git a/eo-runtime/src/test/eo/org/eolang/negative-infinity-tests.eo b/eo-runtime/src/test/eo/org/eolang/negative-infinity-tests.eo index 3d9f00af98..6ac9bfbfdc 100644 --- a/eo-runtime/src/test/eo/org/eolang/negative-infinity-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/negative-infinity-tests.eo @@ -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 > @ diff --git a/eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo b/eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo index 1d356b7612..283d3ab3fd 100644 --- a/eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo @@ -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 > @ From b055d99146b8d4451e7d22629ec399cfc7d67ccc Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Mon, 20 Feb 2023 23:14:27 +0300 Subject: [PATCH 3/3] comments --- eo-runtime/src/main/eo/org/eolang/positive-infinity.eo | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo index 9b887b8357..a9fa9ec3ca 100644 --- a/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo +++ b/eo-runtime/src/main/eo/org/eolang/positive-infinity.eo @@ -58,10 +58,10 @@ x.as-bytes nan.as-bytes + # Multiplication of $ and x # @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 - # Multiplication of $ and x [x...] > times x.at 0 > first! if. > @ @@ -122,17 +122,17 @@ [] > neg negative-infinity > @ + # Difference between $ and x # @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 - # Difference between $ and x [x...] > minus ^.plus ((x.at 0).neg) > @ + # Quotient of the division of $ by x # @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 - # Quotient of the division of $ by x [x...] > div x.at 0 > first! if. > @