1///|
2fn (x : Double, y : Double) -> Double
mod(Double
x : Double
Double, Double
y : Double
Double) -> Double
Double {
3 if Double
x (self_ : Double, other : Double) -> Bool
< 0 {
4 (Double
x (self : Double, other : Double) -> Double
Adds two double-precision floating-point numbers together following IEEE 754
standards.
Parameters:
self : The first double-precision floating-point number.
other : The second double-precision floating-point number to add.
Returns the sum of the two numbers. Special cases follow IEEE 754 rules:
- If either operand is NaN, returns NaN
- If adding +∞ and -∞, returns NaN
- If adding ±∞ with any finite number, returns ±∞
- If adding +0.0 and -0.0, returns +0.0
Example:
test "Double::op_add" {
inspect(2.5 + 3.7, content="6.2")
inspect(1.0 / 0.0 + -1.0 / 0.0, content="NaN") // Infinity + -Infinity = NaN
}
+ Double
y) (self : Double, other : Double) -> Double
Calculates the floating-point remainder when dividend is divided by
divisor. Returns NaN if either operand is NaN, or if dividend is
infinity, or if divisor is zero.
Parameters:
dividend : The floating-point number to be divided.
divisor : The floating-point number used to divide the dividend.
Returns the remainder of the division. The result has the same sign as the
dividend and has an absolute value less than the absolute value of
divisor.
Example:
test "op_mod" {
inspect(5.0.op_mod(3.0), content="2")
inspect((-5.0).op_mod(3.0), content="-2")
inspect(5.0.op_mod(not_a_number), content="NaN")
inspect(infinity.op_mod(3.0), content="NaN")
}
% Double
y
5 } else {
6 Double
x (self : Double, other : Double) -> Double
Calculates the floating-point remainder when dividend is divided by
divisor. Returns NaN if either operand is NaN, or if dividend is
infinity, or if divisor is zero.
Parameters:
dividend : The floating-point number to be divided.
divisor : The floating-point number used to divide the dividend.
Returns the remainder of the division. The result has the same sign as the
dividend and has an absolute value less than the absolute value of
divisor.
Example:
test "op_mod" {
inspect(5.0.op_mod(3.0), content="2")
inspect((-5.0).op_mod(3.0), content="-2")
inspect(5.0.op_mod(not_a_number), content="NaN")
inspect(infinity.op_mod(3.0), content="NaN")
}
% Double
y
7 }
8}
9
10///|
11/// * r in \[0,1\]
12///
13/// * g in \[0,1\]
14///
15/// * b in \[0,1\]
16pub fn (r : Double, g : Double, b : Double) -> (Double, Double, Double)
-
r in [0,1]
-
g in [0,1]
-
b in [0,1]
rgb_to_hsl(
17 Double
r : Double
Double,
18 Double
g : Double
Double,
19 Double
b : Double
Double
20) -> (Double
Double, Double
Double, Double
Double) {
21 let Double
x_max = (x : Double, y : Double) -> Double
Compares and returns the maximum of two values.
Returns the second argument if the comparison determines them to be equal.
Examples
assert_eq(@math.maximum(1, 2), 2)
assert_eq(@math.maximum(2, 2), 2)
@math.maximum(Double
r, (x : Double, y : Double) -> Double
Compares and returns the maximum of two values.
Returns the second argument if the comparison determines them to be equal.
Examples
assert_eq(@math.maximum(1, 2), 2)
assert_eq(@math.maximum(2, 2), 2)
@math.maximum(Double
g, Double
b))
22 let Double
v = Double
x_max
23 let Double
x_min = (x : Double, y : Double) -> Double
Compares and returns the minimum of two values.
Returns the first argument if the comparison determines them to be equal.
Examples
assert_eq(@math.minimum(1, 2), 1)
assert_eq(@math.minimum(2, 2), 2)
@math.minimum(Double
r, (x : Double, y : Double) -> Double
Compares and returns the minimum of two values.
Returns the first argument if the comparison determines them to be equal.
Examples
assert_eq(@math.minimum(1, 2), 1)
assert_eq(@math.minimum(2, 2), 2)
@math.minimum(Double
g, Double
b))
24 let Double
c = Double
x_max (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
x_min
25 let Double
l = (Double
x_max (self : Double, other : Double) -> Double
Adds two double-precision floating-point numbers together following IEEE 754
standards.
Parameters:
self : The first double-precision floating-point number.
other : The second double-precision floating-point number to add.
Returns the sum of the two numbers. Special cases follow IEEE 754 rules:
- If either operand is NaN, returns NaN
- If adding +∞ and -∞, returns NaN
- If adding ±∞ with any finite number, returns ±∞
- If adding +0.0 and -0.0, returns +0.0
Example:
test "Double::op_add" {
inspect(2.5 + 3.7, content="6.2")
inspect(1.0 / 0.0 + -1.0 / 0.0, content="NaN") // Infinity + -Infinity = NaN
}
+ Double
x_min) (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")
}
/ 2
26 let Double
h = if Double
c (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== 0 {
27 0.0
28 } else if Double
v (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== Double
r {
29 60.0 (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")
}
* (x : Double, y : Double) -> Double
mod((Double
g (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
b) (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")
}
/ Double
c, 6)
30 } else if Double
v (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== Double
g {
31 60.0 (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")
}
* ((Double
b (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
r) (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")
}
/ Double
c (self : Double, other : Double) -> Double
Adds two double-precision floating-point numbers together following IEEE 754
standards.
Parameters:
self : The first double-precision floating-point number.
other : The second double-precision floating-point number to add.
Returns the sum of the two numbers. Special cases follow IEEE 754 rules:
- If either operand is NaN, returns NaN
- If adding +∞ and -∞, returns NaN
- If adding ±∞ with any finite number, returns ±∞
- If adding +0.0 and -0.0, returns +0.0
Example:
test "Double::op_add" {
inspect(2.5 + 3.7, content="6.2")
inspect(1.0 / 0.0 + -1.0 / 0.0, content="NaN") // Infinity + -Infinity = NaN
}
+ 2)
32 } else if Double
v (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== Double
b {
33 60.0 (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")
}
* ((Double
r (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
g) (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")
}
/ Double
c (self : Double, other : Double) -> Double
Adds two double-precision floating-point numbers together following IEEE 754
standards.
Parameters:
self : The first double-precision floating-point number.
other : The second double-precision floating-point number to add.
Returns the sum of the two numbers. Special cases follow IEEE 754 rules:
- If either operand is NaN, returns NaN
- If adding +∞ and -∞, returns NaN
- If adding ±∞ with any finite number, returns ±∞
- If adding +0.0 and -0.0, returns +0.0
Example:
test "Double::op_add" {
inspect(2.5 + 3.7, content="6.2")
inspect(1.0 / 0.0 + -1.0 / 0.0, content="NaN") // Infinity + -Infinity = NaN
}
+ 4)
34 } else {
35 (msg : String) -> Double
Aborts the program with an error message. Always causes a panic, regardless
of the message provided.
Parameters:
message : A string containing the error message to be displayed when
aborting.
Returns a value of type T. However, this function never actually returns a
value as it always causes a panic.
abort("unreachable")
36 }
37 let Double
s = if Double
l (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== 0 (Bool, Bool) -> Bool
|| Double
l (self : Double, other : Double) -> Bool
Compares two double-precision floating-point numbers for equality following
IEEE 754 rules. Returns true if both numbers are equal, including when both
are NaN. Note that this differs from the standard IEEE 754 behavior where
NaN is not equal to any value, including itself.
Parameters:
self : The first double-precision floating-point number to compare.
other : The second double-precision floating-point number to compare.
Returns true if both numbers are equal, false otherwise.
Example:
test "Double::op_equal" {
let a = 3.14
let b = 3.14
let c = 2.718
inspect(a == b, content="true")
inspect(a == c, content="false")
let nan = 0.0 / 0.0 // NaN
inspect(nan == nan, content="false") // Note: NaN equals itself in MoonBit
}
== 1 {
38 0.0
39 } else {
40 2.0 (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")
}
* (Double
v (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
l) (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")
}
/ (1.0 (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- (Double) -> Double
Double::(self : Double) -> Double
Returns the absolute value of a double-precision floating-point number.
Parameters:
value : The double-precision floating-point number to compute the
absolute value of.
Returns the absolute value of the input number. For any input x, the result
is equivalent to if x < 0.0 { -x } else { x }.
Example:
test "abs" {
inspect((-2.5).abs(), content="2.5")
inspect(3.14.abs(), content="3.14")
inspect(0.0.abs(), content="0")
}
abs(2.0 (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")
}
* Double
l (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- 1))
41 }
42 (Double
h, Double
s, Double
l)
43}
44
45///|
46/// h in \[0,360)
47///
48/// s in \[0,1\]
49///
50/// l in \[0,1\]
51pub fn (h : Double, s : Double, l : Double) -> (Double, Double, Double)
h in [0,360)
s in [0,1]
l in [0,1]
hsl_to_rgb(
52 Double
h : Double
Double,
53 Double
s : Double
Double,
54 Double
l : Double
Double
55) -> (Double
Double, Double
Double, Double
Double) {
56 let Double
c = (1.0 (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- (Double) -> Double
Double::(self : Double) -> Double
Returns the absolute value of a double-precision floating-point number.
Parameters:
value : The double-precision floating-point number to compute the
absolute value of.
Returns the absolute value of the input number. For any input x, the result
is equivalent to if x < 0.0 { -x } else { x }.
Example:
test "abs" {
inspect((-2.5).abs(), content="2.5")
inspect(3.14.abs(), content="3.14")
inspect(0.0.abs(), content="0")
}
abs(2.0 (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")
}
* Double
l (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- 1.0)) (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")
}
* Double
s
57 let Double
h_ = Double
h (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")
}
/ 60
58 let Double
x = Double
c (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")
}
* (1.0 (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- (Double) -> Double
Double::(self : Double) -> Double
Returns the absolute value of a double-precision floating-point number.
Parameters:
value : The double-precision floating-point number to compute the
absolute value of.
Returns the absolute value of the input number. For any input x, the result
is equivalent to if x < 0.0 { -x } else { x }.
Example:
test "abs" {
inspect((-2.5).abs(), content="2.5")
inspect(3.14.abs(), content="3.14")
inspect(0.0.abs(), content="0")
}
abs(Double
h_ (self : Double, other : Double) -> Double
Calculates the floating-point remainder when dividend is divided by
divisor. Returns NaN if either operand is NaN, or if dividend is
infinity, or if divisor is zero.
Parameters:
dividend : The floating-point number to be divided.
divisor : The floating-point number used to divide the dividend.
Returns the remainder of the division. The result has the same sign as the
dividend and has an absolute value less than the absolute value of
divisor.
Example:
test "op_mod" {
inspect(5.0.op_mod(3.0), content="2")
inspect((-5.0).op_mod(3.0), content="-2")
inspect(5.0.op_mod(not_a_number), content="NaN")
inspect(infinity.op_mod(3.0), content="NaN")
}
% 2.0 (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- 1.0))
59 let Double
m = Double
l (self : Double, other : Double) -> Double
Performs subtraction between two double-precision floating-point numbers.
Parameters:
self : The first operand (minuend).
other : The second operand (subtrahend).
Returns the difference between the two numbers according to IEEE 754
double-precision arithmetic rules.
Example:
test "Double::op_sub" {
let a = 5.0
let b = 3.0
inspect(a - b, content="2")
inspect(0.0 / 0.0 - 1.0, content="NaN") // NaN - anything = NaN
}
- Double
c (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")
}
/ 2.0
60 let (Double
r, Double
g, Double
b) = match Double
h_.(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() {
61 0 => (Double
c, Double
x, 0.0)
62 1 => (Double
x, Double
c, 0.0)
63 2 => (0.0, Double
c, Double
x)
64 3 => (0.0, Double
x, Double
c)
65 4 => (Double
x, 0.0, Double
c)
66 5 => (Double
c, 0.0, Double
x)
67 _ => (msg : String) -> (Double, Double, Double)
Aborts the program with an error message. Always causes a panic, regardless
of the message provided.
Parameters:
message : A string containing the error message to be displayed when
aborting.
Returns a value of type T. However, this function never actually returns a
value as it always causes a panic.
abort("unreachable")
68 }
69 fn (Double) -> Double
aux(Double
v : Double
Double) -> Double
Double {
70 Double
v (self : Double, other : Double) -> Double
Adds two double-precision floating-point numbers together following IEEE 754
standards.
Parameters:
self : The first double-precision floating-point number.
other : The second double-precision floating-point number to add.
Returns the sum of the two numbers. Special cases follow IEEE 754 rules:
- If either operand is NaN, returns NaN
- If adding +∞ and -∞, returns NaN
- If adding ±∞ with any finite number, returns ±∞
- If adding +0.0 and -0.0, returns +0.0
Example:
test "Double::op_add" {
inspect(2.5 + 3.7, content="6.2")
inspect(1.0 / 0.0 + -1.0 / 0.0, content="NaN") // Infinity + -Infinity = NaN
}
+ Double
m
71 }
72
73 ((Double) -> Double
aux(Double
r), (Double) -> Double
aux(Double
g), (Double) -> Double
aux(Double
b))
74}
75