diff --git a/stdlib/int8.gr b/stdlib/int8.gr index cf1c8c51f2..0caa952ae3 100644 --- a/stdlib/int8.gr +++ b/stdlib/int8.gr @@ -2,6 +2,9 @@ * Utilities for working with the Int8 type. * @example include "int8" * + * @example 1s + * @example -1s + * * @since v0.6.0 */ @@ -51,6 +54,8 @@ provide { fromNumber, toNumber } * @param number: The value to convert * @returns The Uint8 represented as an Int8 * + * @example Int8.fromUint8(1us) == 1s + * * @since v0.6.0 */ @unsafe @@ -67,6 +72,9 @@ provide let fromUint8 = (x: Uint8) => { * @param value: The value to increment * @returns The incremented value * + * @example Int8.incr(1s) == 2s + * @example Int8.incr(-2s) == -1s + * * @since v0.6.0 */ @unsafe @@ -83,6 +91,9 @@ provide let incr = (value: Int8) => { * @param value: The value to decrement * @returns The decremented value * + * @example Int8.decr(2s) == 1s + * @example Int8.decr(0s) == -1s + * * @since v0.6.0 */ @unsafe @@ -100,6 +111,10 @@ provide let decr = (value: Int8) => { * @param y: The second operand * @returns The sum of the two operands * + * @example + * from Int8 use { (+) } + * assert 1s + 1s == 2s + * * @since v0.6.0 */ @unsafe @@ -121,6 +136,10 @@ provide let (+) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns The difference of the two operands * + * @example + * from Int8 use { (-) } + * assert 2s - 1s == 1s + * * @since v0.6.0 */ @unsafe @@ -139,6 +158,10 @@ provide let (-) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns The product of the two operands * + * @example + * from Int8 use { (*) } + * assert 2s * 2s == 4s + * * @since v0.6.0 */ @unsafe @@ -156,6 +179,10 @@ provide let (*) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns The quotient of its operands * + * @example + * from Int8 use { (/) } + * assert 8s / 2s == 4s + * * @since v0.6.0 */ @unsafe @@ -174,6 +201,8 @@ provide let (/) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns The remainder of its operands * + * @example Int8.rem(8s, 3s) == 2s + * * @since v0.6.0 */ @unsafe @@ -202,6 +231,10 @@ let abs = n => { * * @throws ModuloByZero: When `y` is zero * + * @example + * from Int8 use { (%) } + * assert -5s % 3s == 1s + * * @since v0.6.0 */ @unsafe @@ -233,6 +266,10 @@ provide let (%) = (x: Int8, y: Int8) => { * @param amount: The number of bits to shift by * @returns The shifted value * + * @example + * from Int8 use { (<<) } + * assert (5s << 1s) == 10s + * * @since v0.6.0 */ @unsafe @@ -252,6 +289,10 @@ provide let (<<) = (value: Int8, amount: Int8) => { * @param amount: The amount to shift by * @returns The shifted value * + * @example + * from Int8 use { (>>) } + * assert (5s >> 1s) == 2s + * * @since v0.6.0 */ @unsafe @@ -271,6 +312,10 @@ provide let (>>) = (value: Int8, amount: Int8) => { * @param y: The second value * @returns `true` if the first value is equal to the second value or `false` otherwise * + * @example + * from Int8 use { (==) } + * assert 1s == 1s + * * @since v0.6.0 */ @unsafe @@ -287,6 +332,10 @@ provide let (==) = (x: Int8, y: Int8) => { * @param y: The second value * @returns `true` if the first value is not equal to the second value or `false` otherwise * + * @example + * from Int8 use { (!=) } + * assert 1s != 2s + * * @since v0.6.0 */ @unsafe @@ -303,6 +352,10 @@ provide let (!=) = (x: Int8, y: Int8) => { * @param y: The second value * @returns `true` if the first value is less than the second value or `false` otherwise * + * @example + * from Int8 use { (<) } + * assert 1s < 2s + * * @since v0.6.0 */ @unsafe @@ -319,6 +372,10 @@ provide let (<) = (x: Int8, y: Int8) => { * @param y: The second value * @returns `true` if the first value is greater than the second value or `false` otherwise * + * @example + * from Int8 use { (>) } + * assert 2s > 1s + * * @since v0.6.0 */ @unsafe @@ -335,6 +392,13 @@ provide let (>) = (x: Int8, y: Int8) => { * @param y: The second value * @returns `true` if the first value is less than or equal to the second value or `false` otherwise * + * @example + * from Int8 use { (<=) } + * assert 1s <= 2s + * @example + * from Int8 use { (<=) } + * assert 1s <= 1s + * * @since v0.6.0 */ @unsafe @@ -351,6 +415,13 @@ provide let (<=) = (x: Int8, y: Int8) => { * @param y: The second value * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise * + * @example + * from Int8 use { (>=) } + * assert 2s >= 1s + * @example + * from Int8 use { (>=) } + * assert 1s >= 1s + * * @since v0.6.0 */ @unsafe @@ -366,6 +437,8 @@ provide let (>=) = (x: Int8, y: Int8) => { * @param value: The given value * @returns Containing the inverted bits of the given value * + * @example Int.lnot(-5s) == 4s + * * @since v0.6.0 */ @unsafe @@ -381,6 +454,10 @@ provide let lnot = (value: Int8) => { * @param y: The second operand * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1` * + * @example + * from Int8 use { (&) } + * assert (3s & 4s) == 0s + * * @since v0.6.0 */ @unsafe @@ -399,6 +476,10 @@ provide let (&) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1` * + * @example + * from Int8 use { (|) } + * assert (3s | 4s) == 7s + * * @since v0.6.0 */ @unsafe @@ -417,6 +498,10 @@ provide let (|) = (x: Int8, y: Int8) => { * @param y: The second operand * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1` * + * @example + * from Int8 use { (^) } + * assert (3s ^ 5s) == 6s + * * @since v0.6.0 */ @unsafe diff --git a/stdlib/int8.md b/stdlib/int8.md index f5e88b2f8d..d696bc322a 100644 --- a/stdlib/int8.md +++ b/stdlib/int8.md @@ -13,6 +13,14 @@ No other changes yet. include "int8" ``` +```grain +1s +``` + +```grain +-1s +``` + ## Values Functions and constants included in the Int8 module. @@ -92,6 +100,12 @@ Returns: |----|-----------| |`Int8`|The Uint8 represented as an Int8| +Examples: + +```grain +Int8.fromUint8(1us) == 1s +``` + ### Int8.**incr**
@@ -117,6 +131,16 @@ Returns: |----|-----------| |`Int8`|The incremented value| +Examples: + +```grain +Int8.incr(1s) == 2s +``` + +```grain +Int8.incr(-2s) == -1s +``` + ### Int8.**decr**
@@ -142,6 +166,16 @@ Returns: |----|-----------| |`Int8`|The decremented value| +Examples: + +```grain +Int8.decr(2s) == 1s +``` + +```grain +Int8.decr(0s) == -1s +``` + ### Int8.**(+)**
@@ -168,6 +202,13 @@ Returns: |----|-----------| |`Int8`|The sum of the two operands| +Examples: + +```grain +from Int8 use { (+) } +assert 1s + 1s == 2s +``` + ### Int8.**(-)**
@@ -194,6 +235,13 @@ Returns: |----|-----------| |`Int8`|The difference of the two operands| +Examples: + +```grain +from Int8 use { (-) } +assert 2s - 1s == 1s +``` + ### Int8.**(*)**
@@ -220,6 +268,13 @@ Returns: |----|-----------| |`Int8`|The product of the two operands| +Examples: + +```grain +from Int8 use { (*) } +assert 2s * 2s == 4s +``` + ### Int8.**(/)**
@@ -246,6 +301,13 @@ Returns: |----|-----------| |`Int8`|The quotient of its operands| +Examples: + +```grain +from Int8 use { (/) } +assert 8s / 2s == 4s +``` + ### Int8.**rem**
@@ -272,6 +334,12 @@ Returns: |----|-----------| |`Int8`|The remainder of its operands| +Examples: + +```grain +Int8.rem(8s, 3s) == 2s +``` + ### Int8.**(%)**
@@ -305,6 +373,13 @@ Throws: * When `y` is zero +Examples: + +```grain +from Int8 use { (%) } +assert -5s % 3s == 1s +``` + ### Int8.**(<<)**
@@ -331,6 +406,13 @@ Returns: |----|-----------| |`Int8`|The shifted value| +Examples: + +```grain +from Int8 use { (<<) } +assert (5s << 1s) == 10s +``` + ### Int8.**(>>)**
@@ -357,6 +439,13 @@ Returns: |----|-----------| |`Int8`|The shifted value| +Examples: + +```grain +from Int8 use { (>>) } +assert (5s >> 1s) == 2s +``` + ### Int8.**(==)**
@@ -383,6 +472,13 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is equal to the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (==) } +assert 1s == 1s +``` + ### Int8.**(!=)**
@@ -409,6 +505,13 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is not equal to the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (!=) } +assert 1s != 2s +``` + ### Int8.**(<)**
@@ -435,6 +538,13 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is less than the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (<) } +assert 1s < 2s +``` + ### Int8.**(>)**
@@ -461,6 +571,13 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is greater than the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (>) } +assert 2s > 1s +``` + ### Int8.**(<=)**
@@ -487,6 +604,18 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (<=) } +assert 1s <= 2s +``` + +```grain +from Int8 use { (<=) } +assert 1s <= 1s +``` + ### Int8.**(>=)**
@@ -513,6 +642,18 @@ Returns: |----|-----------| |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise| +Examples: + +```grain +from Int8 use { (>=) } +assert 2s >= 1s +``` + +```grain +from Int8 use { (>=) } +assert 1s >= 1s +``` + ### Int8.**lnot**
@@ -538,6 +679,12 @@ Returns: |----|-----------| |`Int8`|Containing the inverted bits of the given value| +Examples: + +```grain +Int.lnot(-5s) == 4s +``` + ### Int8.**(&)**
@@ -564,6 +711,13 @@ Returns: |----|-----------| |`Int8`|Containing a `1` in each bit position for which the corresponding bits of both operands are `1`| +Examples: + +```grain +from Int8 use { (&) } +assert (3s & 4s) == 0s +``` + ### Int8.**(|)**
@@ -590,6 +744,13 @@ Returns: |----|-----------| |`Int8`|Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`| +Examples: + +```grain +from Int8 use { (|) } +assert (3s | 4s) == 7s +``` + ### Int8.**(^)**
@@ -616,3 +777,10 @@ Returns: |----|-----------| |`Int8`|Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`| +Examples: + +```grain +from Int8 use { (^) } +assert (3s ^ 5s) == 6s +``` +