frontend/mpfr_expr API
frontend/mpfr_expr parses reference data produced with GNU MPFR and executes
it against bin_float. Three formats are supported: MPFR’s square-root
data_check files, integer-power rows, and an elementary-function matrix with
exception flags. The package does no IO; the runner is
cli/mpfr_expr_cli. See the
tutorial for the workflow and the
design page for the pass rules.
Import the package in moon.pkg:
import {
"Luna-Flow/floating/frontend/mpfr_expr",
}
Common row syntax
All three parsers split the text at \n, trim each line, and skip empty lines
and lines starting with #. Fields are separated by spaces, tabs or carriage
returns. Line numbers start at 1. A rounding field is one of
| Field | BinaryRoundingMode |
|---|---|
n | RoundTiesToEven |
na | RoundTiesToAway |
z | RoundTowardZero |
u | RoundTowardPositive |
d | RoundTowardNegative |
a | RoundAwayFromZero |
and a number is read by @bin_float.BinFloat::from_hex (0x…p…, inf,
-inf, nan). Each parser returns Ok(document) when every line is valid and
otherwise Err with one ParseDiagnostic per invalid line.
Square-root data
parse_sqrt_data
parse_sqrt_data(source, text) parses rows of five fields:
input_precision output_precision rounding input expected.
pub fn parse_sqrt_data(String, String) -> Result[MpfrDocument, Array[ParseDiagnostic]]
The input is read at input_precision bits and the expected value at
output_precision bits. Row ids are sqrt:LINE.
execute_sqrt_data
execute_sqrt_data(document) computes input.sqrt_ctx(ctx) for every row,
where ctx is BinaryContext::unbounded(output_precision, rounding~).
pub fn execute_sqrt_data(MpfrDocument) -> RunSummary
A row passes when the result is equal (==) to the expected BinFloat.
Flags are not compared.
MpfrDocument, MpfrCase
MpfrDocument is a parsed square-root file; MpfrCase is one of its rows and
has no public methods.
pub struct MpfrDocument {
// private fields
}
pub fn MpfrDocument::source(Self) -> String
pub fn MpfrDocument::case_count(Self) -> Int
pub struct MpfrCase {
// private fields
}
source returns the name given to the parser and case_count the number of
rows.
Integer powers
parse_pow_data
parse_pow_data(source, text) parses rows of ten fields.
pub fn parse_pow_data(String, String) -> Result[MpfrPowDocument, Array[ParseDiagnostic]]
The fields are precision rounding input_coefficient_hex input_exponent2 input_negative exponent expected_coefficient_hex expected_exponent2 expected_negative inexact, where the two numbers are
,
the signs and inexact are 0 or 1, and exponent is the integer power.
The input is read at 512 bits and the expected value at precision bits. Row
ids are pow:LINE.
execute_pow_data
execute_pow_data(document) computes input.pow_int_ctx(exponent, ctx) with
ctx = BinaryContext::unbounded(precision, rounding~).
pub fn execute_pow_data(MpfrPowDocument) -> RunSummary
A row passes when the result is equal (==) to the expected value, the
inexact flag equals the row’s flag, and no underflow, overflow, division by
zero or invalid flag is raised.
MpfrPowDocument, MpfrPowCase
MpfrPowDocument is a parsed power file; MpfrPowCase is one row and has no
public methods.
pub struct MpfrPowDocument {
// private fields
}
pub fn MpfrPowDocument::source(Self) -> String
pub fn MpfrPowDocument::case_count(Self) -> Int
pub struct MpfrPowCase {
// private fields
}
Elementary functions
parse_elementary_data
parse_elementary_data(source, text) parses rows of ten fields:
op precision rounding x y n expected inexact invalid divbyzero.
pub fn parse_elementary_data(String, String) -> Result[MpfrElementaryDocument, Array[ParseDiagnostic]]
op is one of exp, exp2, exp10, expm1, ln, log2, log10,
log1p, sqrt, rootn, pown, pow, hypot, sin, cos, tan,
sinpi, cospi, tanpi, asin, acos, atan, atan2, sinh, cosh,
tanh, asinh, acosh, atanh. x and y are operands read at 512 bits
(y is - when unused), n is the integer argument of rootn and pown,
expected is read at precision bits, and the last three fields are 0 or
1. Row ids are op:LINE.
The parser does not check that y is present for the two-operand functions
pow, hypot and atan2; executing such a row with y = - aborts.
execute_elementary_data
execute_elementary_data(document) evaluates every row with the checked
try_*_ctx method of BinFloat for its operation (sqrt_ctx and pown_ctx
for sqrt and pown) in BinaryContext::unbounded(precision, rounding~).
pub fn execute_elementary_data(MpfrElementaryDocument) -> RunSummary
A row passes when the result compares equal to the expected value
(compare == 0: and every NaN equals every NaN), the inexact,
invalid and division-by-zero flags equal the row’s flags, and neither
underflow nor overflow is raised. If a try_*_ctx method returns Err (for
example a certification failure) the row fails with the message
"certification failure for MPFR differential case".
MpfrElementaryDocument
MpfrElementaryDocument is a parsed elementary file.
pub struct MpfrElementaryDocument {
// private fields
}
pub fn MpfrElementaryDocument::source(Self) -> String
pub fn MpfrElementaryDocument::case_count(Self) -> Int
Diagnostics and results
ParseDiagnostic
ParseDiagnostic is one invalid line.
pub struct ParseDiagnostic {
// private fields
} derive(Eq, @debug.Debug)
pub fn ParseDiagnostic::source(Self) -> String
pub fn ParseDiagnostic::line(Self) -> Int
pub fn ParseDiagnostic::message(Self) -> String
Messages name the problem, for example "MPFR pow row must contain ten fields", "invalid MPFR pow field" or "invalid MPFR elementary expected value".
CaseResult
CaseResult is the outcome of one row.
pub struct CaseResult {
// private fields
}
pub fn CaseResult::id(Self) -> String
pub fn CaseResult::passed(Self) -> Bool
pub fn CaseResult::message(Self) -> String
The message is empty for a pass and otherwise shows expected and actual values in hexadecimal (and the compared flags for power and elementary rows).
RunSummary
RunSummary aggregates the rows of one document.
pub struct RunSummary {
// private fields
}
pub fn RunSummary::total_cases(Self) -> Int
pub fn RunSummary::passed_cases(Self) -> Int
pub fn RunSummary::failed_cases(Self) -> Int
pub fn RunSummary::results(Self) -> Array[CaseResult]
pub fn RunSummary::success(Self) -> Bool
Every row is executed, so ;
success is true when no row failed. results returns the results in row
order.
///|
test "mpfr summary" {
let rows =
#|53 53 n 0x0p0 0x0p0
#|53 53 u 0x3p0 0x1bb67ae8584cabp-52
#|
let summary = @mpfr_expr.execute_sqrt_data(
@mpfr_expr.parse_sqrt_data("s", rows).unwrap(),
)
inspect(summary.total_cases(), content="2")
inspect(summary.passed_cases(), content="2")
}
Trait implementations
ParseDiagnostic::equal, ParseDiagnostic::not_equal, ParseDiagnostic::to_repr
These methods compare location and message and render a diagnostic for
Debug. Use ==, != and debug_inspect in new code.
pub fn ParseDiagnostic::equal(Self, Self) -> Bool
pub fn ParseDiagnostic::not_equal(Self, Self) -> Bool
pub fn ParseDiagnostic::to_repr(Self) -> @debug.Repr
Complete public interface
This snapshot is the generated pkg.generated.mbti of the package. It is the authority when prose and interface disagree.
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/frontend/mpfr_expr"
import {
"moonbitlang/core/debug",
}
// Values
pub fn execute_elementary_data(MpfrElementaryDocument) -> RunSummary
pub fn execute_pow_data(MpfrPowDocument) -> RunSummary
pub fn execute_sqrt_data(MpfrDocument) -> RunSummary
pub fn parse_elementary_data(String, String) -> Result[MpfrElementaryDocument, Array[ParseDiagnostic]]
pub fn parse_pow_data(String, String) -> Result[MpfrPowDocument, Array[ParseDiagnostic]]
pub fn parse_sqrt_data(String, String) -> Result[MpfrDocument, Array[ParseDiagnostic]]
// Errors
// Types and methods
pub struct CaseResult {
// private fields
}
pub fn CaseResult::id(Self) -> String
pub fn CaseResult::message(Self) -> String
pub fn CaseResult::passed(Self) -> Bool
pub struct MpfrCase {
// private fields
}
pub struct MpfrDocument {
// private fields
}
pub fn MpfrDocument::case_count(Self) -> Int
pub fn MpfrDocument::source(Self) -> String
pub struct MpfrElementaryDocument {
// private fields
}
pub fn MpfrElementaryDocument::case_count(Self) -> Int
pub fn MpfrElementaryDocument::source(Self) -> String
pub struct MpfrPowCase {
// private fields
}
pub struct MpfrPowDocument {
// private fields
}
pub fn MpfrPowDocument::case_count(Self) -> Int
pub fn MpfrPowDocument::source(Self) -> String
pub struct ParseDiagnostic {
// private fields
} derive(Eq, @debug.Debug)
pub fn ParseDiagnostic::equal(Self, Self) -> Bool
pub fn ParseDiagnostic::line(Self) -> Int
pub fn ParseDiagnostic::message(Self) -> String
pub fn ParseDiagnostic::not_equal(Self, Self) -> Bool
pub fn ParseDiagnostic::source(Self) -> String
pub fn ParseDiagnostic::to_repr(Self) -> @debug.Repr
pub struct RunSummary {
// private fields
}
pub fn RunSummary::failed_cases(Self) -> Int
pub fn RunSummary::passed_cases(Self) -> Int
pub fn RunSummary::results(Self) -> Array[CaseResult]
pub fn RunSummary::success(Self) -> Bool
pub fn RunSummary::total_cases(Self) -> Int
// Type aliases
// Traits