1///|
2test "rgb/hsl convert: assert_eq" {
3  let mut 
Int
count
= 0
4 for
Int
h
in
Int
0
..<12 {
5 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 {
6 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 {
7 let
Double
h
=
Int
h
.
(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

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")
}
*
30
8 let
Double
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
9 let
Double
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
10 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
)
11 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
)
12
(a : Double, b : Double, 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
!(
Double
l
,
Double
l_
)
13 if (
Double
l
(x : Double, y : Double) -> Bool
!=
0
(Bool, Bool) -> Bool
&&
Double
l
(x : Double, y : Double) -> Bool
!=
1)
(Bool, Bool) -> Bool
||
(
Double
l_
(x : Double, y : Double) -> Bool
!=
0
(Bool, Bool) -> Bool
&&
Double
l_
(x : Double, y : Double) -> Bool
!=
1) {
14
(a : Double, b : Double, 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
!(
Double
h
,
Double
h_
)
15
(a : Double, b : Double, 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
!(
Double
s
,
Double
s_
)
16 } 17 } 18 } 19 } 20} 21 22///| 23test "rgb/hsl convert: assert_eq_with_error" { 24 let mut
Int
count
= 0
25 let
Double
error
:
Double
Double
= 0.000000000000001
26 for
UInt
h
in
UInt
0U
..<360 {
27 for
UInt
s
in
UInt
0U
..=100 {
28 for
UInt
l
in
UInt
0U
..=100 {
29 let
Double
h
=
UInt
h
.
(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
()
30 let
Double
s
=
UInt
s
.
(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
31 let
Double
l
=
UInt
l
.
(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
32 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
)
33 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
)
34
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
Double
l
,
Double
l_
,
Double
error
~)
35 if (
Double
l
.
(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
()
(x : Double, y : Double) -> Bool
!=
0
(Bool, Bool) -> Bool
&&
Double
l
.
(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
()
(x : Double, y : Double) -> Bool
!=
1)
(Bool, Bool) -> Bool
||
36 (
Double
l_
.
(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
()
(x : Double, y : Double) -> Bool
!=
0
(Bool, Bool) -> Bool
&&
Double
l_
.
(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
()
(x : Double, y : Double) -> Bool
!=
1) {
37
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
Double
h
,
Double
h_
,
Double
error
~)
38
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
!(
Double
s
,
Double
s_
,
Double
error
~)
39 } 40 } 41 } 42 } 43} 44