Skip to content

Commit

Permalink
Fix: Base library issues in Int8/16/32/64 (#478)
Browse files Browse the repository at this point in the history
Fix some issues reported in #476:
* Offer minimum and maximum integer constants
* Remove superfluous second argument in `bitnot()`
  • Loading branch information
luc-blaeser committed Jan 5, 2023
1 parent b59b2d5 commit 885067b
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 588 deletions.
12 changes: 8 additions & 4 deletions src/Int16.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module {
/// 16-bit signed integers.
public type Int16 = Prim.Types.Int16;

/// Minimum 16-bit integer value, `-2 ** 15`.
public let minimumValue = -32_768 : Int16;

/// Maximum 16-bit integer value, `+2 ** 15 - 1`.
public let maximumValue = 32_767 : Int16;

/// Converts a 16-bit signed integer to a signed integer with infinite precision.
///
/// Example:
Expand Down Expand Up @@ -279,16 +285,14 @@ module {
public func pow(x : Int16, y : Int16) : Int16 { x ** y };

/// Returns the bitwise negation of `x`, `^x`.
/// Issue: The argument `y` is not needed and will be removed in future.
///
/// Example:
/// ```motoko
/// import Int16 "mo:base/Int16";
///
/// let unused = 0 : Int16; // will be fixed in future
/// Int16.bitnot(-256 /* 0xff00 */, unused) // => +255 // 0xff
/// Int16.bitnot(-256 /* 0xff00 */) // => +255 // 0xff
/// ```
public func bitnot(x : Int16, y : Int16) : Int16 { ^x };
public func bitnot(x : Int16) : Int16 { ^x };

/// Returns the bitwise "and" of `x` and `y`, `x & y`.
///
Expand Down
12 changes: 8 additions & 4 deletions src/Int32.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module {
/// 32-bit signed integers.
public type Int32 = Prim.Types.Int32;

/// Minimum 32-bit integer value, `-2 ** 31`.
public let minimumValue = -2_147_483_648 : Int32;

/// Maximum 32-bit integer value, `+2 ** 31 - 1`.
public let maximumValue = 2_147_483_647 : Int32;

/// Converts a 32-bit signed integer to a signed integer with infinite precision.
///
/// Example:
Expand Down Expand Up @@ -279,16 +285,14 @@ module {
public func pow(x : Int32, y : Int32) : Int32 { x ** y };

/// Returns the bitwise negation of `x`, `^x`.
/// Issue: The argument `y` is not needed and will be removed in future.
///
/// Example:
/// ```motoko
/// import Int32 "mo:base/Int32";
///
/// let unused = 0 : Int32; // will be fixed in future
/// Int32.bitnot(-256 /* 0xffff_ff00 */, unused) // => +255 // 0xff
/// Int32.bitnot(-256 /* 0xffff_ff00 */) // => +255 // 0xff
/// ```
public func bitnot(x : Int32, y : Int32) : Int32 { ^x };
public func bitnot(x : Int32) : Int32 { ^x };

/// Returns the bitwise "and" of `x` and `y`, `x & y`.
///
Expand Down
12 changes: 8 additions & 4 deletions src/Int64.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module {
/// 64-bit signed integers.
public type Int64 = Prim.Types.Int64;

/// Minimum 64-bit integer value, `-2 ** 63`.
public let minimumValue = -9_223_372_036_854_775_808 : Int64;

/// Maximum 64-bit integer value, `+2 ** 63 - 1`.
public let maximumValue = 9_223_372_036_854_775_807 : Int64;

/// Converts a 64-bit signed integer to a signed integer with infinite precision.
///
/// Example:
Expand Down Expand Up @@ -279,16 +285,14 @@ module {
public func pow(x : Int64, y : Int64) : Int64 { x ** y };

/// Returns the bitwise negation of `x`, `^x`.
/// Issue: The argument `y` is not needed and will be removed in future.
///
/// Example:
/// ```motoko
/// import Int64 "mo:base/Int64";
///
/// let unused = 0 : Int64; // will be fixed in future
/// Int64.bitnot(-256 /* 0xffff_ffff_ffff_ff00 */, unused) // => +255 // 0xff
/// Int64.bitnot(-256 /* 0xffff_ffff_ffff_ff00 */) // => +255 // 0xff
/// ```
public func bitnot(x : Int64, y : Int64) : Int64 { ^x };
public func bitnot(x : Int64) : Int64 { ^x };

/// Returns the bitwise "and" of `x` and `y`, `x & y`.
///
Expand Down
12 changes: 8 additions & 4 deletions src/Int8.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module {
/// 8-bit signed integers.
public type Int8 = Prim.Types.Int8;

/// Minimum 8-bit integer value, `-2 ** 7`.
public let minimumValue = -128 : Int8;

/// Maximum 8-bit integer value, `+2 ** 7 - 1`.
public let maximumValue = 127 : Int8;

/// Converts a 8-bit signed integer to a signed integer with infinite precision.
///
/// Example:
Expand Down Expand Up @@ -279,16 +285,14 @@ module {
public func pow(x : Int8, y : Int8) : Int8 { x ** y };

/// Returns the bitwise negation of `x`, `^x`.
/// Issue: The argument `y` is not needed and will be removed in future.
///
/// Example:
/// ```motoko
/// import Int8 "mo:base/Int8";
///
/// let unused = 0 : Int8; // will be fixed in future
/// Int8.bitnot(-16 /* 0xf0 */, unused) // => +15 // 0x0f
/// Int8.bitnot(-16 /* 0xf0 */) // => +15 // 0x0f
/// ```
public func bitnot(x : Int8, y : Int8) : Int8 { ^x };
public func bitnot(x : Int8) : Int8 { ^x };

/// Returns the bitwise "and" of `x` and `y`, `x & y`.
///
Expand Down
Loading

0 comments on commit 885067b

Please sign in to comment.