Replies: 2 comments
This comment has been hidden.
This comment has been hidden.
-
See the issue #661 for the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Based on the concept of bijection and our desire to represent real world objects with our explicit types, we would like to re-implement a new type-system for integers.
Representation
For a full coverage, this type-system should include the following types:
Zero
type representing the zero number.PositiveInteger
type representing an integer that is greater than zero (in the[1;+∞[
range).NegativeInteger
type representing an integer that is less than zero (in the]-∞;-1]
range).NonNegativeInteger
type representing an integer that is greater than or equal to zero (in the[0;+∞[
range).NonPositiveInteger
type representing an integer that is less than or equal to zero (in the]-∞;0]
range).NonZeroInteger
type representing an integer that is other than zero (in the]-∞;-1]∪[1;+∞[
range).Integer
type representing an integer.These types have a subset relationship with others:
Zero
type is a subset of theNonPositiveInteger
and theNonNegativeInteger
types.PositiveInteger
type is a subset of theNonNegativeInteger
and theNonZeroInteger
types.NegativeInteger
type is a subset of theNonPositiveInteger
and theNonZeroInteger
types.NonPositiveInteger
, theNonNegativeInteger
and theNonZeroInteger
types are subsets of theInteger
type.Here's an example of valid representation of this type-system using Kotlin:
Note
Since practical computers are of finite capacity, we could represent them internally using arrays.
For example, we can consider that the number
1234
is[1, 2, 3, 4]
.Operations
These types should support the following basic operations:
unaryMinus
operation (-x
) for returning the additive inverse of an integer.plus
operation (x + y
) for adding two integers.minus
operation (x - y
) for subtracting an integer from another one.times
operation (x * y
) multiplying an integer by another one.div
operation (x / y
) for dividing an integer by another one.rem
operation (x % y
) for calculating the remainder of truncating division of an integer by another one.Beta Was this translation helpful? Give feedback.
All reactions