1///|
2pub fn 
type Color UInt

RGBA color

Color
::
(self : Color) -> Byte
red
(
Color
self
:
type Color UInt

RGBA color

Color
) ->
Byte
Byte
{
3 ((
Color
self
.
UInt
_
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
24)
(UInt, UInt) -> UInt
&
0xFFU).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
4} 5 6///| 7pub fn
type Color UInt

RGBA color

Color
::
(self : Color) -> Byte
green
(
Color
self
:
type Color UInt

RGBA color

Color
) ->
Byte
Byte
{
8 ((
Color
self
.
UInt
_
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
16)
(UInt, UInt) -> UInt
&
0xFFU).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
9} 10 11///| 12pub fn
type Color UInt

RGBA color

Color
::
(self : Color) -> Byte
blue
(
Color
self
:
type Color UInt

RGBA color

Color
) ->
Byte
Byte
{
13 ((
Color
self
.
UInt
_
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
8)
(UInt, UInt) -> UInt
&
0xFFU).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
14} 15 16///| 17pub fn
type Color UInt

RGBA color

Color
::
(self : Color) -> Byte
alpha
(
Color
self
:
type Color UInt

RGBA color

Color
) ->
Byte
Byte
{
18 (
Color
self
.
UInt
_
(UInt, UInt) -> UInt
&
0xFFU).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
19} 20 21///| 22/// * `red` in \[0,255\] 23/// 24/// * `green` in \[0,255\] 25/// 26/// * `blue` in \[0,255\] 27/// 28/// * `alpha` in \[0,255\] 29pub fn
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte, alpha : Byte) -> Color
  • red in [0,255]

  • green in [0,255]

  • blue in [0,255]

  • alpha in [0,255]

rgba
(
30
Byte
red
:
Byte
Byte
,
31
Byte
green
:
Byte
Byte
,
32
Byte
blue
:
Byte
Byte
,
33
Byte
alpha
:
Byte
Byte
34) ->
type Color UInt

RGBA color

Color
{
35 (
Byte
red
.
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
24)
(UInt, UInt) -> UInt
|
36 (
Byte
green
.
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
16)
(UInt, UInt) -> UInt
|
37 (
Byte
blue
.
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
8)
(UInt, UInt) -> UInt
|
38
Byte
alpha
.
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
39} 40 41///| 42test "rgba" { 43 let
Color
color
=
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte, alpha : Byte) -> Color
  • red in [0,255]

  • green in [0,255]

  • blue in [0,255]

  • alpha in [0,255]

