1///|
2test "output" {
3  
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
type Color UInt

RGBA color

Color
::
(x : UInt) -> Color
new
(0x00_00_00_00),
String
content
="00000000")
4
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
type Color UInt

RGBA color

Color
::
(x : UInt) -> Color
new
(0xFF_00_00_00),
String
content
="FF000000")
5
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
type Color UInt

RGBA color

Color
::
(x : UInt) -> Color
new
(0xFF_FF_00_00),
String
content
="FFFF0000")
6
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
type Color UInt

RGBA color

Color
::
(x : UInt) -> Color
new
(0xFF_FF_FF_00),
String
content
="FFFFFF00")
7} 8 9///| 10test "hsl/rgb" { 11 let
Color
hsl_red
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(0, 100, 50)
12 let
Color
rgb_red
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(255, 0, 0)
13
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_red
,
Color
rgb_red
)
14 let
Color
hsl_blue
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(240, 100, 50)
15 let
Color
rgb_blue
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 0, 255)
16
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_blue
,
Color
rgb_blue
)
17 let
Color
hsl_green
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(120, 100, 50)
18 let
Color
rgb_green
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 255, 0)
19
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_green
,
Color
rgb_green
)
20 let
Color
hsl_white
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(0, 0, 100)
21 let
Color
rgb_white
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(255, 255, 255)
22
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_white
,
Color
rgb_white
)
23 let
Color
hsl_black
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(0, 0, 0)
24 let
Color
rgb_black
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 0, 0)
25
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_black
,
Color
rgb_black
)
26 let
Color
hsl_purple
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(300, 100, 25)
27 let
Color
rgb_purple
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(128, 0, 128)
28
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
hsl_purple
,
Color
rgb_purple
)
29} 30 31///| 32test "to_hsl" { 33 let
Color
red
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(255, 0, 0)
34
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
red
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 0, saturation: 100, lightness: 50}")
35
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
red
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
red
)
36 let
Color
green
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 255, 0)
37
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
green
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 120, saturation: 100, lightness: 50}")
38
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
green
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
green
)
39 let
Color
blue
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 0, 255)
40
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
blue
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 240, saturation: 100, lightness: 50}")
41
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
blue
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
blue
)
42 let
Color
white
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(255, 255, 255)
43
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
white
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 0, saturation: 0, lightness: 100}")
44
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
white
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
white
)
45 let
Color
black
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(0, 0, 0)
46
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
black
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 0, saturation: 0, lightness: 0}")
47
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
black
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
black
)
48 let
Color
color
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(128, 0, 128)
49
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
Color
color
.
(self : Color) -> HSL
to_hsl
(),
String
content
="{hue: 300, saturation: 100, lightness: 25}")
50
(a : Color, b : Color, loc~ : SourceLoc = _) -> Unit!Error

Asserts that two values are equal. If they are not equal, raises a failure with a message containing the source location and the values being compared.

Parameters:

  • a : First value to compare.
  • b : Second value to compare.
  • loc : Source location information to include in failure messages. This is usually automatically provided by the compiler.

Throws a Failure error if the values are not equal, with a message showing the location of the failing assertion and the actual values that were compared.

Example:

test "assert_eq" {
  assert_eq(1, 1)
  assert_eq("hello", "hello")
}

