frontend/mpfr_expr API
frontend/mpfr_expr は GNU MPFR で生成された参照データを構文解析し、bin_float に対して実行します。サポートする形式は 3 つで、MPFR の平方根 data_check ファイル、整数べきの行、および例外フラグ付きの初等関数マトリクスです。このパッケージは IO を行わず、ランナーは cli/mpfr_expr_cli です。ワークフローはチュートリアルを、合格規則は設計ページを参照してください。
moon.pkg でパッケージをインポートします:
import {
"Luna-Flow/floating/frontend/mpfr_expr",
}
共通の行構文
3 つのパーサはいずれもテキストを \n で分割し、各行の前後の空白を除去し、空行と # で始まる行をスキップします。フィールドは空白、タブ、キャリッジリターンで区切られます。行番号は 1 から始まります。丸めフィールドは次のいずれかであり、
| フィールド | BinaryRoundingMode |
|---|---|
n | RoundTiesToEven |
na | RoundTiesToAway |
z | RoundTowardZero |
u | RoundTowardPositive |
d | RoundTowardNegative |
a | RoundAwayFromZero |
数は @bin_float.BinFloat::from_hex(0x…p…、inf、-inf、nan)で読み取られます。各パーサは、すべての行が有効なら Ok(document) を、そうでなければ無効な行ごとに 1 つの ParseDiagnostic を含む Err を返します。
平方根データ
parse_sqrt_data
parse_sqrt_data(source, text) は 5 つのフィールド input_precision output_precision rounding input expected からなる行を構文解析します。
pub fn parse_sqrt_data(String, String) -> Result[MpfrDocument, Array[ParseDiagnostic]]
入力は input_precision ビットで、期待値は output_precision ビットで読み取られます。行 id は sqrt:LINE です。
execute_sqrt_data
execute_sqrt_data(document) は各行について input.sqrt_ctx(ctx) を計算します。ここで ctx は BinaryContext::unbounded(output_precision, rounding~) です。
pub fn execute_sqrt_data(MpfrDocument) -> RunSummary
結果が期待される BinFloat と等しい(==)とき、その行は合格です。フラグは比較されません。
MpfrDocument, MpfrCase
MpfrDocument は構文解析済みの平方根ファイルです。MpfrCase はその 1 行で、公開メソッドはありません。
pub struct MpfrDocument {
// private fields
}
pub fn MpfrDocument::source(Self) -> String
pub fn MpfrDocument::case_count(Self) -> Int
pub struct MpfrCase {
// private fields
}
source はパーサに与えられた名前を、case_count は行数を返します。
整数べき
parse_pow_data
parse_pow_data(source, text) は 10 個のフィールドからなる行を構文解析します。
pub fn parse_pow_data(String, String) -> Result[MpfrPowDocument, Array[ParseDiagnostic]]
フィールドは precision rounding input_coefficient_hex input_exponent2 input_negative exponent expected_coefficient_hex expected_exponent2 expected_negative inexact です。ここで 2 つの数は であり、符号と inexact は 0 または 1、exponent は整数のべき指数です。入力は 512 ビットで、期待値は precision ビットで読み取られます。行 id は pow:LINE です。
execute_pow_data
execute_pow_data(document) は ctx = BinaryContext::unbounded(precision, rounding~) として input.pow_int_ctx(exponent, ctx) を計算します。
pub fn execute_pow_data(MpfrPowDocument) -> RunSummary
結果が期待値と等しく(==)、inexact フラグが行のフラグと等しく、アンダーフロー・オーバーフロー・ゼロ除算・invalid のいずれのフラグも発生しないとき、その行は合格です。
MpfrPowDocument, MpfrPowCase
MpfrPowDocument は構文解析済みのべき乗ファイルです。MpfrPowCase はその 1 行で、公開メソッドはありません。
pub struct MpfrPowDocument {
// private fields
}
pub fn MpfrPowDocument::source(Self) -> String
pub fn MpfrPowDocument::case_count(Self) -> Int
pub struct MpfrPowCase {
// private fields
}
初等関数
parse_elementary_data
parse_elementary_data(source, text) は 10 個のフィールド op precision rounding x y n expected inexact invalid divbyzero からなる行を構文解析します。
pub fn parse_elementary_data(String, String) -> Result[MpfrElementaryDocument, Array[ParseDiagnostic]]
op は 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 と y は 512 ビットで読み取られるオペランド(y は使わない場合 -)、n は rootn と pown の整数引数、expected は precision ビットで読み取られ、最後の 3 つのフィールドは 0 または 1 です。行 id は op:LINE です。
パーサは、2 オペランドの関数 pow、hypot、atan2 について y があることを検査しません。そのような行を y = - のまま実行すると異常終了します。
execute_elementary_data
execute_elementary_data(document) は各行を、その演算に対応する BinFloat の checked な try_*_ctx メソッド(sqrt と pown については sqrt_ctx と pown_ctx)で BinaryContext::unbounded(precision, rounding~) のもとで評価します。
pub fn execute_elementary_data(MpfrElementaryDocument) -> RunSummary
結果が期待値と等しいと比較され(compare == 0。 であり、すべての NaN はすべての NaN と等しい)、inexact・invalid・ゼロ除算の各フラグが行のフラグと等しく、アンダーフローもオーバーフローも発生しないとき、その行は合格です。try_*_ctx メソッドが Err を返した場合(例えば認証の失敗)、その行はメッセージ "certification failure for MPFR differential case" で失敗します。
MpfrElementaryDocument
MpfrElementaryDocument は構文解析済みの初等関数ファイルです。
pub struct MpfrElementaryDocument {
// private fields
}
pub fn MpfrElementaryDocument::source(Self) -> String
pub fn MpfrElementaryDocument::case_count(Self) -> Int
診断と結果
ParseDiagnostic
ParseDiagnostic は 1 つの無効な行です。
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
メッセージは問題を示します。例えば "MPFR pow row must contain ten fields"、"invalid MPFR pow field"、"invalid MPFR elementary expected value" などです。
CaseResult
CaseResult は 1 行の結果です。
pub struct CaseResult {
// private fields
}
pub fn CaseResult::id(Self) -> String
pub fn CaseResult::passed(Self) -> Bool
pub fn CaseResult::message(Self) -> String
メッセージは合格なら空で、そうでなければ期待値と実際の値を 16 進で示します(べき乗と初等関数の行では比較したフラグも示します)。
RunSummary
RunSummary は 1 つの文書の行を集計します。
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
すべての行が実行されるため です。success はどの行も失敗しなかったとき真です。results は結果を行順に返します。
///|
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")
}
トレイト実装
ParseDiagnostic::equal, ParseDiagnostic::not_equal, ParseDiagnostic::to_repr
これらのメソッドは位置とメッセージを比較し、診断を Debug 用に描画します。新しいコードでは ==、!=、debug_inspect を使ってください。
pub fn ParseDiagnostic::equal(Self, Self) -> Bool
pub fn ParseDiagnostic::not_equal(Self, Self) -> Bool
pub fn ParseDiagnostic::to_repr(Self) -> @debug.Repr
公開インターフェース全体
このスナップショットは、パッケージの生成された pkg.generated.mbti です。説明文とインターフェースが食い違う場合は、こちらが正となります。
// 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