rgba
(0x00, 0x10, 0x20, 0x30)
44
(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) -> Byte
red
(),
String
content
="b'\\x00'")
45
(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) -> Byte
green
(),
String
content
="b'\\x10'")
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
color
.
(self : Color) -> Byte
blue
(),
String
content
="b'\\x20'")
47
(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) -> Byte
alpha
(),
String
content
="b'\\x30'")
48} 49 50///| 51fn
(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> Unit
validate_hsla
(
52
UInt
hue
:
UInt
UInt
,
53
UInt
saturation
:
UInt
UInt
,
54
UInt
lightness
:
UInt
UInt
,
55
UInt
alpha
:
UInt
UInt
56) ->
Unit
Unit
{
57 guard
UInt
hue
(self_ : UInt, other : UInt) -> Bool
<
360
(Bool, Bool) -> Bool
&&
UInt
saturation
(self_ : UInt, other : UInt) -> Bool
<=
100
(Bool, Bool) -> Bool
&&
UInt
lightness
(self_ : UInt, other : UInt) -> Bool
<=
100
(Bool, Bool) -> Bool
&&
UInt
alpha
(self_ : UInt, other : UInt) -> Bool
<=
100
58} 59 60///| 61/// * `hue` in \[0,360) 62/// 63/// * `saturation` in \[0,100\] 64/// 65/// * `lightness` in \[0,100\] 66/// 67/// * `alpha` in \[0,100\] 68/// 69/// [wiki](https://en.wikipedia.org/wiki/HSL_and_HSV) 70pub fn
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> Color
  • hue in [0,360)

  • saturation in [0,100]

  • lightness in [0,100]

  • alpha in [0,100]

wiki

hsla
(
71
UInt
hue
:
UInt
UInt
,
72
UInt
saturation
:
UInt
UInt
,
73
UInt
lightness
:
UInt
UInt
,
74
UInt
alpha
:
UInt
UInt
75) ->
type Color UInt

RGBA color

Color
{
76
(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> Unit
validate_hsla
(
UInt
hue
,
UInt
saturation
,
UInt
lightness
,
UInt
alpha
)
77 let
Double
h
=
UInt
hue
.
(self : UInt) -> Double

Converts an unsigned 32-bit integer to a double-precision floating-point number. Since the range of unsigned 32-bit integers is smaller than what can be precisely represented by a double-precision floating-point number, this conversion is guaranteed to be exact.

Parameters:

  • value : The unsigned 32-bit integer to be converted.

Returns a double-precision floating-point number that exactly represents the input value.

Example:

test "Double::convert_uint" {
  let n = 42U
  inspect(n.to_double(), content="42")
  let max = 4294967295U // maximum value of UInt
  inspect(max.to_double(), content="4294967295")
}
to_double
()
78 let
Double
s
=
UInt
saturation
.
(self : UInt) -> Double

Converts an unsigned 32-bit integer to a double-precision floating-point number. Since the range of unsigned 32-bit integers is smaller than what can be precisely represented by a double-precision floating-point number, this conversion is guaranteed to be exact.

Parameters:

  • value : The unsigned 32-bit integer to be converted.

Returns a double-precision floating-point number that exactly represents the input value.

Example:

test "Double::convert_uint" {
  let n = 42U
  inspect(n.to_double(), content="42")
  let max = 4294967295U // maximum value of UInt
  inspect(max.to_double(), content="4294967295")
}
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")
}
/
100
79 let
Double
l
=
UInt
lightness
.
(self : UInt) -> Double

Converts an unsigned 32-bit integer to a double-precision floating-point number. Since the range of unsigned 32-bit integers is smaller than what can be precisely represented by a double-precision floating-point number, this conversion is guaranteed to be exact.

Parameters:

  • value : The unsigned 32-bit integer to be converted.

Returns a double-precision floating-point number that exactly represents the input value.

Example:

test "Double::convert_uint" {
  let n = 42U
  inspect(n.to_double(), content="42")
  let max = 4294967295U // maximum value of UInt
  inspect(max.to_double(), content="4294967295")
}
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")
}
/
100
80 let
Double
a
=
UInt
alpha
.
(self : UInt) -> Double

Converts an unsigned 32-bit integer to a double-precision floating-point number. Since the range of unsigned 32-bit integers is smaller than what can be precisely represented by a double-precision floating-point number, this conversion is guaranteed to be exact.

Parameters:

  • value : The unsigned 32-bit integer to be converted.

Returns a double-precision floating-point number that exactly represents the input value.

Example:

test "Double::convert_uint" {
  let n = 42U
  inspect(n.to_double(), content="42")
  let max = 4294967295U // maximum value of UInt
  inspect(max.to_double(), content="4294967295")
}
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")
}
/
100
81 fn
(Double) -> Byte
to_byte
(
Double
v
:
Double
Double
) ->
Byte
Byte
{
82 (
Double
v
(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")
}
*
255.0).
(self : Double) -> Double

Rounds a floating-point number to the nearest integer using "round half up" rule. In this rule, when a number is halfway between two integers (like 3.5), it is rounded up to the next integer.

Parameters:

  • value : The floating-point number to be rounded.

Returns the rounded value as a double-precision floating-point number.

Example:

test "round" {
  inspect(3.7.round(), content="4")
  inspect(3.2.round(), content="3")
  inspect(3.5.round(), content="4")
  inspect((-3.5).round(), content="-3")
}
round
().
(self : Double) -> Int

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

Parameters:

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

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

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

Example:

test "Double::to_int/normal" {
  inspect(42.0.to_int(), content="42")
  inspect((-42.5).to_int(), content="-42")
  inspect((0.0 / 0.0).to_int(), content="0") // NaN
  inspect((1.0 / 0.0).to_int(), content="2147483647") // Infinity
  inspect((-1.0 / 0.0).to_int(), content="-2147483648") // -Infinity
}
to_int
().
(self : Int) -> Byte

Converts a 32-bit signed integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • value : The 32-bit signed integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "Int::to_byte" {
  let n = 258 // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let neg = -1 // In binary: all 1's
  inspect(neg.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
83 } 84 85 let (
Double
r
,
Double
g
,
Double
b
) =
(h : Double, s : Double, l : Double) -> (Double, Double, Double)

h in [0,360)

s in [0,1]

l in [0,1]

hsl_to_rgb
(
Double
h
,
Double
s
,
Double
l
)
86
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte, alpha : Byte) -> Color
  • red in [0,255]

  • green in [0,255]

  • blue in [0,255]

  • alpha in [0,255]

rgba
(
87
(Double) -> Byte
to_byte
(
Double
r
),
88
(Double) -> Byte
to_byte
(
Double
g
),
89
(Double) -> Byte
to_byte
(
Double
b
),
90 (
Double
a
(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")
}
*
255.0).
(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
().
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
(),
91 ) 92} 93 94///| 95pub fn
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte) -> Color
rgb
(
Byte
red
:
Byte
Byte
,
Byte
green
:
Byte
Byte
,
Byte
blue
:
Byte
Byte
) ->
type Color UInt

RGBA color

Color
{
96
type Color UInt

RGBA color

Color
::
(red : Byte, green : Byte, blue : Byte, alpha : Byte) -> Color
  • red in [0,255]

  • green in [0,255]

  • blue in [0,255]

  • alpha in [0,255]

rgba
(
Byte
red
,
Byte
green
,
Byte
blue
, 255)
97} 98 99///| 100pub fn
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt) -> Color
hsl
(
UInt
hue
:
UInt
UInt
,
UInt
saturation
:
UInt
UInt
,
UInt
lightness
:
UInt
UInt
) ->
type Color UInt