test "panic assert_eq/not_equal" {
  ignore(assert_eq(1, 2)) // Will fail with message showing values and location
}
assert_eq
!(
Color
color
.
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
(),
Color
color
)
51} 52 53///| 54test "hsl/rgb convert error=5" { 55 fn
(Byte) -> Double
b2d
(
Byte
x
:
Byte
Byte
) ->
Double
Double
{
56
Byte
x
.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
().
(self : Int) -> Double

Converts a 32-bit integer to a double-precision floating-point number. The conversion preserves the exact value since all integers in the range of Int can be represented exactly as Double values.

Parameters:

  • self : The 32-bit integer to be converted.

Returns a double-precision floating-point number that represents the same numerical value as the input integer.

Example:

test "Int::to_double" {
  let n = 42
  inspect(n.to_double(), content="42")
  let neg = -42
  inspect(neg.to_double(), content="-42")
}
to_double
()
57 } 58 59 for
UInt
h
in
UInt
0U
..<12 {
60 for
Int
s
= 4;
Int
s
(self_ : Int, other : Int) -> Bool
>=
1;
Int
s
=
Int
s
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
1 {
61 for
Int
l
= 8;
Int
l
(self_ : Int, other : Int) -> Bool
>=
0;
Int
l
=
Int
l
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
1 {
62 let
UInt
h
=
UInt
h
(self : UInt, other : UInt) -> UInt

Performs multiplication between two unsigned 32-bit integers. The result wraps around if it exceeds the maximum value of UInt.

Parameters:

  • self : The first unsigned integer operand.
  • other : The second unsigned integer operand.

Returns the product of the two unsigned integers. If the result exceeds the maximum value of UInt (4294967295), it wraps around to the corresponding value modulo 2^32.

Example:

test "UInt::op_mul" {
  let a = 3U
  let b = 4U
  inspect(a * b, content="12")
  let max = 4294967295U
  inspect(max * 2U, content="4294967294") // Wraps around to max * 2 % 2^32
}
*
30
63 let
UInt
s
= (
Int
s
.
(self : Int) -> Double

Converts a 32-bit integer to a double-precision floating-point number. The conversion preserves the exact value since all integers in the range of Int can be represented exactly as Double values.

Parameters:

  • self : The 32-bit integer to be converted.

Returns a double-precision floating-point number that represents the same numerical value as the input integer.

Example:

test "Int::to_double" {
  let n = 42
  inspect(n.to_double(), content="42")
  let neg = -42
  inspect(neg.to_double(), content="-42")
}
to_double
()
(self : Double, other : Double) -> Double

Performs division between two double-precision floating-point numbers. Follows IEEE 754 standard for floating-point arithmetic, including handling of special cases like division by zero (returns infinity) and operations involving NaN.

Parameters:

  • self : The dividend (numerator) in the division operation.
  • other : The divisor (denominator) in the division operation.

Returns the result of dividing self by other. Special cases follow IEEE 754:

  • Division by zero returns positive or negative infinity based on the dividend's sign
  • Operations involving NaN return NaN
  • Division of infinity by infinity returns NaN

Example:

test "Double::op_div" {
  inspect(6.0 / 2.0, content="3")
  inspect(-6.0 / 2.0, content="-3")
  inspect(1.0 / 0.0, content="Infinity")
}
/
4
(self : Double, other : Double) -> Double

Multiplies two double-precision floating-point numbers. This is the implementation of the * operator for Double type.

Parameters:

  • self : The first double-precision floating-point operand.
  • other : The second double-precision floating-point operand.

Returns a new double-precision floating-point number representing the product of the two operands. Special cases follow IEEE 754 standard:

  • If either operand is NaN, returns NaN
  • If one operand is infinity and the other is zero, returns NaN
  • If one operand is infinity and the other is a non-zero finite number, returns infinity with the appropriate sign
  • If both operands are infinity, returns infinity with the appropriate sign

Example:

test "Double::op_mul" {
  inspect(2.5 * 2.0, content="5")
  inspect(-2.0 * 3.0, content="-6")
  let nan = 0.0 / 0.0 // NaN
  inspect(nan * 1.0, content="NaN")
}
*
100).
(self : Double) -> UInt

Converts a double-precision floating-point number to a 32-bit unsigned integer. Handles special cases including NaN and numbers outside the valid UInt range.

Parameters:

  • self : The double-precision floating-point number to be converted.

Returns an 32-bit unsigned integer value according to the following rules:

  • Returns 0 if the input is NaN
  • Returns @uint.max_value (4294967295U) if the input is greater than or equal to @uint.max_value
  • Returns @uint.min_value (0U) if the input is less than or equal to @uint.min_value
  • Otherwise returns the integer part of the input by truncating towards zero

Example:

test "Double::to_uint/normal" {
  inspect(42.0.to_uint(), content="42")
  inspect((-42.5).to_uint(), content="0")
  inspect((0.0 / 0.0).to_uint(), content="0") // NaN
  inspect((1.0 / 0.0).to_uint(), content="4294967295") // Infinity
  inspect((-1.0 / 0.0).to_uint(), content="0") // -Infinity
}
to_uint
()
64 let
UInt
l
= (
Int
l
.
(self : Int) -> Double

Converts a 32-bit integer to a double-precision floating-point number. The conversion preserves the exact value since all integers in the range of Int can be represented exactly as Double values.

Parameters:

  • self : The 32-bit integer to be converted.

Returns a double-precision floating-point number that represents the same numerical value as the input integer.

Example:

test "Int::to_double" {
  let n = 42
  inspect(n.to_double(), content="42")
  let neg = -42
  inspect(neg.to_double(), content="-42")
}
to_double
()
(self : Double, other : Double) -> Double

Performs division between two double-precision floating-point numbers. Follows IEEE 754 standard for floating-point arithmetic, including handling of special cases like division by zero (returns infinity) and operations involving NaN.

Parameters:

  • self : The dividend (numerator) in the division operation.
  • other : The divisor (denominator) in the division operation.

Returns the result of dividing self by other. Special cases follow IEEE 754:

  • Division by zero returns positive or negative infinity based on the dividend's sign
  • Operations involving NaN return NaN
  • Division of infinity by infinity returns NaN

Example:

test "Double::op_div" {
  inspect(6.0 / 2.0, content="3")
  inspect(-6.0 / 2.0, content="-3")
  inspect(1.0 / 0.0, content="Infinity")
}
/
8
(self : Double, other : Double) -> Double

Multiplies two double-precision floating-point numbers. This is the implementation of the * operator for Double type.

Parameters:

  • self : The first double-precision floating-point operand.
  • other : The second double-precision floating-point operand.

Returns a new double-precision floating-point number representing the product of the two operands. Special cases follow IEEE 754 standard:

  • If either operand is NaN, returns NaN
  • If one operand is infinity and the other is zero, returns NaN
  • If one operand is infinity and the other is a non-zero finite number, returns infinity with the appropriate sign
  • If both operands are infinity, returns infinity with the appropriate sign

Example:

test "Double::op_mul" {
  inspect(2.5 * 2.0, content="5")
  inspect(-2.0 * 3.0, content="-6")
  let nan = 0.0 / 0.0 // NaN
  inspect(nan * 1.0, content="NaN")
}
*
100).
(self : Double) -> UInt

Converts a double-precision floating-point number to a 32-bit unsigned integer. Handles special cases including NaN and numbers outside the valid UInt range.

Parameters:

  • self : The double-precision floating-point number to be converted.

Returns an 32-bit unsigned integer value according to the following rules:

  • Returns 0 if the input is NaN
  • Returns @uint.max_value (4294967295U) if the input is greater than or equal to @uint.max_value
  • Returns @uint.min_value (0U) if the input is less than or equal to @uint.min_value
  • Otherwise returns the integer part of the input by truncating towards zero

Example:

test "Double::to_uint/normal" {
  inspect(42.0.to_uint(), content="42")
  inspect((-42.5).to_uint(), content="0")
  inspect((0.0 / 0.0).to_uint(), content="0") // NaN
  inspect((1.0 / 0.0).to_uint(), content="4294967295") // Infinity
  inspect((-1.0 / 0.0).to_uint(), content="0") // -Infinity
}
to_uint
()
65 let
Color
actual
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(
UInt
h
,
UInt
s
,
UInt
l
).
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
()
66 let
Color
expected
=
struct HSL {
  hue: UInt
  saturation: UInt
  lightness: UInt
}

HSL color

HSL
::
(hue : UInt, saturation : UInt, lightness : UInt) -> HSL
new
(
UInt
h
,
UInt
s
,
UInt
l
).
(self : HSL) -> Color
to_color
()
67 let
Double
error
:
Double
Double
= 5
68
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
69
Color
actual
.
(self : Color) -> Byte
red
() |>
(Byte) -> Double
b2d
,
70
Color
expected
.
(self : Color) -> Byte
red
() |>
(Byte) -> Double
b2d
,
71
Double
error
~,
72 ) 73
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
74
Color
actual
.
(self : Color) -> Byte
green
() |>
(Byte) -> Double
b2d
,
75
Color
expected
.
(self : Color) -> Byte
green
() |>
(Byte) -> Double
b2d
,
76
Double
error
~,
77 ) 78
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
79
Color
actual
.
(self : Color) -> Byte
blue
() |>
(Byte) -> Double
b2d
,
80
Color
expected
.
(self : Color) -> Byte
blue
() |>
(Byte) -> Double
b2d
,
81
Double
error
~,
82 ) 83 } 84 } 85 } 86} 87 88///| 89test "hsl/rgb convert error=10" { 90 fn
(Byte) -> Double
b2d
(
Byte
x
:
Byte
Byte
) ->
Double
Double
{
91
Byte
x
.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
().
(self : Int) -> Double

Converts a 32-bit integer to a double-precision floating-point number. The conversion preserves the exact value since all integers in the range of Int can be represented exactly as Double values.

Parameters:

  • self : The 32-bit integer to be converted.

Returns a double-precision floating-point number that represents the same numerical value as the input integer.

Example:

test "Int::to_double" {
  let n = 42
  inspect(n.to_double(), content="42")
  let neg = -42
  inspect(neg.to_double(), content="-42")
}
to_double
()
92 } 93 94 for
UInt
h
in
UInt
0U
..<360 {
95 for
UInt
s
in
UInt
0U
..=100 {
96 for
UInt
l
in
UInt
0U
..=100 {
97 let
Color
actual
=
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(
UInt
h
,
UInt
s
,
UInt
l
).
(self : Color) -> HSL
to_hsl
().
(self : HSL) -> Color
to_color
()
98 let
Color
expected
=
struct HSL {
  hue: UInt
  saturation: UInt
  lightness: UInt
}

HSL color

HSL
::
(hue : UInt, saturation : UInt, lightness : UInt) -> HSL
new
(
UInt
h
,
UInt
s
,
UInt
l
).
(self : HSL) -> Color
to_color
()
99 let
Double
error
:
Double
Double
= 10
100
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
101
Color
actual
.
(self : Color) -> Byte
red
() |>
(Byte) -> Double
b2d
,
102
Color
expected
.
(self : Color) -> Byte
red
() |>
(Byte) -> Double
b2d
,
103
Double
error
~,
104 ) 105
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
106
Color
actual
.
(self : Color) -> Byte
green
() |>
(Byte) -> Double
b2d
,
107
Color
expected
.
(self : Color) -> Byte
green
() |>
(Byte) -> Double
b2d
,
108
Double
error
~,
109 ) 110
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
111
Color
actual
.
(self : Color) -> Byte
blue
() |>
(Byte) -> Double
b2d
,
112
Color
expected
.
(self : Color) -> Byte
blue
() |>
(Byte) -> Double
b2d
,
113
Double
error
~,
114 ) 115 } 116 } 117 } 118} 119