UNPKG

motoko

Version:

Compile and run Motoko smart contracts in Node.js or the browser.

1 lines 1.25 MB
{"name":"core","version":"v2.5.0","files":{"Error.mo":{"content":"/// Error values and inspection.\n///\n/// The `Error` type is the argument to `throw`, parameter of `catch`.\n/// The `Error` type is opaque.\n\nimport Prim \"mo:⛔\";\n\nmodule {\n\n /// Error value resulting from `async` computations\n public type Error = Prim.Types.Error;\n\n /// Error code to classify different kinds of user and system errors:\n /// ```motoko\n /// type ErrorCode = {\n /// // Fatal error.\n /// #system_fatal;\n /// // Transient error.\n /// #system_transient;\n /// // Destination invalid.\n /// #destination_invalid;\n /// // Canister error (e.g., trap, no response).\n /// #canister_error;\n /// // Explicit reject by canister code.\n /// #canister_reject;\n /// // Response unknown; system stopped waiting for it (e.g., timed out, or system under high load).\n /// #system_unknown;\n /// // Future error code (with unrecognized numeric code).\n /// #future : Nat32;\n /// // Error issuing inter-canister call\n /// // (indicating destination queue full or freezing threshold crossed).\n /// #call_error : { err_code : Nat32 }\n /// };\n /// ```\n public type ErrorCode = Prim.ErrorCode;\n\n /// Create an error from the message with the code `#canister_reject`.\n ///\n /// Example:\n /// ```motoko\n /// import Error \"mo:core/Error\";\n ///\n /// Error.reject(\"Example error\") // can be used as throw argument\n /// ```\n public let reject : (message : Text) -> Error = Prim.error;\n\n /// Returns the code of an error.\n ///\n /// Example:\n /// ```motoko\n /// import Error \"mo:core/Error\";\n ///\n /// let error = Error.reject(\"Example error\");\n /// Error.code(error) // #canister_reject\n /// ```\n public let code : (self : Error) -> ErrorCode = Prim.errorCode;\n\n /// Returns the message of an error.\n ///\n /// Example:\n /// ```motoko\n /// import Error \"mo:core/Error\";\n ///\n /// let error = Error.reject(\"Example error\");\n /// Error.message(error) // \"Example error\"\n /// ```\n public let message : (self : Error) -> Text = Prim.errorMessage;\n\n /// Checks if the error is a clean reject.\n /// A clean reject means that there must be no state changes on the callee side.\n public func isCleanReject(self : Error) : Bool = switch (code(self)) {\n case (#system_fatal or #system_transient or #destination_invalid or #call_error _) true;\n case _ false\n };\n\n /// Returns whether retrying to send a message may result in success.\n ///\n /// Example:\n /// ```motoko\n /// import Error \"mo:core/Error\";\n /// import Debug \"mo:core/Debug\";\n ///\n /// persistent actor {\n /// type CallableActor = actor {\n /// call : () -> async ()\n /// };\n ///\n /// public func example(callableActor : CallableActor) {\n /// try {\n /// await (with timeout = 3) callableActor.call();\n /// }\n /// catch e {\n /// if (Error.isRetryPossible e) {\n /// Debug.print(Error.message e);\n /// }\n /// }\n /// }\n /// }\n ///\n /// ```\n public func isRetryPossible(self : Error) : Bool = switch (code(self)) {\n case (#system_transient or #system_unknown) true;\n case _ false\n };\n\n}\n"},"Base64.mo":{"content":"/// Module for Base64 encoding of byte sequences.\n///\n/// Base64 encoding converts binary data to an ASCII string using 64 printable\n/// characters, as specified in [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648).\n/// It is widely used for HTTP Basic Authentication, encoding binary data in\n/// JSON payloads, and data URIs.\n///\n/// This module uses the standard Base64 alphabet (`A–Z`, `a–z`, `0–9`, `+`, `/`)\n/// and pads output to a multiple of 4 characters using `=`.\n///\n/// Original version authored by Claude Sonnet (claude-sonnet-4-6) for use in generated\n/// Motoko API clients. The module received subsequent manual performance improvements.\n///\n/// Import from the core package to use this module.\n/// ```motoko name=import\n/// import Base64 \"mo:core/Base64\";\n/// ```\n\nimport Blob \"Blob\";\nimport Nat8 \"Nat8\";\nimport Nat16 \"Nat16\";\nimport Nat32 \"Nat32\";\nimport Nat64 \"Nat64\";\nimport Text \"Text\";\nimport Prim \"mo:prim\";\n\nmodule {\n\n // Standard Base64 alphabet (RFC 4648 §4) in UTF8 values.\n // Equivalent to Text form:\n /*\n private let alphabet : [Text] = [\n \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\",\n \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\",\n \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\",\n \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\",\n \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"+\", \"/\"\n ];\n */\n // prettier-ignore\n private let alphabet : [Nat8] = [\n 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,\n 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,\n 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,\n 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,\n 43, 47\n ];\n\n /// Encodes a `Blob` as a Base64 `Text` string (RFC 4648 §4).\n ///\n /// Output length is always a multiple of 4, padded with `=` as needed.\n /// An empty `Blob` encodes to an empty `Text`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Base64.encode(\"\" : Blob) == \"\";\n /// assert Base64.encode(\"f\" : Blob) == \"Zg==\";\n /// assert Base64.encode(\"fo\" : Blob) == \"Zm8=\";\n /// assert Base64.encode(\"foo\" : Blob) == \"Zm9v\";\n /// assert Base64.encode(\"foobar\" : Blob) == \"Zm9vYmFy\";\n /// ```\n ///\n /// Typical use — embedding text in a data URI:\n /// ```motoko include=import\n /// let payload = \"Hello\" : Blob;\n /// let uri = \"data:text/plain;base64,\" # Base64.encode(payload);\n /// assert uri == \"data:text/plain;base64,SGVsbG8=\";\n /// ```\n public func encode(data : Blob) : Text {\n let sz = Nat64.fromIntWrap(data.size());\n var result = \"\";\n var i = 0 : Nat64;\n var next_i = 6 : Nat64;\n\n // Process chunks of 6 input bytes at a time (8 output characters)\n while (next_i <= sz) {\n let b1 = data[i.toNat()];\n let b2 : Nat8 = data[(i +% 1).toNat()];\n let b3 : Nat8 = data[(i +% 2).toNat()];\n let b4 : Nat8 = data[(i +% 3).toNat()];\n let b5 : Nat8 = data[(i +% 4).toNat()];\n let b6 : Nat8 = data[(i +% 5).toNat()];\n\n let n = (b1.toNat16().toNat32() << 16) | (b2.toNat16().toNat32() << 8) | b3.toNat16().toNat32();\n let m = (b4.toNat16().toNat32() << 16) | (b5.toNat16().toNat32() << 8) | b6.toNat16().toNat32();\n\n let bytes = Blob.fromArray([\n alphabet[((n >> 18) & 0x3F).toNat()],\n alphabet[((n >> 12) & 0x3F).toNat()],\n alphabet[((n >> 6) & 0x3F).toNat()],\n alphabet[(n & 0x3F).toNat()],\n alphabet[((m >> 18) & 0x3F).toNat()],\n alphabet[((m >> 12) & 0x3F).toNat()],\n alphabet[((m >> 6) & 0x3F).toNat()],\n alphabet[(m & 0x3F).toNat()]\n ]);\n\n switch (Text.decodeUtf8(bytes)) {\n case (?t) result := result # t;\n case (_) {\n Prim.trap(\"Cannot happen: Utf8 decode error in Base64.encode().\")\n }\n };\n\n i := next_i;\n next_i +%= 6\n };\n\n // Process remaining 0-5 input bytes in chunks of 3\n while (i < sz) {\n let b1 = data[i.toNat()];\n let b2 : Nat8 = if (i +% 1 < sz) data[(i +% 1).toNat()] else 0;\n let b3 : Nat8 = if (i +% 2 < sz) data[(i +% 2).toNat()] else 0;\n\n let n = (b1.toNat16().toNat32() << 16) | (b2.toNat16().toNat32() << 8) | b3.toNat16().toNat32();\n\n // Note: Value 61 is the UTF8 encoding of the `=` character\n let bytes = Blob.fromArray([\n alphabet[((n >> 18) & 0x3F).toNat()],\n alphabet[((n >> 12) & 0x3F).toNat()],\n if (i +% 1 < sz) alphabet[((n >> 6) & 0x3F).toNat()] else 61,\n if (i +% 2 < sz) alphabet[(n & 0x3F).toNat()] else 61\n ]);\n\n switch (Text.decodeUtf8(bytes)) {\n case (?t) result := result # t;\n case (_) {\n Prim.trap(\"Cannot happen: Utf8 decode error in Base64.encode().\")\n }\n };\n\n i +%= 3\n };\n result\n };\n\n}\n"},"Int16.mo":{"content":"/// Utility functions on 16-bit signed integers.\n///\n/// Note that most operations are available as built-in operators (e.g. `1 + 1`).\n///\n/// Import from the core package to use this module.\n/// ```motoko name=import\n/// import Int16 \"mo:core/Int16\";\n/// ```\n\nimport Int \"Int\";\nimport Iter \"Iter\";\nimport Prim \"mo:⛔\";\nimport Order \"Order\";\n\nmodule {\n\n /// 16-bit signed integers.\n public type Int16 = Prim.Types.Int16;\n\n /// Minimum 16-bit integer value, `-2 ** 15`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.minValue == (-32_768 : Int16);\n /// ```\n public let minValue : Int16 = -32_768;\n\n /// Maximum 16-bit integer value, `+2 ** 15 - 1`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.maxValue == (+32_767 : Int16);\n /// ```\n public let maxValue : Int16 = 32_767;\n\n /// Converts a 16-bit signed integer to a signed integer with infinite precision.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toInt(12_345) == (12_345 : Int);\n /// ```\n public let toInt : (self : Int16) -> Int = Prim.int16ToInt;\n\n /// Converts a signed integer with infinite precision to a 16-bit signed integer.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromInt(12_345) == (+12_345 : Int16);\n /// ```\n public let fromInt : Int -> Int16 = Prim.intToInt16;\n\n /// Converts a signed integer with infinite precision to a 16-bit signed integer.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromIntWrap(-12_345) == (-12_345 : Int);\n /// ```\n public let fromIntWrap : Int -> Int16 = Prim.intToInt16Wrap;\n\n /// Converts a 8-bit signed integer to a 16-bit signed integer.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromInt8(-123) == (-123 : Int16);\n /// ```\n public let fromInt8 : Int8 -> Int16 = Prim.int8ToInt16;\n\n /// Converts a 16-bit signed integer to a 8-bit signed integer.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toInt8(-123) == (-123 : Int8);\n /// ```\n public let toInt8 : (self : Int16) -> Int8 = Prim.int16ToInt8;\n\n /// Converts a 32-bit signed integer to a 16-bit signed integer.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromInt32(-12_345) == (-12_345 : Int16);\n /// ```\n public let fromInt32 : Int32 -> Int16 = Prim.int32ToInt16;\n\n /// Converts a 16-bit signed integer to a 32-bit signed integer.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toInt32(-12_345) == (-12_345 : Int32);\n /// ```\n public let toInt32 : (self : Int16) -> Int32 = Prim.int16ToInt32;\n\n /// Converts a 64-bit signed integer to a 16-bit signed integer.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromInt64(-12_345) == (-12_345 : Int16);\n /// ```\n public func fromInt64(x : Int64) : Int16 {\n Prim.int32ToInt16(Prim.int64ToInt32(x))\n };\n\n /// Converts a 16-bit signed integer to a 64-bit signed integer.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toInt64(-12_345) == (-12_345 : Int64);\n /// ```\n public func toInt64(self : Int16) : Int64 {\n Prim.int32ToInt64(Prim.int16ToInt32(self))\n };\n\n /// Converts an unsigned 16-bit integer to a signed 16-bit integer.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.fromNat16(12_345) == (+12_345 : Int16);\n /// ```\n public let fromNat16 : Nat16 -> Int16 = Prim.nat16ToInt16;\n\n /// Converts a signed 16-bit integer to an unsigned 16-bit integer.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toNat16(-1) == (65_535 : Nat16); // underflow\n /// ```\n public let toNat16 : (self : Int16) -> Nat16 = Prim.int16ToNat16;\n\n /// Returns the Text representation of `x`. Textual representation _do not_\n /// contain underscores to represent commas.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.toText(-12345) == \"-12345\";\n /// ```\n public func toText(self : Int16) : Text {\n Int.toText(toInt(self))\n };\n\n /// Returns the absolute value of `x`.\n ///\n /// Traps when `x == -2 ** 15` (the minimum `Int16` value).\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.abs(-12345) == +12_345;\n /// ```\n public func abs(x : Int16) : Int16 {\n fromInt(Int.abs(toInt(x)))\n };\n\n /// Returns the minimum of `x` and `y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.min(+2, -3) == -3;\n /// ```\n public func min(x : Int16, y : Int16) : Int16 {\n if (x < y) { x } else { y }\n };\n\n /// Returns the maximum of `x` and `y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.max(+2, -3) == +2;\n /// ```\n public func max(x : Int16, y : Int16) : Int16 {\n if (x < y) { y } else { x }\n };\n\n /// Equality function for Int16 types.\n /// This is equivalent to `x == y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.equal(-1, -1);\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `==` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `==`\n /// as a function value at the moment.\n ///\n /// Example:\n /// ```motoko include=import\n /// let a : Int16 = -123;\n /// let b : Int16 = 123;\n /// assert not Int16.equal(a, b);\n /// ```\n public func equal(x : Int16, y : Int16) : Bool { x == y };\n\n /// Inequality function for Int16 types.\n /// This is equivalent to `x != y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.notEqual(-1, -2);\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `!=` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `!=`\n /// as a function value at the moment.\n public func notEqual(x : Int16, y : Int16) : Bool { x != y };\n\n /// \"Less than\" function for Int16 types.\n /// This is equivalent to `x < y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.less(-2, 1);\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `<` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `<`\n /// as a function value at the moment.\n public func less(x : Int16, y : Int16) : Bool { x < y };\n\n /// \"Less than or equal\" function for Int16 types.\n /// This is equivalent to `x <= y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.lessOrEqual(-2, -2);\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `<=` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `<=`\n /// as a function value at the moment.\n public func lessOrEqual(x : Int16, y : Int16) : Bool { x <= y };\n\n /// \"Greater than\" function for Int16 types.\n /// This is equivalent to `x > y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert not Int16.greater(-2, 1);\n /// ```\n public func greater(x : Int16, y : Int16) : Bool { x > y };\n\n /// \"Greater than or equal\" function for Int16 types.\n /// This is equivalent to `x >= y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.greaterOrEqual(-2, -2);\n /// ```\n public func greaterOrEqual(x : Int16, y : Int16) : Bool {\n x >= y\n };\n\n /// General-purpose comparison function for `Int16`. Returns the `Order` (\n /// either `#less`, `#equal`, or `#greater`) of comparing `x` with `y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.compare(-3, 2) == #less;\n /// ```\n ///\n /// This function can be used as value for a high order function, such as a sort function.\n ///\n /// Example:\n /// ```motoko include=import\n /// import Array \"mo:core/Array\";\n /// assert Array.sort([1, -2, -3] : [Int16], Int16.compare) == [-3, -2, 1];\n /// ```\n public func compare(x : Int16, y : Int16) : Order.Order {\n if (x < y) { #less } else if (x == y) { #equal } else {\n #greater\n }\n };\n\n /// Returns the negation of `x`, `-x`.\n ///\n /// Traps on overflow, i.e. for `neg(-2 ** 15)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.neg(123) == -123;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `-` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `-`\n /// as a function value at the moment.\n public func neg(x : Int16) : Int16 { -x };\n\n /// Returns the sum of `x` and `y`, `x + y`.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.add(100, 23) == +123;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `+` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `+`\n /// as a function value at the moment.\n ///\n /// Example:\n /// ```motoko include=import\n /// import Array \"mo:core/Array\";\n /// assert Array.foldLeft<Int16, Int16>([1, -2, -3], 0, Int16.add) == -4;\n /// ```\n public func add(x : Int16, y : Int16) : Int16 { x + y };\n\n /// Returns the difference of `x` and `y`, `x - y`.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.sub(123, 100) == +23;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `-` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `-`\n /// as a function value at the moment.\n ///\n /// Example:\n /// ```motoko include=import\n /// import Array \"mo:core/Array\";\n /// assert Array.foldLeft<Int16, Int16>([1, -2, -3], 0, Int16.sub) == 4;\n /// ```\n public func sub(x : Int16, y : Int16) : Int16 { x - y };\n\n /// Returns the product of `x` and `y`, `x * y`.\n ///\n /// Traps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.mul(12, 10) == +120;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `*` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `*`\n /// as a function value at the moment.\n ///\n /// Example:\n /// ```motoko include=import\n /// import Array \"mo:core/Array\";\n /// assert Array.foldLeft<Int16, Int16>([1, -2, -3], 1, Int16.mul) == 6;\n /// ```\n public func mul(x : Int16, y : Int16) : Int16 { x * y };\n\n /// Returns the signed integer division of `x` by `y`, `x / y`.\n /// Rounds the quotient towards zero, which is the same as truncating the decimal places of the quotient.\n ///\n /// Traps when `y` is zero.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.div(123, 10) == +12;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `/` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `/`\n /// as a function value at the moment.\n public func div(x : Int16, y : Int16) : Int16 { x / y };\n\n /// Returns the remainder of the signed integer division of `x` by `y`, `x % y`,\n /// which is defined as `x - x / y * y`.\n ///\n /// Traps when `y` is zero.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.rem(123, 10) == +3;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `%` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `%`\n /// as a function value at the moment.\n public func rem(x : Int16, y : Int16) : Int16 { x % y };\n\n /// Returns `x` to the power of `y`, `x ** y`.\n ///\n /// Traps on overflow/underflow and when `y < 0 or y >= 16`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.pow(2, 10) == +1_024;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `**` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `**`\n /// as a function value at the moment.\n public func pow(x : Int16, y : Int16) : Int16 { x ** y };\n\n /// Returns the bitwise negation of `x`, `^x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitnot(-256 /* 0xff00 */) == +255 // 0xff;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `^` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `^`\n /// as a function value at the moment.\n public func bitnot(x : Int16) : Int16 { ^x };\n\n /// Returns the bitwise \"and\" of `x` and `y`, `x & y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitand(0x0fff, 0x00f0) == +240 // 0xf0;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `&` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `&`\n /// as a function value at the moment.\n public func bitand(x : Int16, y : Int16) : Int16 { x & y };\n\n /// Returns the bitwise \"or\" of `x` and `y`, `x | y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitor(0x0f0f, 0x00f0) == +4_095 // 0x0fff;\n /// ```\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `|` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `|`\n /// as a function value at the moment.\n public func bitor(x : Int16, y : Int16) : Int16 { x | y };\n\n /// Returns the bitwise \"exclusive or\" of `x` and `y`, `x ^ y`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitxor(0x0fff, 0x00f0) == +3_855 // 0x0f0f;\n /// ```\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `^` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `^`\n /// as a function value at the moment.\n public func bitxor(x : Int16, y : Int16) : Int16 { x ^ y };\n\n /// Returns the bitwise left shift of `x` by `y`, `x << y`.\n /// The right bits of the shift filled with zeros.\n /// Left-overflowing bits, including the sign bit, are discarded.\n ///\n /// For `y >= 16`, the semantics is the same as for `bitshiftLeft(x, y % 16)`.\n /// For `y < 0`, the semantics is the same as for `bitshiftLeft(x, y + y % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitshiftLeft(1, 8) == +256 // 0x100 equivalent to `2 ** 8`.;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `<<` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `<<`\n /// as a function value at the moment.\n public func bitshiftLeft(x : Int16, y : Int16) : Int16 {\n x << y\n };\n\n /// Returns the signed bitwise right shift of `x` by `y`, `x >> y`.\n /// The sign bit is retained and the left side is filled with the sign bit.\n /// Right-underflowing bits are discarded, i.e. not rotated to the left side.\n ///\n /// For `y >= 16`, the semantics is the same as for `bitshiftRight(x, y % 16)`.\n /// For `y < 0`, the semantics is the same as for `bitshiftRight (x, y + y % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitshiftRight(1024, 8) == +4 // equivalent to `1024 / (2 ** 8)`;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `>>` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `>>`\n /// as a function value at the moment.\n public func bitshiftRight(x : Int16, y : Int16) : Int16 {\n x >> y\n };\n\n /// Returns the bitwise left rotatation of `x` by `y`, `x <<> y`.\n /// Each left-overflowing bit is inserted again on the right side.\n /// The sign bit is rotated like y bits, i.e. the rotation interprets the number as unsigned.\n ///\n /// Changes the direction of rotation for negative `y`.\n /// For `y >= 16`, the semantics is the same as for `bitrotLeft(x, y % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitrotLeft(0x2001, 4) == +18 // 0x12.;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `<<>` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `<<>`\n /// as a function value at the moment.\n public func bitrotLeft(x : Int16, y : Int16) : Int16 { x <<> y };\n\n /// Returns the bitwise right rotation of `x` by `y`, `x <>> y`.\n /// Each right-underflowing bit is inserted again on the right side.\n /// The sign bit is rotated like y bits, i.e. the rotation interprets the number as unsigned.\n ///\n /// Changes the direction of rotation for negative `y`.\n /// For `y >= 16`, the semantics is the same as for `bitrotRight(x, y % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitrotRight(0x2010, 8) == +4_128 // 0x01020.;\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `<>>` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `<>>`\n /// as a function value at the moment.\n public func bitrotRight(x : Int16, y : Int16) : Int16 {\n x <>> y\n };\n\n /// Returns the value of bit `p` in `x`, `x & 2**p == 2**p`.\n /// If `p >= 16`, the semantics is the same as for `bittest(x, p % 16)`.\n /// This is equivalent to checking if the `p`-th bit is set in `x`, using 0 indexing.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bittest(128, 7);\n /// ```\n public func bittest(x : Int16, p : Nat) : Bool {\n Prim.btstInt16(x, Prim.intToInt16(p))\n };\n\n /// Returns the value of setting bit `p` in `x` to `1`.\n /// If `p >= 16`, the semantics is the same as for `bitset(x, p % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitset(0, 7) == +128;\n /// ```\n public func bitset(x : Int16, p : Nat) : Int16 {\n x | (1 << Prim.intToInt16(p))\n };\n\n /// Returns the value of clearing bit `p` in `x` to `0`.\n /// If `p >= 16`, the semantics is the same as for `bitclear(x, p % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitclear(-1, 7) == -129;\n /// ```\n public func bitclear(x : Int16, p : Nat) : Int16 {\n x & ^(1 << Prim.intToInt16(p))\n };\n\n /// Returns the value of flipping bit `p` in `x`.\n /// If `p >= 16`, the semantics is the same as for `bitclear(x, p % 16)`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitflip(255, 7) == +127;\n /// ```\n public func bitflip(x : Int16, p : Nat) : Int16 {\n x ^ (1 << Prim.intToInt16(p))\n };\n\n /// Returns the count of non-zero bits in `x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitcountNonZero(0xff) == +8;\n /// ```\n public let bitcountNonZero : (x : Int16) -> Int16 = Prim.popcntInt16;\n\n /// Returns the count of leading zero bits in `x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitcountLeadingZero(0x80) == +8;\n /// ```\n public let bitcountLeadingZero : (x : Int16) -> Int16 = Prim.clzInt16;\n\n /// Returns the count of trailing zero bits in `x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.bitcountTrailingZero(0x0100) == +8;\n /// ```\n public let bitcountTrailingZero : (x : Int16) -> Int16 = Prim.ctzInt16;\n\n /// Returns the upper (i.e. most significant) and lower (least significant) byte of `x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.explode 0x77ee == (119, 238);\n /// ```\n public let explode : (x : Int16) -> (msb : Nat8, lsb : Nat8) = Prim.explodeInt16;\n\n /// Returns the sum of `x` and `y`, `x +% y`.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.addWrap(2 ** 14, 2 ** 14) == -32_768; // overflow\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `+%` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `+%`\n /// as a function value at the moment.\n public func addWrap(x : Int16, y : Int16) : Int16 { x +% y };\n\n /// Returns the difference of `x` and `y`, `x -% y`.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.subWrap(-2 ** 15, 1) == +32_767; // underflow\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `-%` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `-%`\n /// as a function value at the moment.\n public func subWrap(x : Int16, y : Int16) : Int16 { x -% y };\n\n /// Returns the product of `x` and `y`, `x *% y`. Wraps on overflow.\n ///\n /// Wraps on overflow/underflow.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Int16.mulWrap(2 ** 8, 2 ** 8) == 0; // overflow\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `*%` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `*%`\n /// as a function value at the moment.\n public func mulWrap(x : Int16, y : Int16) : Int16 { x *% y };\n\n /// Returns `x` to the power of `y`, `x **% y`.\n ///\n /// Wraps on overflow/underflow.\n /// Traps if `y < 0 or y >= 16`.\n ///\n /// Example:\n /// ```motoko include=import\n ///\n /// assert Int16.powWrap(2, 15) == -32_768; // overflow\n /// ```\n ///\n /// Note: The reason why this function is defined in this library (in addition\n /// to the existing `**%` operator) is so that you can use it as a function\n /// value to pass to a higher order function. It is not possible to use `**%`\n /// as a function value at the moment.\n public func powWrap(x : Int16, y : Int16) : Int16 { x **% y };\n\n /// Returns an iterator over `Int16` values from the first to second argument with an exclusive upper bound.\n /// ```motoko include=import\n /// import Iter \"mo:core/Iter\";\n ///\n /// let iter = Int16.range(1, 4);\n /// assert iter.next() == ?1;\n /// assert iter.next() == ?2;\n /// assert iter.next() == ?3;\n /// assert iter.next() == null;\n /// ```\n ///\n /// If the first argument is greater than the second argument, the function returns an empty iterator.\n /// ```motoko include=import\n /// import Iter \"mo:core/Iter\";\n ///\n /// let iter = Int16.range(4, 1);\n /// assert iter.next() == null; // empty iterator\n /// ```\n public func range(fromInclusive : Int16, toExclusive : Int16) : Iter.Iter<Int16> {\n if (fromInclusive >= toExclusive) {\n Iter.empty()\n } else {\n object {\n var n = fromInclusive;\n public func next() : ?Int16 {\n if (n == toExclusive) {\n null\n } else {\n let result = n;\n n += 1;\n ?result\n }\n }\n }\n }\n };\n\n /// Returns an iterator over `Int16` values from the first to second argument, inclusive.\n /// ```motoko include=import\n /// import Iter \"mo:core/Iter\";\n ///\n /// let iter = Int16.rangeInclusive(1, 3);\n /// assert iter.next() == ?1;\n /// assert iter.next() == ?2;\n /// assert iter.next() == ?3;\n /// assert iter.next() == null;\n /// ```\n ///\n /// If the first argument is greater than the second argument, the function returns an empty iterator.\n /// ```motoko include=import\n /// import Iter \"mo:core/Iter\";\n ///\n /// let iter = Int16.rangeInclusive(4, 1);\n /// assert iter.next() == null; // empty iterator\n /// ```\n public func rangeInclusive(from : Int16, to : Int16) : Iter.Iter<Int16> {\n if (from > to) {\n Iter.empty()\n } else {\n object {\n var n = from;\n var done = false;\n public func next() : ?Int16 {\n if (done) {\n null\n } else {\n let result = n;\n if (n == to) {\n done := true\n } else {\n n += 1\n };\n ?result\n }\n }\n }\n }\n };\n\n /// Returns an iterator over all Int16 values, from minValue to maxValue.\n /// ```motoko include=import\n /// import Iter \"mo:core/Iter\";\n ///\n /// let iter = Int16.allValues();\n /// assert iter.next() == ?-32_768;\n /// assert iter.next() == ?-32_767;\n /// assert iter.next() == ?-32_766;\n /// // ...\n /// ```\n public func allValues() : Iter.Iter<Int16> {\n rangeInclusive(minValue, maxValue)\n };\n\n}\n"},"CallerAttributes.mo":{"content":"/// Allows accessing the Internet Computer's caller attributes.\n/// TODO: link to official documentation, once it's available.\n///\n/// ```motoko name=import\n/// import CallerAttributes \"mo:core/CallerAttributes\";\n/// ```\n\nimport Prim \"mo:⛔\";\nimport Text \"Text\";\nimport Iter \"Iter\";\nimport Runtime \"Runtime\";\nimport Principal \"Principal\";\n\nmodule {\n /// Returns the attribute data attached to the current call, but only\n /// when the signer is listed in the `trusted_attribute_signers`\n /// canister environment variable.\n ///\n /// Returns `null` if the current call carries no caller attributes.\n /// Traps if the signer isn't trusted.\n ///\n /// `trusted_attribute_signers` is expected to be a comma-separated list\n /// of principal texts, for example:\n /// `\"aaaaa-aa,un4fu-tqaaa-aaaab-qadjq-cai\"`.\n ///\n /// Example:\n /// ```motoko include=import no-validate\n /// persistent actor {\n /// public shared func handle() : async () {\n /// switch (CallerAttributes.getAttributes()) {\n /// case (?data) { /* attributes came from a trusted signer */ };\n /// case null { /* no attributes, or signer is not trusted */ };\n /// };\n /// };\n /// }\n /// ```\n public func getAttributes<system>() : ?Blob {\n let signerBlob : Blob = Prim.callerInfoSigner<system>();\n // An empty signer means no attributes where sent in this call.\n if (signerBlob.size() == 0) {\n return null\n };\n let signer = Principal.fromBlob(signerBlob);\n let ?trustedSigners = Runtime.envVar<system>(\"trusted_attribute_signers\") else {\n Runtime.trap(\"trusted_attribute_signers environment variable is not set\")\n };\n if (trustedSigners.split(#char(',')).any(func(t) { Principal.fromText(t) == signer })) {\n return ?Prim.callerInfoData<system>()\n };\n Runtime.trap(\"untrusted attribute signer\")\n }\n}\n"},"Func.mo":{"content":"/// Functions on functions, creating functions from simpler inputs.\n///\n/// (Most commonly used when programming in functional style using higher-order\n/// functions.)\n///\n/// Import from the core package to use this module.\n///\n/// ```motoko name=import\n/// import Func = \"mo:core/Func\";\n/// ```\n\nmodule {\n\n /// The composition of two functions `f` and `g` is a function that applies `g` and then `f`.\n ///\n /// Example:\n /// ```motoko include=import\n /// import Text \"mo:core/Text\";\n /// import Char \"mo:core/Char\";\n ///\n /// let textFromNat32 = Func.compose(Text.fromChar, Char.fromNat32);\n /// assert textFromNat32(65) == \"A\";\n /// ```\n public func compose<A, B, C>(f : B -> C, g : A -> B) : A -> C {\n func(x : A) : C {\n f(g(x))\n }\n };\n\n /// The `identity` function returns its argument.\n /// Example:\n /// ```motoko include=import\n /// assert Func.identity(10) == 10;\n /// assert Func.identity(true) == true;\n /// ```\n public func identity<A>(x : A) : A = x;\n\n /// The const function is a _curried_ function that accepts an argument `x`,\n /// and then returns a function that discards its argument and always returns\n /// the `x`.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Func.const<Nat, Text>(10)(\"hello\") == 10;\n /// assert Func.const(true)(20) == true;\n /// ```\n public func const<A, B>(x : A) : B -> A = func _ = x\n}\n"},"Float32.mo":{"content":"/// Single precision (32-bit) floating-point numbers in IEEE 754 representation.\n///\n/// This module contains common floating-point constants and utility functions.\n///\n/// ```motoko name=import\n/// import Float32 \"mo:core/Float32\";\n/// ```\n///\n/// Notation for special values in the documentation below:\n/// `+inf`: Positive infinity\n/// `-inf`: Negative infinity\n/// `NaN`: \"not a number\" (can have different sign bit values, but `NaN != NaN` regardless of the sign).\n///\n/// Note:\n/// Floating point numbers have limited precision and operations may inherently result in numerical errors.\n/// `Float32` has less precision than `Float` (64-bit); only about 7 significant decimal digits.\n///\n/// Examples of numerical errors:\n/// ```motoko\n/// assert 0.1 + 0.1 + 0.1 != 0.3;\n/// ```\n///\n/// Advice:\n/// * Floating point number comparisons by `==` or `!=` are discouraged. Instead, it is better to compare\n/// floating-point numbers with a numerical tolerance, called epsilon.\n///\n/// Example:\n/// ```motoko\n/// import Float32 \"mo:core/Float32\";\n/// let x = 0.1 + 0.1 + 0.1 : Float32;\n/// let y = 0.3 : Float32;\n///\n/// let epsilon = 1e-5 : Float32; // This depends on the application case (needs a numerical error analysis).\n/// assert Float32.equal(x, y, epsilon);\n/// ```\n///\n/// * For absolute precision, it is recommended to encode the fraction number as a pair of a Nat for the base\n/// and a Nat for the exponent (decimal point).\n///\n/// Note: As of `moc` 1.4, `Float32` support is experimental.\n///\n/// NaN sign:\n/// * The NaN sign is only applied by `abs`, `neg`, and `copySign`. Other operations can have an arbitrary\n/// sign bit for NaN results.\n\nimport Prim \"mo:⛔\";\nimport Order \"Order\";\n\nmodule {\n\n /// 32-bit floating point number type.\n public type Float32 = Prim.Types.Float32;\n\n /// Conversion to Float (64-bit double precision).\n ///\n /// This is a lossless widening conversion.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.toFloat(1.5) == 1.5;\n /// ```\n public let toFloat : (self : Float32) -> Float = Prim.float32ToFloat;\n\n /// Conversion from Float (64-bit double precision) to Float32.\n ///\n /// Note: This may lose precision for values that are not exactly representable in 32-bit.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.fromFloat(1.5) == 1.5;\n /// ```\n public let fromFloat : (x : Float) -> Float32 = Prim.floatToFloat32;\n\n /// Ratio of the circumference of a circle to its diameter.\n /// Note: Limited precision (approximately 7 significant decimal digits).\n public let pi : Float32 = 3.14159265358979323846;\n\n /// Base of the natural logarithm.\n /// Note: Limited precision (approximately 7 significant decimal digits).\n public let e : Float32 = 2.7182818284590452354;\n\n /// Determines whether the `number` is a `NaN` (\"not a number\" in the floating point representation).\n /// Notes:\n /// * Equality test of `NaN` with itself or another number is always `false`.\n /// * There exist many internal `NaN` value representations, such as positive and negative NaN,\n /// signalling and quiet NaNs, each with many different bit representations.\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.isNaN(0.0/0.0);\n /// ```\n public func isNaN(self : Float32) : Bool {\n self != self\n };\n\n /// Returns the absolute value of `x`.\n ///\n /// Special cases:\n /// ```\n /// abs(+inf) => +inf\n /// abs(-inf) => +inf\n /// abs(-NaN) => +NaN\n /// abs(-0.0) => 0.0\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.abs(-1.2), 1.2, epsilon);\n /// ```\n public func abs(x : Float32) : Float32 {\n fromFloat(Prim.floatAbs(toFloat(x)))\n };\n\n /// Returns the square root of `x`.\n ///\n /// Special cases:\n /// ```\n /// sqrt(+inf) => +inf\n /// sqrt(-0.0) => -0.0\n /// sqrt(x) => NaN if x < 0.0\n /// sqrt(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.sqrt(6.25), 2.5, epsilon);\n /// ```\n public func sqrt(x : Float32) : Float32 {\n fromFloat(Prim.floatSqrt(toFloat(x)))\n };\n\n /// Returns the smallest integral float greater than or equal to `x`.\n ///\n /// Special cases:\n /// ```\n /// ceil(+inf) => +inf\n /// ceil(-inf) => -inf\n /// ceil(NaN) => NaN\n /// ceil(0.0) => 0.0\n /// ceil(-0.0) => -0.0\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.ceil(1.2), 2.0, epsilon);\n /// ```\n public func ceil(x : Float32) : Float32 {\n fromFloat(Prim.floatCeil(toFloat(x)))\n };\n\n /// Returns the largest integral float less than or equal to `x`.\n ///\n /// Special cases:\n /// ```\n /// floor(+inf) => +inf\n /// floor(-inf) => -inf\n /// floor(NaN) => NaN\n /// floor(0.0) => 0.0\n /// floor(-0.0) => -0.0\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.floor(1.2), 1.0, epsilon);\n /// ```\n public func floor(x : Float32) : Float32 {\n fromFloat(Prim.floatFloor(toFloat(x)))\n };\n\n /// Returns the nearest integral float not greater in magnitude than `x`.\n /// This is equivalent to returning `x` with truncating its decimal places.\n ///\n /// Special cases:\n /// ```\n /// trunc(+inf) => +inf\n /// trunc(-inf) => -inf\n /// trunc(NaN) => NaN\n /// trunc(0.0) => 0.0\n /// trunc(-0.0) => -0.0\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.trunc(2.75), 2.0, epsilon);\n /// ```\n public func trunc(x : Float32) : Float32 {\n fromFloat(Prim.floatTrunc(toFloat(x)))\n };\n\n /// Returns the nearest integral float to `x`.\n /// A decimal place of exactly .5 is rounded to the nearest even integral float.\n ///\n /// Special cases:\n /// ```\n /// nearest(+inf) => +inf\n /// nearest(-inf) => -inf\n /// nearest(NaN) => NaN\n /// nearest(0.0) => 0.0\n /// nearest(-0.0) => -0.0\n /// nearest(14.5) => 14.0\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.nearest(2.75) == 3.0\n /// ```\n public func nearest(x : Float32) : Float32 {\n fromFloat(Prim.floatNearest(toFloat(x)))\n };\n\n /// Returns `x` if `x` and `y` have same sign, otherwise `x` with negated sign.\n ///\n /// The sign bit of zero, infinity, and `NaN` is considered.\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.copySign(1.2, -2.3), -1.2, epsilon);\n /// ```\n public func copySign(x : Float32, y : Float32) : Float32 {\n fromFloat(Prim.floatCopySign(toFloat(x), toFloat(y)))\n };\n\n /// Returns the smaller value of `x` and `y`.\n ///\n /// Special cases:\n /// ```\n /// min(NaN, y) => NaN for any Float32 y\n /// min(x, NaN) => NaN for any Float32 x\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.min(1.2, -2.3) == -2.3; // with numerical imprecision\n /// ```\n public func min(x : Float32, y : Float32) : Float32 {\n fromFloat(Prim.floatMin(toFloat(x), toFloat(y)))\n };\n\n /// Returns the larger value of `x` and `y`.\n ///\n /// Special cases:\n /// ```\n /// max(NaN, y) => NaN for any Float32 y\n /// max(x, NaN) => NaN for any Float32 x\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// assert Float32.max(1.2, -2.3) == 1.2;\n /// ```\n public func max(x : Float32, y : Float32) : Float32 {\n fromFloat(Prim.floatMax(toFloat(x), toFloat(y)))\n };\n\n /// Returns the sine of the radian angle `x`.\n ///\n /// Special cases:\n /// ```\n /// sin(+inf) => NaN\n /// sin(-inf) => NaN\n /// sin(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.sin(Float32.pi / 2.0), 1.0, epsilon);\n /// ```\n public func sin(x : Float32) : Float32 {\n fromFloat(Prim.sin(toFloat(x)))\n };\n\n /// Returns the cosine of the radian angle `x`.\n ///\n /// Special cases:\n /// ```\n /// cos(+inf) => NaN\n /// cos(-inf) => NaN\n /// cos(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.cos(Float32.pi / 2.0), 0.0, epsilon);\n /// ```\n public func cos(x : Float32) : Float32 {\n fromFloat(Prim.cos(toFloat(x)))\n };\n\n /// Returns the tangent of the radian angle `x`.\n ///\n /// Special cases:\n /// ```\n /// tan(+inf) => NaN\n /// tan(-inf) => NaN\n /// tan(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.tan(Float32.pi / 4.0), 1.0, epsilon);\n /// ```\n public func tan(x : Float32) : Float32 {\n fromFloat(Prim.tan(toFloat(x)))\n };\n\n /// Returns the arc sine of `x` in radians.\n ///\n /// Special cases:\n /// ```\n /// arcsin(x) => NaN if x > 1.0\n /// arcsin(x) => NaN if x < -1.0\n /// arcsin(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.arcsin(1.0), Float32.pi / 2.0, epsilon);\n /// ```\n public func arcsin(x : Float32) : Float32 {\n fromFloat(Prim.arcsin(toFloat(x)))\n };\n\n /// Returns the arc cosine of `x` in radians.\n ///\n /// Special cases:\n /// ```\n /// arccos(x) => NaN if x > 1.0\n /// arccos(x) => NaN if x < -1.0\n /// arccos(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.arccos(1.0), 0.0, epsilon);\n /// ```\n public func arccos(x : Float32) : Float32 {\n fromFloat(Prim.arccos(toFloat(x)))\n };\n\n /// Returns the arc tangent of `x` in radians.\n ///\n /// Special cases:\n /// ```\n /// arctan(+inf) => pi / 2\n /// arctan(-inf) => -pi / 2\n /// arctan(NaN) => NaN\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let epsilon = 1e-5 : Float32;\n /// assert Float32.equal(Float32.arctan(1.0), Float32.pi / 4.0, epsilon);\n /// ```\n public func arctan(x : Float32) : Float32 {\n fromFloat(Prim.arctan(toFloat(x)))\n };\n\n /// Given `(y, x)`, returns the arc tangent in radians of `y/x` based on the signs of both values to determine the correct quadrant.\n ///\n /// Special cases:\n /// ```\n /// arctan2(0.0, 0.0) => 0.0\n /// arctan2(-0.0, 0.0) => -0.0\n /// arctan2(0.0, -0.0) => pi\n /// arctan2(-0.0, -0.0) => -pi\n /// arctan2(+inf, +inf) => pi / 4\n /// arctan2(+inf, -inf) => 3 * pi / 4\n /// arctan2(-inf, +inf) => -pi / 4\n /// arctan2(-inf, -inf) => -3 * pi / 4\n /// arctan2(NaN, x) => NaN for any Float32 x\n /// arctan2(y, NaN) => NaN for any Float32 y\n /// ```\n ///\n /// Example:\n /// ```motoko include=import\n /// let sqrt2over2 = Float32.sqrt(2.0) / 2.0;\n /// assert Float32.a