Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#3251): introduced i64 object #3337

Merged
merged 21 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
# package name contains capital letter and such names are conventional.
---
exclude_paths:
- "eo-runtime/src/test/java/org/eolang/SnippetIT.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOi64$EOas_number.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOi64$EOdiv.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOi64$EOgt.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOi64$EOplus.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOi64$EOtimes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOnumber$EOas_i64.java"
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ public void enterData(final EoParser.DataContext ctx) {
data = XeEoListener.bytesToHex(
ByteBuffer
.allocate(Double.BYTES)
.putDouble(((Long) Long.parseLong(text)).doubleValue())
.putDouble(Double.parseDouble(text))
.array()
);
} else if (ctx.HEX() != null) {
Expand Down
18 changes: 17 additions & 1 deletion eo-runtime/src/main/eo/org/eolang/bytes.eo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

+alias org.eolang.txt.sprintf
+architect [email protected]
+home https://github.com/objectionary/eo
+package org.eolang
Expand Down Expand Up @@ -53,7 +54,22 @@
if. > @
^.size.eq 8
number ^
error "Can't convert non 8 length bytes to a number"
error
sprintf
"Can't convert non 8 length bytes to a number, bytes are %s"
* ^

# Turn this chain of eight bytes into a i64 number.
# If there are less or more than eight bytes, there will
# be an error returned.
[] > as-i64
if. > @
^.size.eq 8
i64 ^
error
sprintf
"Can't convert non 8 length bytes to i64, bytes are %s"
* ^

# Calculate bitwise and.
[b] > and /bytes
Expand Down
91 changes: 91 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/i64.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

+architect [email protected]
+home https://github.com/objectionary/eo
+package org.eolang
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0

# The 64 bits signed integer.
# Here `as-bytes` must be a `bytes` object.
[as-bytes] > i64
as-bytes > @
$ > as-i64
times -1.as-i64 > neg

# Convert this `i64` to `number` object.
[] > as-number /number

# Returns true if `$` = `x` in terms of bytes.
# Here `x` can be a `number` or any other object which
# can be converted to `bytes` via `as-bytes` object.
^.as-bytes.eq x.as-bytes > [x] > eq

# Returns `true` if `$` < `x`.
# Here `x` must be an `i64` object.
[x] > lt
x > value!
0.as-i64.gt > @
^.minus
i64 value

# Returns `true` if `$` <= `x`.
# Here `x` must be an `i64` object.
[x] > lte
x > value!
or. > @
^.lt value
^.eq value

# Returns `true` if `$` > `x`.
# Here `x` must be an `i64` object.
[x] > gt /bool

# Returns `true` if `$` >= `x`.
# Here `x` must be an `i64` object.
[x] > gte
x > value!
or. > @
^.gt value
^.eq value

# Multiplication of `$` and `x`.
# Here `x` must be an `i64` object.
[x] > times /i64

# Sum of `$` and `x`.
# Here `x` must be an `i64` object.
[x] > plus /i64

# Subtraction between `$` and `x`.
# Here `x` must be an `i64` object.
[x] > minus
x > value!
^.plus > @
(i64 value).neg

# Quotient of the division of `$` by `x`.
# Here `x` must be an `i64` object.
# An `error` is returned if or `x` is equal to 0.
[x] > div /i64
11 changes: 7 additions & 4 deletions eo-runtime/src/main/eo/org/eolang/nan.eo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@

# Not a number.
[] > nan
0.0.div 0.0 > @
number 7F-F8-00-00-00-00-00-00 > @
$ > floor
$ > neg
true > is-nan
false > is-finite
false > is-integer
error "Can't convert NaN to i64" > as-i64

# Tests that $ = x.
false > [x] > eq
Expand All @@ -52,9 +58,6 @@
# Sum of $ and x.
^ > [x] > plus

# Negation of $.
^ > [] > neg

# Difference between $ and x.
^ > [x] > minus

Expand Down
63 changes: 25 additions & 38 deletions eo-runtime/src/main/eo/org/eolang/negative-infinity.eo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@

# Negative infinity.
[] > negative-infinity
-1.0.div 0.0 > @
number FF-F0-00-00-00-00-00-00 > @
$ > floor
positive-infinity > neg
false > is-nan
false > is-finite
false > is-integer
error "Can't convert negative infinity to i64" > as-i64

# Tests that $ = x.
[x] > eq
Expand All @@ -42,86 +48,67 @@
x > value!
not. > @
or.
value.eq nan.as-bytes
(number value).is-nan
^.eq value

# Tests that $ ≤ x.
[x] > lte
x > value!
not. > @
eq.
x.as-bytes
nan.as-bytes
(number value).is-nan

# Tests that $ > x.
[x] > gt
false > @
false > [x] > gt

# Tests that $ ≥ x.
[x] > gte
^.eq x > @
^.eq x > [x] > gte

# Multiplication of $ and x.
[x] > times
x > value!
number value > num
if. > @
is-nan-or-zero value
or.
num.is-nan
num.eq 0
nan
if.
0.lt value
num.gt 0
^
positive-infinity

num.eq nan.as-bytes > [num] > is-nan

[num] > is-nan-or-zero
or. > @
or.
is-nan num
num.eq -0.0
num.eq 0.0

# Sum of $ and x.
[x] > plus
x > value!
if. > @
or.
is-nan value
(number value).is-nan
value.eq positive-infinity
nan
^

num.eq nan.as-bytes > [num] > is-nan

# Difference between $ and x.
[x] > minus
x > value!
if. > @
or.
is-nan value
(number value).is-nan
value.eq ^
nan
^

num.eq nan.as-bytes > [num] > is-nan

# Quotient of the division of $ by x
[x] > div
x > value!
number value > num
if. > @
is-nan-or-infinite value
or.
num.is-nan
num.is-finite.not
nan
if.
or.
value.eq -0.0.as-bytes
0.0.gt value
value.eq -0.as-bytes
0.gt value
positive-infinity
^

num.eq nan.as-bytes > [num] > is-nan

[num] > is-nan-or-infinite
or. > @
or.
is-nan num
num.eq positive-infinity
num.eq ^.^
Loading
Loading