Skip to content
Draft
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
13 changes: 5 additions & 8 deletions src/int.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,8 @@ struct Int64
end

struct Int128
# TODO: eventually update to literals once UInt128 bit support is finished
MIN = new(1) << 127
MAX = ~MIN
MIN = -170141183460469231731687303715884105728_i128
MAX = 170141183460469231731687303715884105727_i128
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be easy to have a character off here. Is there a spec asserting these numbers are 2**127 - 1 and -(2**127)?

Copy link
Copy Markdown
Contributor

@bew bew Jan 6, 2018

Choose a reason for hiding this comment

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

wouldn't it be better if those numbers are calculated from macros directly, sth like:

MIN = {{ -(2 ** 127) }}_i128
MAX = {{ 2 ** 127 - 1 }}_i128

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Quite possible, these numbers were taken from rust's 128-bit integer support RFC - if they indeed turn out to be wrong, linked wiki page could use an update too.


# Returns an `Int128` by invoking `to_i128` on *value*.
# See `String#to_i` for more details.
Expand Down Expand Up @@ -1070,8 +1069,7 @@ struct Int128
Number.expand_div [Float64], Float64

def -
# TODO: use 0_i128 - self
Int128.new(0) - self
0_i128 - self
end

def popcount
Expand Down Expand Up @@ -1313,9 +1311,8 @@ struct UInt64
end

struct UInt128
# TODO: eventually update to literals once UInt128 bit support is finished
MIN = new 0
MAX = ~MIN
MIN = 0_u128
MAX = 340282366920938463463374607431768211455_u128
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto.


# Returns an `UInt128` by invoking `to_u128` on *value*.
# See `String#to_i` for more details.
Expand Down