1///|
2fn 
(x : Double, y : Double, error~ : Double, loc~ : SourceLoc = _) -> Unit!Error
assert_eq_with_error
(
3
Double
x
:
Double
Double
,
4
Double
y
:
Double
Double
,
5
Double
error
~ :
Double
Double
,
6
SourceLoc
loc
~ :
type SourceLoc

Represents a source code location in a MoonBit program, containing information about the file path, line number, and column number. Used internally by the compiler for error reporting and debugging purposes.

This type is public to all packages but its internal representation is opaque. Users cannot construct values of this type directly; they are automatically created by the compiler when needed.

SourceLoc
= _
7) ->
Unit
Unit
! {
8 if (
Double
x
(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
y
).
(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
()
(self_ : Double, other : Double) -> Bool
>
Double
error
{
9
(msg : String, loc~ : SourceLoc) -> Unit!Failure

Raises a Failure error with a given message and source location.

Parameters:

  • message : A string containing the error message to be included in the failure.
  • location : The source code location where the failure occurred. Automatically provided by the compiler when not specified.

Returns a value of type T wrapped in a Failure error type.

Throws an error of type Failure with a message that includes both the source location and the provided error message.

Example:

test "panic fail" {
  fail("Something went wrong")
}
fail
!("|\{
Double
x
} - \{
Double
y
}| <= \{
Double
error
}",
SourceLoc
loc
~)
10 } 11} 12