RGBA color

Color
{
101
type Color UInt

RGBA color

Color
::
(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> Color
  • hue in [0,360)

  • saturation in [0,100]

  • lightness in [0,100]

  • alpha in [0,100]

wiki

hsla
(
UInt
hue
,
UInt
saturation
,
UInt
lightness
, 100)
102} 103 104///| 105pub impl
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
for
type Color UInt

RGBA color

Color
with
(self : Color, logger : &Logger) -> Unit
output
(
Color
self
,
&Logger
logger
) {
106 fn
(Byte) -> Char
to_xdigit
(
Byte
x
:
Byte
Byte
) {
107 if
Byte
x
(self_ : Byte, other : Byte) -> Bool
<
10 {
108
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, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

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

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
'0'.
(self : Char) -> Int

Converts a character to its Unicode code point value as an integer.

Parameters:

  • self : The character to be converted.

Returns an integer representing the Unicode code point value of the character.

Example:

test "Char::to_int" {
  inspect('A'.to_int(), content="65") // ASCII value of 'A'
  inspect('あ'.to_int(), content="12354") // Unicode code point of 'あ'
}
to_int
() |>
(Int) -> Char
Int::unsafe_to_char
109 } else { 110
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, 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
}
-
10
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

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

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
'A'.
(self : Char) -> Int

Converts a character to its Unicode code point value as an integer.

Parameters:

  • self : The character to be converted.

Returns an integer representing the Unicode code point value of the character.

Example:

test "Char::to_int" {
  inspect('A'.to_int(), content="65") // ASCII value of 'A'
  inspect('あ'.to_int(), content="12354") // Unicode code point of 'あ'
}
to_int
() |>
(Int) -> Char
Int::unsafe_to_char
111 } 112 } 113 114 fn
(Byte) -> Unit
aux
(
Byte
x
:
Byte
Byte
) {
115 if
Byte
x
(self_ : Byte, other : Byte) -> Bool
<
0x0f {
116
&Logger
logger
.
(&Logger, Char) -> Unit
write_char
('0')
117
&Logger
logger
.
(&Logger, Char) -> Unit
write_char
(
(Byte) -> Char
to_xdigit
(
Byte
x
))
118 } else { 119
&Logger
logger
.
(&Logger, Char) -> Unit
write_char
(
(Byte) -> Char
to_xdigit
(
Byte
x
(self : Byte, count : Int) -> Byte

Shifts the bits of the Byte value to the right by the specified number of positions.

Parameters:

  • byte : The Byte value whose bits are to be shifted.
  • count : The number of bit positions to shift the byte value to the right.

Returns the resulting Byte value after the bitwise right shift operation.

>>
4))
120
&Logger
logger
.
(&Logger, Char) -> Unit
write_char
(
(Byte) -> Char
to_xdigit
(
Byte
x
(self : Byte, that : Byte) -> Byte

Performs a bitwise AND operation between two Byte values.

Parameters:

  • byte1 : The first Byte value to perform the bitwise AND operation with.
  • byte2 : The second Byte value to perform the bitwise AND operation with.

Returns the result of the bitwise AND operation as a Byte.

&
0x0F))
121 } 122 } 123 124
(Byte) -> Unit
aux
(
Color
self
.
(self : Color) -> Byte
red
())
125
(Byte) -> Unit
aux
(
Color
self
.
(self : Color) -> Byte
green
())
126
(Byte) -> Unit
aux
(
Color
self
.
(self : Color) -> Byte
blue
())
127
(Byte) -> Unit
aux
(
Color
self
.
(self : Color) -> Byte
alpha
())
128} 129 130///| 131pub fn
type Color UInt

RGBA color

Color
::new(x :
UInt
UInt
) ->
type Color UInt

RGBA color

Color
= "%identity"
132 133///| 134pub fn
type Color UInt

RGBA color

Color
::
(self : Color) -> HSL
to_hsl
(
Color
self
:
type Color UInt

RGBA color

Color
) ->
struct HSL {
  hue: UInt
  saturation: UInt
  lightness: UInt
}

HSL color

HSL
{
135 let
Double
r
=
Color
self
.
(self : Color) -> Byte
red
().
(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
()
(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")
}
/
255
136 let
Double
g
=
Color
self
.
(self : Color) -> Byte
green
().
(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
()
(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")
}
/
255
137 let
Double
b
=
Color
self
.
(self : Color) -> Byte
blue
().
(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
()
(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")
}
/
255
138 let (
Double
h
,
Double
s
,
Double
l
) =
(r : Double, g : Double, b : Double) -> (Double, Double, Double)
  • r in [0,1]

  • g in [0,1]

  • b in [0,1]

rgb_to_hsl
(
Double
r
,
Double
g
,
Double
b
)
139 let
UInt
hue
=
Double
h
.
(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
()
140 let
UInt
lightness
= (
Double
l
(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
()
141 let
UInt
saturation
= (
Double
s
(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
()
142 {
UInt
hue
,
UInt
saturation
,
UInt
lightness
}
143} 144