decimal_gda API
decimal_gda は M. F. Cowlishaw による General Decimal Arithmetic 仕様(GDA、バージョン 1.70)を実装します。その Decimal は符号、任意長の十進係数、十進指数からなります。GdaContext は精度、丸めモード、指数の上下限、クランプ、拡張/サブセットのスイッチ、スティッキーなステータス、有効なトラップを保持します。すべての GDA 演算は純粋関数で、定義された結果、次のコンテキスト、発生した条件を保持する GdaOutcome を返します。チュートリアルではこのパッケージの使用例を示し、設計ページではここで述べる規則を導出します。
このパッケージは IEEE 754 のパッケージ decimal に依存しません。GDA の表面に加えて、GDA の関数の土台となるステータスを持たない下位層(DecimalContext、DecimalFlags、Decimal::*_ctx メソッド)と、Luna-Flow/arithmetic および Luna-Flow/luna-generic のトレイトへのアダプタも公開しています。
本ページを通じて、有限値は係数 と指数 を用いて と書きます。その調整済み指数は 、すなわち先頭の桁の指数です。精度 のコンテキストに対して、 は結果が取りうる最小の指数です。
Decimal 値
Decimal
Decimal は不変の GDA の数で、有限値、無限大、quiet NaN、signaling NaN のいずれかです。
pub struct Decimal {
// private fields
} derive(@debug.Debug)
有限値は指数を保持するため、2.50 と 2.5 は同じコホートの別のメンバーです。数値としては等しく比較されますが、compare_total、same_quantum、出力では異なります。ゼロは符号を持ちます。NaN は符号と非負整数のペイロードを持ちます。すべての値は精度属性(precision())も保持します。これはその値を生成したコンテキストまたはコンストラクタの精度で、GDA の演算はこれを無視して代わりにコンテキストの精度を使います。係数は永続的な十進リム配列として格納されるため、値は自由に共有できます。
Decimal::zero, Decimal::negative_zero, Decimal::one
これらはそれぞれ指数 0 の 、、 を返します。
pub fn Decimal::zero(precision? : Int) -> Self
pub fn Decimal::negative_zero(precision? : Int) -> Self
pub fn Decimal::one(precision? : Int) -> Self
precision(既定 34、最小 1 にクランプ)は格納される精度属性にすぎません。
Decimal::inf, Decimal::nan, Decimal::quiet_nan, Decimal::signaling_nan
これらは特殊値を構築します。
pub fn Decimal::inf(@def.Sign, precision? : Int) -> Self
pub fn Decimal::nan(precision? : Int) -> Self
pub fn Decimal::quiet_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::signaling_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
inf(Negative) は で、それ以外の Sign では になります。nan() はペイロード 0 の正の quiet NaN です。ペイロードは絶対値として格納されます。signaling NaN は、算術演算がそれを消費するときに InvalidOperation を発生させ、同じ符号とペイロードを持つ quiet NaN に置き換えられます。
Decimal::make
make(c, e, p) は、p 桁の有効数字に丸めて末尾のゼロを除去した を返します。
pub fn Decimal::make(@bigint.BigInt, Int, Int, mode? : @arithmetic.RoundingMode) -> Self
符号は c の符号から取られます。丸めには mode(既定 ToNearestEven)を使います。末尾のゼロが除去されるため、make(1200, 0, 34) は 1.2E+3 です。量子が重要な場合は文字列から構築してください。フラグは報告されません。
Decimal::from_int, Decimal::from_bigint, Decimal::from_double, Decimal::from_float, Decimal::from_bin_float
これらは二進値を十進に変換し、precision 桁に最近接偶数丸め(half to even)で丸めて、末尾のゼロを除去します。
pub fn Decimal::from_int(Int, precision? : Int) -> Self
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int) -> Self
pub fn Decimal::from_double(Double, precision? : Int) -> Self
pub fn Decimal::from_float(Float, precision? : Int) -> Self
pub fn Decimal::from_bin_float(@bin_float.BinFloat, precision? : Int) -> Self
precision の既定は 34(from_bin_float では引数の精度)です。 の二進浮動小数点数 はまず正確に と書かれるため、結果が precision 桁に収まるときは変換は正確です。たとえば from_double(0.1) は、 に最も近い binary64 の値を 34 桁に丸めたものです。NaN は quiet NaN になり(from_double では符号が保たれます)、無限大は符号を保ち、ゼロも符号を保ちます(from_bin_float は を返します)。from_int(100) は 1E+2 です。
Decimal::to_bin_float
to_bin_float は値を有効ビット数 precision の二進 BinFloat に丸めます。
pub fn Decimal::to_bin_float(Self, precision? : Int, mode? : @arithmetic.RoundingMode) -> @bin_float.BinFloat
precision の既定は格納された精度属性、mode の既定は ToNearestEven です。TowardNegative と TowardPositive による 2 つの結果は十進値を包みます。初等関数は認証付きの入力区間を構築するのにまさにこれを使います。ゼロは に、NaN は二進の NaN に写されます。
Decimal::parse, Decimal::from_string
これらは GDA コンテキストなしで GDA の数値文字列を読み取ります。
pub fn Decimal::parse(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_string(String, precision? : Int) -> Self?
受理される構文は GDA の数値文字列の文法です。省略可能な符号、省略可能な小数点を含む数字列、省略可能な指数 E±n、または Infinity/Inf/NaN/sNaN(大文字小文字を区別しない)と省略可能な十進の NaN ペイロードです。指数はそのまま保たれるため、from_string("2.50") の指数は です。precision(既定 34)より多くの有効数字を持つリテラルは half to even で丸められ、末尾のゼロが除去されます。不正なリテラルは Err(parse_error) または None を与えます。コンテキストの指数の上下限、フラグ、ステータス、トラップを適用する必要がある場合は、パッケージ関数 parse を使用してください。
Decimal::to_string, Decimal::output
これらは値を GDA の科学表記で、特殊値は小文字で出力します。
pub fn Decimal::to_string(Self) -> String
pub fn Decimal::output(Self, &Logger) -> Unit
pub impl Show for Decimal
かつ の有限値は指数なしで出力されます(0.000123、7.50)。それ以外では 1 桁、小数点の後に残りの桁、そして E± を出力します(1.23E+7、1E-7、0E+2)。無限大は inf/-inf、NaN は nan、snan、-nan と出力され、ペイロードがゼロでなければその後に続きます。GDA の綴り Infinity/NaN/sNaN が必要なら Decimal::to_sci_string を使用してください。
Decimal::to_sci_string, Decimal::to_eng_string
これらは DecimalContext のもとで数値文字列を変換し、GDA の to-scientific-string または to-engineering-string で出力します。
pub fn Decimal::to_sci_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_eng_string(String, DecimalContext) -> (String, DecimalFlags)
文字列は Decimal::from_string_ctx とまったく同じように変換され(コンテキストに合わせて丸め、変換フラグを返します)、その後書式化されます。工学表記は 3 の倍数の指数を使います(123E+5 は 12.3E+6 と出力されます)。特殊値は Infinity、-Infinity、NaN、sNaN とペイロード付きで出力されます。
Decimal::from_string_ctx
from_string_ctx は、ステータスを持たないコンテキストのもとでの GDA の to-number 変換です。
pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)
リテラルはコンテキストの精度に丸められ、指数範囲に照らして検査され(オーバーフロー、非正規化数、アンダーフロー、クランプ)、フラグとともに返されます。不正な入力は conversion_syntax 付きの quiet NaN を返します。拡張でないコンテキストでは、無限大と NaN はそれ自体が変換構文エラーであり、ゼロは符号と指数を失います。
///|
test "Decimal construction and printing" {
inspect(@decimal_gda.Decimal::from_string("2.50").unwrap(), content="2.50")
inspect(@decimal_gda.Decimal::from_int(100), content="1E+2")
inspect(@decimal_gda.Decimal::make(12345N, -2, 3), content="123")
inspect(@decimal_gda.Decimal::from_double(0.5), content="0.5")
inspect(@decimal_gda.Decimal::signaling_nan(payload=7N), content="snan7")
inspect(@decimal_gda.Decimal::from_string("1.2.3") is None, content="true")
let ctx = @decimal_gda.DecimalContext::new(precision=3)
let (v, flags) = @decimal_gda.Decimal::from_string_ctx("1.2345", ctx)
inspect(v, content="1.23")
inspect(flags.inexact, content="true")
let (sci, _) = @decimal_gda.Decimal::to_sci_string("-sNaN12", ctx)
inspect(sci, content="-sNaN12")
}
値の観測
Decimal::classify, Decimal::sign, Decimal::precision
これらはクラス、数値の符号、格納された精度属性を報告します。
pub fn Decimal::classify(Self) -> @arithmetic.FpClass
pub fn Decimal::sign(Self) -> @def.Sign
pub fn Decimal::precision(Self) -> Int
classify は Finite、Infinity、NaN のいずれかを返します。sign はどちらの符号のゼロと NaN に対しても Zero を、それ以外では Positive/Negative を返します。符号ビットを読むには is_negative を使用してください。
Decimal::coefficient, Decimal::magnitude, Decimal::exponent10, Decimal::quantum
これらは格納された表現 を公開します。
pub fn Decimal::coefficient(Self) -> @bigint.BigInt
pub fn Decimal::magnitude(Self) -> @bigint.BigInt
pub fn Decimal::exponent10(Self) -> Int
pub fn Decimal::quantum(Self) -> Int
coefficient と magnitude はどちらも を返します(NaN ではペイロード、無限大では 0)。exponent10 と quantum はどちらも を返します(特殊値では 0)。
Decimal::is_finite, Decimal::is_infinite, Decimal::is_nan, Decimal::is_zero, Decimal::is_negative, Decimal::is_signed, Decimal::is_negative_zero
これらはクラスと符号の述語です。
pub fn Decimal::is_finite(Self) -> Bool
pub fn Decimal::is_infinite(Self) -> Bool
pub fn Decimal::is_nan(Self) -> Bool
pub fn Decimal::is_zero(Self) -> Bool
pub fn Decimal::is_negative(Self) -> Bool
pub fn Decimal::is_signed(Self) -> Bool
pub fn Decimal::is_negative_zero(Self) -> Bool
is_negative と is_signed は同じもので、符号ビットを読むため、、、負の NaN に対して真になります。is_zero は任意の指数の有限のゼロに対して真です。
Decimal::is_quiet_nan, Decimal::is_qnan, Decimal::is_signaling_nan, Decimal::is_snan
これらは quiet NaN と signaling NaN を区別します。各組は互いの別名です。
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_qnan(Self) -> Bool
pub fn Decimal::is_signaling_nan(Self) -> Bool
pub fn Decimal::is_snan(Self) -> Bool
Decimal::is_canonical
is_canonical は常に true を返します。すべての Decimal 値は正準です(非正準になりうるのは交換エンコーディングだけです。GdaInterchange::is_canonical を参照)。
pub fn Decimal::is_canonical(Self) -> Bool
Decimal::nan_payload, Decimal::get_payload, Decimal::set_payload, Decimal::set_payload_signaling
これらは NaN のペイロードを読み取り、置き換えます。
pub fn Decimal::nan_payload(Self) -> @bigint.BigInt
pub fn Decimal::get_payload(Self) -> @bigint.BigInt
pub fn Decimal::set_payload(Self, @bigint.BigInt) -> Self
pub fn Decimal::set_payload_signaling(Self, @bigint.BigInt) -> Self
nan_payload と get_payload は NaN のペイロードを返し、それ以外の値に対しては 0 を返します。set_payload は NaN を、与えられたペイロードと同じ符号を持つ quiet NaN にし、set_payload_signaling は signaling NaN にします。どちらも NaN でない値はそのまま返します。
Decimal::is_normal, Decimal::is_subnormal, Decimal::class_name
これらは DecimalContext の指数範囲に照らして値を分類します。
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_subnormal(Self, DecimalContext) -> Bool
pub fn Decimal::class_name(Self, DecimalContext) -> String
非ゼロの有限値は、 のとき正規化数、 のとき非正規化数です。ゼロ、無限大、NaN はどちらでもありません。class_name は GDA のクラス文字列 sNaN、NaN、-Infinity、+Infinity、-Zero、+Zero、-Subnormal、+Subnormal、-Normal、+Normal のいずれかを返します。GdaContext を受け取る GDA 版はパッケージ関数 class_name、is_normal、is_subnormal です。
符号、コホート、精度の変換
Decimal::neg, Decimal::abs, Decimal::copy, Decimal::copy_abs, Decimal::copy_negate, Decimal::copy_sign
これらは符号ビットだけを変更します。signaling NaN に対しても、丸めやシグナルの発生は一切行いません。
pub fn Decimal::neg(Self) -> Self
pub fn Decimal::abs(Self) -> Self
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_abs(Self) -> Self
pub fn Decimal::copy_negate(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self
neg と copy_negate は符号を反転し、abs と copy_abs は符号をクリアし、copy は値を返し、copy_sign(x, y) は x に y の符号ビットを与えます。これらは GDA の copy 演算です。丸めを伴う版はパッケージ関数 minus、plus、abs です。
Decimal::normalized, Decimal::trim, Decimal::with_precision
これらは値をコホート内で移動するか、新しい精度属性に丸めます。
pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::trim(Self) -> Self
pub fn Decimal::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self
normalized は格納された精度に half to even で丸め、末尾のゼロをすべて除去します(7.50 は 7.5 に、1200 は 1.2E+3 になります)。trim は小数部の末尾のゼロだけを除去し、指数を正にすることはありません(7.50 は 7.5 になり、1200 は 1200 のまま)。ゼロは指数 0 の 0 になります。with_precision(p, mode) は mode で p 桁に丸め、末尾のゼロを除去して精度属性を設定します。特殊値は新しい属性を得るだけです。いずれもフラグを報告しません。
Decimal::same_quantum
same_quantum は 2 つの値が同じ指数を持つかを判定します。
pub fn Decimal::same_quantum(Self, Self) -> Bool
指数が等しい 2 つの有限値、2 つの無限大、2 つの NaN に対して真となり、それ以外では偽です。
GDA コンテキスト
GdaContext
GdaContext は不変の GDA コンテキストで、演算ポリシー、スティッキーなステータス、有効なトラップからなります。
pub struct GdaContext {
// private fields
}
ポリシーは精度 、GdaRoundingMode、、clamp、extended です。ステータスは演算によって拡大されることしかない GdaFlags 値で、トラップは GdaTrapSet です。ステータスもトラップも演算の数値結果には影響せず、次のコンテキストと、結果が Completed か Trapped かを決めるだけです。
GdaContext::new, GdaContext::try_new
これらはステータスが空のコンテキストを構築します。
pub fn GdaContext::new(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, traps? : GdaTrapSet) -> Self
pub fn GdaContext::try_new(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, traps? : GdaTrapSet) -> Result[Self, @arithmetic.ArithmeticError]
既定値:precision=34、rounding=HalfEven、e_min=-999_999_999、e_max=999_999_999、clamp=false、extended=true、トラップなし。new は precision <= 0 または e_min > e_max のとき中断し、try_new は代わりに Err(domain_error) を返します。clamp=true は交換形式と同様に指数を に制限します。extended=false は GDA のサブセット演算を選択します。 桁より長いオペランドは先に丸められ(不正確なら LostDigits を発生)、特殊値は解析できず、ゼロや一部の結果は正規化され、fma は無効になります。
GdaContext::basic, GdaContext::default, GdaContext::decimal32, GdaContext::decimal64, GdaContext::decimal128
これらは標準のコンテキストを返します。
pub fn GdaContext::basic() -> Self
pub fn GdaContext::default() -> Self
pub fn GdaContext::decimal32() -> Self
pub fn GdaContext::decimal64() -> Self
pub fn GdaContext::decimal128() -> Self
| コンテキスト | 丸め | clamp | 拡張 | トラップ | |||
|---|---|---|---|---|---|---|---|
basic, default | 9 | HalfUp | いいえ | いいえ | DivisionByZero, InvalidOperation, Overflow, Underflow, Clamped | ||
decimal32 | 7 | HalfEven | あり | あり | なし | ||
decimal64 | 16 | HalfEven | あり | あり | なし | ||
decimal128 | 34 | HalfEven | あり | あり | なし |
basic は GDA の基本既定コンテキストで、default も同じ値です。これらの値は一度だけ作られて共有されます。
context, decimal32_context, decimal64_context, decimal128_context
これらのパッケージ関数は、GdaContext::new(トラップ引数なし)と 3 つの交換形式プリセットの省略形です。
pub fn context(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool) -> GdaContext
pub fn decimal32_context() -> GdaContext
pub fn decimal64_context() -> GdaContext
pub fn decimal128_context() -> GdaContext
GdaContext::precision, GdaContext::rounding, GdaContext::e_min, GdaContext::e_max, GdaContext::clamp, GdaContext::extended, GdaContext::radix
これらは演算ポリシーを読み取ります。
pub fn GdaContext::precision(Self) -> Int
pub fn GdaContext::rounding(Self) -> GdaRoundingMode
pub fn GdaContext::e_min(Self) -> Int
pub fn GdaContext::e_max(Self) -> Int
pub fn GdaContext::clamp(Self) -> Bool
pub fn GdaContext::extended(Self) -> Bool
pub fn GdaContext::radix(Self) -> Int
radix は常に 10 を返します。
GdaContext::status, GdaContext::traps
これらはスティッキーなステータスと有効なトラップを読み取ります。
pub fn GdaContext::status(Self) -> GdaFlags
pub fn GdaContext::traps(Self) -> GdaTrapSet
GdaContext::trap, GdaContext::with_traps, GdaContext::clear_status, GdaContext::reset
これらはトラップまたはステータスを変更した新しいコンテキストを返します。レシーバは変更されません。
pub fn GdaContext::trap(Self, GdaSignal, enabled? : Bool) -> Self
pub fn GdaContext::with_traps(Self, GdaTrapSet) -> Self
pub fn GdaContext::clear_status(Self) -> Self
pub fn GdaContext::reset(Self) -> Self
trap(s) は 1 つのトラップを有効にします(enabled=false なら無効にします)。with_traps は集合全体を置き換えます。clear_status はステータスを空にしてトラップを保持し、reset は両方を空にします。
GdaRoundingMode
GdaRoundingMode は GDA の 8 つの丸めモードを列挙します。
pub(all) enum GdaRoundingMode {
HalfEven
HalfUp
HalfDown
Down
Ceiling
Floor
Up
ZeroFiveUp
}
pub fn GdaRoundingMode::equal(Self, Self) -> Bool
pub fn GdaRoundingMode::not_equal(Self, Self) -> Bool
正確な結果が隣接する 2 つの表現可能な値の間に厳密にあるとき、Down はゼロに近いほう、Up はゼロから遠いほう、Ceiling は大きいほう、Floor は小さいほうを取ります。HalfEven、HalfUp、HalfDown は近いほうを取り、ちょうど中間のときはそれぞれ最終桁が偶数になるほうへ、ゼロから遠いほうへ、ゼロに近いほうへ丸めます。ZeroFiveUp はゼロ方向に丸めますが、その結果最終桁が 0 または 5 になる場合はゼロから遠いほうへ丸めます。設計ページでは各モードを式で示しています。
シグナル、フラグ、トラップ
GdaSignal
GdaSignal は 13 個の GDA の条件を指します。
pub(all) enum GdaSignal {
ConversionSyntax
DivisionByZero
DivisionImpossible
DivisionUndefined
InvalidContext
InvalidOperation
Overflow
Underflow
Subnormal
Inexact
Rounded
Clamped
LostDigits
}
pub fn GdaSignal::equal(Self, Self) -> Bool
pub fn GdaSignal::not_equal(Self, Self) -> Bool
GDA のシグナルは Clamped、DivisionByZero、Inexact、InvalidOperation、Overflow、Rounded、Subnormal、Underflow です。ConversionSyntax、DivisionImpossible、DivisionUndefined、InvalidContext は、仕様が InvalidOperation シグナルを通じて報告する条件です。このパッケージはそれらを区別できるように、別々のフラグとトラップとして保持します。LostDigits はサブセット演算でのみ発生します。
GdaFlags
GdaFlags は条件の集合で、1 回の演算で発生した条件と、コンテキストのスティッキーなステータスの両方に使われます。
pub struct GdaFlags {
conversion_syntax : Bool
division_by_zero : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
invalid_operation : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
inexact : Bool
rounded : Bool
clamped : Bool
lost_digits : Bool
} derive(Eq)
pub fn GdaFlags::none() -> Self
pub fn GdaFlags::contains(Self, GdaSignal) -> Bool
pub fn GdaFlags::combine(Self, Self) -> Self
pub fn GdaFlags::equal(Self, Self) -> Bool
pub fn GdaFlags::not_equal(Self, Self) -> Bool
フィールドは読み取り専用です。集合は none と combine(フィールドごとの和集合)で構築します。contains(s) は s に対応するフィールドを読みますが、contains(InvalidOperation) だけは、invalid_operation、conversion_syntax、division_impossible、division_undefined、invalid_context のいずれかが設定されていれば真になります。
GdaTrapSet
GdaTrapSet は有効なトラップの集合です。
pub struct GdaTrapSet {
conversion_syntax : Bool
division_by_zero : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
invalid_operation : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
inexact : Bool
rounded : Bool
clamped : Bool
lost_digits : Bool
} derive(Eq)
pub fn GdaTrapSet::none() -> Self
pub fn GdaTrapSet::with_signal(Self, GdaSignal, enabled? : Bool) -> Self
pub fn GdaTrapSet::contains(Self, GdaSignal) -> Bool
pub fn GdaTrapSet::equal(Self, Self) -> Bool
pub fn GdaTrapSet::not_equal(Self, Self) -> Bool
with_signal(s) は 1 つのトラップを有効にします(enabled=false なら無効にします)。contains(s) は s に対応するフィールドだけをそのまま読みます。
GdaOutcome
GdaOutcome[T] はすべての GDA 演算の結果です。
pub(all) enum GdaOutcome[T] {
Completed(T, GdaContext, GdaFlags)
Trapped(GdaSignal, T, GdaContext, GdaFlags)
}
pub fn[T] GdaOutcome::value(Self[T]) -> T
pub fn[T] GdaOutcome::next_context(Self[T]) -> GdaContext
pub fn[T] GdaOutcome::raised(Self[T]) -> GdaFlags
どちらのバリアントも、GDA で定義された結果、次のコンテキスト、この演算で発生した条件を保持します。Trapped はさらに発動したトラップを示します。value、next_context、raised はマッチせずに共通のフィールドを読み取ります。
トラップの選択
すべての GDA 関数は同じ方法で終了します。 を演算が発生させた条件、 を入力コンテキストとします。
- が空なら、結果は
Completed(v, C, none)で、まったく同じコンテキストが返ります。 - そうでなければ、次のコンテキストはステータスを とした です。ここで、 が 4 つの詳細な無効条件のいずれかを含むときは
invalid_operationフラグも設定されます。 - トラップされるシグナルは、次の順序で
raised.contains(s)かつtraps.contains(s)を満たす最初の です:InvalidOperation、DivisionByZero、DivisionUndefined、DivisionImpossible、InvalidContext、ConversionSyntax、Overflow、Underflow、Subnormal、Inexact、Rounded、Clamped、LostDigits。そのようなシグナルがあれば結果はTrapped(s, v, C', R)、なければCompleted(v, C', R)です。
contains(InvalidOperation) は詳細な無効条件を包含するため、InvalidOperation のトラップはそれらすべてを捕捉し、詳細な条件自体に対するトラップより優先されます。
///|
test "GDA context, status and traps" {
let ctx = @decimal_gda.GdaContext::decimal64()
.trap(DivisionUndefined)
.trap(InvalidOperation)
let zero = @decimal_gda.Decimal::zero()
let out = @decimal_gda.divide(zero, zero, ctx) // 0/0
inspect(out.value(), content="nan")
inspect(out.raised().division_undefined, content="true")
inspect(out.raised().contains(InvalidOperation), content="true")
match out {
@decimal_gda.GdaOutcome::Trapped(signal, _, _, _) =>
inspect(signal == InvalidOperation, content="true")
@decimal_gda.GdaOutcome::Completed(_, _, _) => fail("expected a trap")
}
inspect(out.next_context().status().invalid_operation, content="true")
inspect(ctx.status() == @decimal_gda.GdaFlags::none(), content="true")
inspect(ctx.reset().traps() == @decimal_gda.GdaTrapSet::none(), content="true")
}
GDA 演算
この節のすべての関数はオペランドと GdaContext を受け取り、そのコンテキストに合わせて丸め、トラップの選択の規則で構築した GdaOutcome を返します。signaling NaN のオペランドは InvalidOperation を発生させ、対応する quiet NaN を生じます。quiet NaN のオペランドは何も発生させずに伝播します(最初の NaN のオペランドが優先されます)。サブセットコンテキスト(extended=false)では、精度より長い有限のオペランドが先に丸められます。特に断りのない限り、結果は数学的に正確な結果を一度だけ丸めたもので、結果が正確な場合は演算ごとに示す理想指数を持ちます。
parse
parse は文字列の GDA の to-number 変換です。
pub fn parse(String, GdaContext) -> GdaOutcome[Decimal]
リテラルは、精度に合わせて丸める必要があるか指数範囲にクランプする必要がない限り、その指数を保持します。不正なテキストは ConversionSyntax 付きの quiet NaN を与えます。サブセットコンテキストでは、無限大と NaN も変換構文エラーになります。
apply, plus, minus, abs
これらは 1 つのオペランドをコンテキストに合わせて丸めます。plus は 、minus は 、abs は 、apply は値をコンテキストへ単純に変換するものです。
pub fn apply(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn plus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn minus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn abs(Decimal, GdaContext) -> GdaOutcome[Decimal]
理想指数:オペランドの指数。plus、minus、abs はゼロの結果を として返します。apply はゼロの符号を保ち、サブセットのオペランドを先に丸めることはしません。
add, subtract, multiply, divide, fma
これらは基本的な算術演算です。fma(a, b, c) は 1 回の丸めによる です。
pub fn add(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn subtract(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn multiply(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn divide(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn fma(Decimal, Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
理想指数:add と subtract では 、multiply では 、divide では (不正確な商は 桁すべてを使った係数を持ちます)、fma では正確な積と加数に add の規則を適用したもの。正確なゼロの和は で、両方のオペランドが負であるかモードが Floor のときは です。特殊ケース:、、 は無効です。 は DivisionByZero 付きの 、 は DivisionUndefined 付きの NaN、 は指数 のゼロで Clamped 付きです。サブセットコンテキストでは fma は無効です。
divide_integer, remainder, remainder_near
これらは整数商を求める除算を行います。
pub fn divide_integer(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn remainder(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn remainder_near(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
divide_integer は指数 0 の を返します。remainder は ( の符号)を返します。remainder_near は を返し、 は を最も近い整数に丸めたもの(中間は偶数へ)です。剰余の理想指数は です。(または )に 桁より多くの桁が必要なとき、結果は DivisionImpossible 付きの NaN です。ゼロの除数は DivisionByZero(非ゼロの数の divide_integer)または DivisionUndefined()を与えます。ゼロの除数や無限大の被除数は両方の剰余を無効にします。有限の被除数を無限大の除数で割った剰余は被除数自身です。
quantize, rescale
これらは値を指定された指数に丸めます。
pub fn quantize(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn rescale(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
quantize(x, q) は指数 を持つ の値を返し、コンテキストのモードで丸めます(Rounded を発生させ、桁が失われれば Inexact も発生させます)。rescale(x, n) は指数 で同じことを行い、 は整数値でなければなりません。目標の指数が (サブセットコンテキストでは )の外にあるとき、結果の係数に 桁より多くの桁が必要になるとき、またはちょうど一方のオペランドだけが無限大のとき、結果は無効です。2 つの無限大からはその無限大が得られます。quantize の結果が Underflow を発生させることはありません。
to_integral_exact, to_integral_value
これらはコンテキストの丸めモードで整数に丸めます。
pub fn to_integral_exact(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn to_integral_value(Decimal, GdaContext) -> GdaOutcome[Decimal]
指数が負の値は指数 0 に quantize されます。to_integral_exact は桁が捨てられたとき Inexact と Rounded を発生させ、to_integral_value は決して発生させません。指数が の値は apply を通されるため、 桁より長ければコンテキストの精度に丸められます。11 GDA のリファレンス実装はこのようなオペランドをそのまま返します。たとえば精度 3 では 12345 を 12345 に写しますが、このパッケージは Inexact 付きで 1.23E+4 を返します。固定されたテストスイートにはそのような行はありません。
sqrt, exp, ln, log10
これらは正しく丸められた平方根、指数関数、自然対数、常用対数です。
pub fn sqrt(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn exp(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn ln(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn log10(Decimal, GdaContext) -> GdaOutcome[Decimal]
コンテキストの丸めモードにかかわらず、常に half to even で丸めます。正確な結果:完全平方数の sqrt は理想指数 を持ちます。exp(0) = 1、ln(1) = 0 であり、10 の冪 の log10 は整数 です。それ以外の有限の結果はすべて 桁の不正確な値です。定義域:負数の平方根と対数は無効で、、 であり、4 つすべてで は に写されます。exp、ln、log10 は、、、 がいずれも 999,999 以下でなければ InvalidContext を発生させます。認証付き評価が精緻化の予算内で丸めを決定できない場合、結果は InvalidOperation 付きの NaN です。サブセットコンテキストでは、ln は古典的なリファレンスアルゴリズムの結果を再現するため、正しく丸められた結果を最終桁の 1 単位だけ上回ることがあります。
power
power(x, y) は です。
pub fn power(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
整数の に対しては、結果は 桁の作業桁(サブセットコンテキストでは 1 桁少ない)を用いた二進冪乗法で計算され、その後コンテキストのモードで丸められます。 桁に収まる正確な冪は、指数 で正確に返されます。非整数の に対しては、 は正でなければならず(負の底は無効)、結果はコンテキストの丸めモードで正しく丸められていることが認証されます。 はコンテキストの丸めモードのもとで平方根として計算されます。非整数の指数には exp と同じコンテキストの制限が適用されます。特殊ケースは GDA に従います。( は無効)、 と の冪の符号は整数の指数の偶奇で決まり、 です。
reduce
reduce はコンテキストに合わせて丸め、末尾のゼロを除去します。
pub fn reduce(Decimal, GdaContext) -> GdaOutcome[Decimal]
ゼロは指数 0 の になります(拡張コンテキストでは符号を保ちます)。クランプされたコンテキストでは、指数が より大きくされることはありません。
scaleb, logb
これらは 10 の冪で拡大縮小し、調整済み指数を取り出します。
pub fn scaleb(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logb(Decimal, GdaContext) -> GdaOutcome[Decimal]
scaleb(x, n) は指数に を加えて を返します。 は指数 0 で の整数でなければならず、そうでなければ結果は無効です。その後、結果のオーバーフロー、非正規化、クランプが検査されます。logb(x) は を整数として返します。logb(0) は DivisionByZero 付きの で、logb(±∞) は です。
next_plus, next_minus, next_toward
これらは隣接する表現可能な値へ 1 ステップ移動します。
pub fn next_plus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn next_minus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn next_toward(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
next_plus はコンテキストにおいて より大きい最小の表現可能な数を、next_minus はそれより小さい最大の数を返します。ゼロからは へ移動し、最大の有限数を超えると に達します。どちらも有限の結果に対してはフラグを立てません。next_toward(x, y) は から に向かって 1 ステップ移動し(両者が等しく比較されるときは を返し、ゼロなら の符号を付けます)、ステップが正規化数の範囲を出るときは Overflow、または Underflow と Subnormal を、Inexact と Rounded とともに発生させます。
logical_and, logical_or, logical_xor, logical_invert
これらは論理オペランド、すなわち指数 0 で桁がすべて 0 か 1 の非負整数に対する桁ごとの論理演算です。
pub fn logical_and(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_or(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_xor(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_invert(Decimal, GdaContext) -> GdaOutcome[Decimal]
各オペランドはちょうど 桁として読まれます。短いオペランドは先頭をゼロで埋め、長いオペランドは下位 桁だけが使われます。logical_invert は 桁すべてを反転します。それ以外のオペランドは結果を無効にします。
shift, rotate
これらは の係数の桁を 桁の窓の中で 桁移動します。
pub fn shift(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn rotate(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
は指数 0 で の整数でなければならず、そうでなければ結果は無効です。正の は桁を左へ移動します。shift は窓からはみ出た桁を捨ててゼロで埋め、rotate はそれを反対側の端へ回り込ませます。指数と符号は変わりません。無限大の はそのまま返されます。
compare, compare_signal, compare_total, compare_total_magnitude
これらは 2 つの値を比較します。
pub fn compare(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn compare_signal(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn compare_total(Decimal, Decimal, GdaContext) -> GdaOutcome[Int]
pub fn compare_total_magnitude(Decimal, Decimal, GdaContext) -> GdaOutcome[Int]
compare は数値に従って十進の 、、 を返し(、)、オペランドが NaN のときは quiet NaN を返します(InvalidOperation を発生させるのは signaling NaN の場合だけです)。compare_signal も同じですが、すべての NaN に対して InvalidOperation を発生させます。compare_total は GDA の全順序で 、、 を返します。まず符号ビットで比較し、正の値については の順で、有限値は数値、次いで指数で(2.50 < 2.5)、NaN はペイロードで比較します。負の値では順序が逆になります。compare_total_magnitude は絶対値に全順序を適用します。全順序がフラグを立てることはありません。
max, min, max_mag, min_mag
これらは値または絶対値に対する GDA の max 演算と min 演算です。
pub fn max(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn min(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn max_mag(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn min_mag(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
quiet NaN が 1 つだけなら無視して数値のほうを採用し、quiet NaN が 2 つなら最初のものを与えます。signaling NaN は InvalidOperation 付きの quiet NaN を与えます。等しく比較される値は全順序で区別されます(したがって max(2.5, 2.50) は 2.5)。選ばれたオペランドはその後 plus と同様にコンテキストに合わせて丸められます。
class_name, is_normal, is_subnormal, same_quantum
これらはコンテキストのもとで値を分類します。条件を発生させることはないので、常に入力コンテキストとともに Completed を返します。
pub fn class_name(Decimal, GdaContext) -> GdaOutcome[String]
pub fn is_normal(Decimal, GdaContext) -> GdaOutcome[Bool]
pub fn is_subnormal(Decimal, GdaContext) -> GdaOutcome[Bool]
pub fn same_quantum(Decimal, Decimal, GdaContext) -> GdaOutcome[Bool]
これらは Decimal::class_name、Decimal::is_normal、Decimal::is_subnormal、Decimal::same_quantum を包みます。
///|
test "GDA operation sampler" {
let ctx = @decimal_gda.GdaContext::decimal64()
let d = (s : String) => @decimal_gda.Decimal::from_string(s).unwrap()
inspect(@decimal_gda.divide_integer(d("17"), d("5"), ctx).value(), content="3")
inspect(@decimal_gda.remainder(d("-17"), d("5"), ctx).value(), content="-2")
inspect(@decimal_gda.remainder_near(d("17"), d("5"), ctx).value(), content="2")
inspect(@decimal_gda.fma(d("1.5"), d("2"), d("0.25"), ctx).value(), content="3.25")
inspect(@decimal_gda.to_integral_exact(d("2.5"), ctx).value(), content="2")
inspect(@decimal_gda.rescale(d("1.2345"), d("-2"), ctx).value(), content="1.23")
inspect(@decimal_gda.reduce(d("120.00"), ctx).value(), content="1.2E+2")
inspect(@decimal_gda.scaleb(d("1.5"), d("3"), ctx).value(), content="1.5E+3")
inspect(@decimal_gda.logb(d("0.00123"), ctx).value(), content="-3")
inspect(@decimal_gda.next_plus(d("1"), ctx).value(), content="1.000000000000001")
inspect(@decimal_gda.logical_xor(d("1100"), d("1010"), ctx).value(), content="110")
inspect(@decimal_gda.shift(d("12345"), d("2"), ctx).value(), content="1234500")
inspect(@decimal_gda.rotate(d("12345"), d("-1"), @decimal_gda.context(precision=5)).value(), content="51234")
inspect(@decimal_gda.power(d("2"), d("-3"), ctx).value(), content="0.125")
inspect(@decimal_gda.max(d("2.5"), d("2.50"), ctx).value(), content="2.5")
inspect(@decimal_gda.class_name(d("-0"), ctx).value(), content="-Zero")
let wide = @decimal_gda.context() // exponent range ±999,999,999
inspect(@decimal_gda.exp(d("1"), wide).raised().invalid_context, content="true")
}
値に対する順序付けと素の演算
これらのメソッドと演算子はコンテキストを受け取りません。シグナルもトラップも発生させないので、フラグが重要な場合は GDA の関数を使用してください。
Decimal::compare, Decimal::compare_checked
compare はすべての値の上で全である数値の三方比較で、compare_checked は NaN を拒否します。
pub fn Decimal::compare(Self, Self) -> Int
pub fn Decimal::compare_checked(Self, Self) -> Result[Int, @arithmetic.ArithmeticError]
pub impl Compare for Decimal
pub impl @arithmetic.CompareChecked for Decimal
compare は有限値と無限大を として数値的に順序付け、すべての NaN を他のすべての NaN と等しく、すべての数より上に置くため、全前順序であり、ソートが中断することはありません。compare_checked は、どちらかのオペランドが NaN のとき Err(unordered_comparison) を返します。
Decimal::equal, Decimal::not_equal, Decimal::op_lt, Decimal::op_le, Decimal::op_gt, Decimal::op_ge
これらは Eq と Compare の演算子メソッドです。
pub fn Decimal::equal(Self, Self) -> Bool
pub fn Decimal::not_equal(Self, Self) -> Bool
pub fn Decimal::op_lt(Self, Self) -> Bool
pub fn Decimal::op_le(Self, Self) -> Bool
pub fn Decimal::op_gt(Self, Self) -> Bool
pub fn Decimal::op_ge(Self, Self) -> Bool
pub impl Eq for Decimal
== は有限値では数値の等価性(、)、無限大では符号の等価性であり、任意の 2 つの NaN に対して真です。<、<=、>、>= は compare に従います。
Decimal::compare_total, Decimal::compare_total_magnitude
これらは GDA の全順序を素のメソッドとしたもので、、、 を返します。
pub fn Decimal::compare_total(Self, Self) -> Int
pub fn Decimal::compare_total_magnitude(Self, Self) -> Int
これらはパッケージ関数 compare_total、compare_total_magnitude と一致します(サブセットのオペランドの丸めは行いません)。
Decimal::min, Decimal::max, Decimal::clamp, Decimal::clamp_checked
これらは丸めを行わずに値を選択します。
pub fn Decimal::min(Self, Self) -> Self
pub fn Decimal::max(Self, Self) -> Self
pub fn Decimal::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Decimal::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]
min と max は、一方が quiet NaN ならもう一方のオペランドを、signaling NaN が関わるか両方が NaN なら最初の NaN(quiet にしたもの)を、両者が等しく比較されるならレシーバを返します。clamp は値が の外にあれば min か max を、そうでなければ値を返します(NaN の値はそのまま返されます)。境界が NaN であるか min > max のときは中断し、その場合 clamp_checked は Err(domain_error) を返します。
Decimal::add, Decimal::sub, Decimal::mul, Decimal::div, Decimal::neg
これらはコンテキストなしで +、-、*、/ と単項の - を実装します。
pub fn Decimal::add(Self, Self) -> Self
pub fn Decimal::sub(Self, Self) -> Self
pub fn Decimal::mul(Self, Self) -> Self
pub fn Decimal::div(Self, Self) -> Self
pub impl Add for Decimal
pub impl Sub for Decimal
pub impl Mul for Decimal
pub impl Div for Decimal
pub impl Neg for Decimal
をオペランドの精度属性のうち大きいほうとします。+、-、/ は 桁に half to even で丸めてから末尾のゼロを除去します。* は属性 を持つ正確な積を返します(丸められることはありません)。特殊値はシグナルなしで IEEE の規則に従います。NaN のオペランドは quiet NaN を与え、、、、 は NaN を、 は符号付き無限大を、 は を与えます。neg は Decimal::neg です。
Decimal::div_checked, Decimal::sqrt
これらは、大きいほうのオペランド精度の既定コンテキストを使う checked な便利関数です。
pub fn Decimal::div_checked(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt(Self) -> Result[Self, @arithmetic.ArithmeticError]
div_checked は DecimalContext::new(precision=P) で除算し、ゼロの除数に対しては Err(division_by_zero) を、無効な除算に対しては Err(domain_error) を返します。sqrt は値自身の精度属性で平方根を求め、負のオペランドに対しては Err(domain_error) を返します。
///|
test "context-free ordering and operators" {
let d = (s : String) => @decimal_gda.Decimal::from_string(s).unwrap()
inspect(d("2.50") == d("2.5"), content="true")
inspect(d("2.50").compare_total(d("2.5")), content="-1")
inspect(@decimal_gda.Decimal::nan() == @decimal_gda.Decimal::nan(), content="true")
inspect(d("1").compare(@decimal_gda.Decimal::nan()), content="-1")
inspect(d("1").compare_checked(@decimal_gda.Decimal::nan()) is Err(_), content="true")
inspect(d("1.10") + d("2.20"), content="3.3")
inspect(d("1.10") * d("2.20"), content="2.4200")
inspect(d("1") / d("3"), content="0.3333333333333333333333333333333333")
inspect(d("5").clamp(min=d("0"), max=d("3")), content="3")
}
ステータスを持たないコンテキスト層
GDA の関数は以下のメソッドの薄いラッパーです。各関数は GdaContext のポリシーを DecimalContext に変換し、メソッドを 1 つ呼び出して、返された DecimalFlags をトラップの選択に渡します。スティッキーなステータスなしで演算ごとのフラグが欲しい場合や、この層が追加する IEEE 風の機能(IEEE 754-2019 の minimum/maximum、極小性判定の選択)を使いたい場合は、この層を直接呼び出せます。サポートされている IEEE 754 の実装はこの層ではなく decimal パッケージです。
DecimalContext
DecimalContext はステータスを持たないコンテキストで、精度、丸めモードの 2 つのビュー、指数範囲、クランプ、拡張、極小性判定からなります。
pub struct DecimalContext {
// private fields
} derive(Eq)
pub fn DecimalContext::new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Self
pub fn DecimalContext::try_new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalContext::exact() -> Self
pub fn DecimalContext::decimal32() -> Self
pub fn DecimalContext::decimal64() -> Self
pub fn DecimalContext::decimal128() -> Self
pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Self
pub fn DecimalContext::precision(Self) -> Int
pub fn DecimalContext::rounding(Self) -> @arithmetic.RoundingMode
pub fn DecimalContext::decimal_rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::with_rounding(Self, @arithmetic.RoundingMode) -> Self
pub fn DecimalContext::e_min(Self) -> Int
pub fn DecimalContext::e_max(Self) -> Int
pub fn DecimalContext::clamp(Self) -> Bool
pub fn DecimalContext::extended(Self) -> Bool
pub fn DecimalContext::tininess(Self) -> DecimalTininessDetection
pub fn DecimalContext::with_tininess(Self, DecimalTininessDetection) -> Self
pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::not_equal(Self, Self) -> Bool
既定値は GdaContext::new と同じで、rounding=ToNearestEven、tininess=BeforeRounding です。実際に使われる丸めは decimal_rounding で、その既定は rounding を変換したもの(DecimalRoundingMode::from_arithmetic)です。HalfUp、HalfDown、ZeroFiveUp を選ぶには decimal_rounding を渡してください。with_rounding は両方のビューを設定します。precision <= 0 または e_min > e_max のとき、new は中断し、try_new は Err(domain_error) を返します。exact() は精度無制限のコンテキスト(精度 0)で、結果が丸められることはありません。decimal32/64/128 は GdaContext のプリセットに一致します。from_arithmetic_context は精度、丸め、省略可能な指数の上下限(既定 )、クランプをコピーします。GDA の関数は常に BeforeRounding の極小性判定を使います。
DecimalRoundingMode
DecimalRoundingMode は、ステータスを持たない層のための、GdaRoundingMode と同じ 8 モードの集合です。
pub(all) enum DecimalRoundingMode {
HalfEven
HalfUp
HalfDown
Down
Ceiling
Floor
Up
ZeroFiveUp
} derive(Eq)
pub fn DecimalRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self
pub fn DecimalRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
pub fn DecimalRoundingMode::equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::not_equal(Self, Self) -> Bool
from_arithmetic は ToNearestEven、TowardZero、TowardPositive、TowardNegative、AwayFromZero をそれぞれ HalfEven、Down、Ceiling、Floor、Up に写します。to_arithmetic はその逆で、HalfUp、HalfDown、ZeroFiveUp に対しては None を返します。
DecimalTininessDetection
DecimalTininessDetection は、Underflow と Subnormal に関して結果を極小とみなす時点を選びます。
pub(all) enum DecimalTininessDetection {
BeforeRounding
AfterRounding
} derive(Eq)
pub fn DecimalTininessDetection::equal(Self, Self) -> Bool
pub fn DecimalTininessDetection::not_equal(Self, Self) -> Bool
BeforeRounding は正確な結果の調整済み指数を と比較し、AfterRounding は に丸めた結果を判定します。
DecimalSignal, DecimalFlags
これらは、ステータスを持たない層における演算ごとの条件名とフラグ集合です。
pub(all) enum DecimalSignal {
ConversionSyntax
DivisionByZero
DivisionImpossible
DivisionUndefined
InvalidContext
InvalidOperation
Overflow
Underflow
Subnormal
Inexact
Rounded
Clamped
LostDigits
} derive(Eq)
pub fn DecimalSignal::equal(Self, Self) -> Bool
pub fn DecimalSignal::not_equal(Self, Self) -> Bool
pub struct DecimalFlags {
inexact : Bool
rounded : Bool
lost_digits : Bool
invalid_operation : Bool
division_by_zero : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
clamped : Bool
conversion_syntax : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
} derive(Eq)
pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::contains(Self, DecimalSignal) -> Bool
pub fn DecimalFlags::has_error(Self) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::not_equal(Self, Self) -> Bool
new は空集合、combine は和集合です。GdaFlags と異なり、DecimalFlags::contains(InvalidOperation) は invalid_operation フィールドだけを読みます(この層は division_undefined や division_impossible と一緒にそれを設定しますが、conversion_syntax や invalid_context と一緒には設定しません)。has_error は、invalid_operation、division_by_zero、division_undefined、division_impossible、invalid_context のいずれかが設定されていれば真です。
Decimal のコンテキストメソッド
以下の各メソッドは同名の GDA 関数のステータスを持たない版で、与えられた DecimalContext で丸めを行い、(result, DecimalFlags) を返します。
pub fn Decimal::apply_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::plus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::abs_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::add_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sub_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::mul_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::div_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::divide_integer(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_near(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::quantize(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rescale(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_exact(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::reduce_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::scaleb_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_plus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_minus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_toward(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_and(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_or(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_xor(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_invert(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::shift_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rotate_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_signal_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_total_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::compare_total_magnitude_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::min_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
結果とフラグは、GDA 関数がその結果で報告するものとまったく同じです(GDA の関数 parse、add、subtract、multiply、fma は、小さな正確な整数オペランドに対してまず高速経路を試みますが、それが採用されるのは同じ値をフラグなしで生じる場合だけです)。
Decimal::sqrt_ctx, Decimal::exp_ctx, Decimal::ln_ctx, Decimal::log10_ctx, Decimal::power_ctx
これらはステータスを持たない初等関数です。
pub fn Decimal::sqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::ln_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::power_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
GDA の関数 sqrt、exp、ln、log10 と異なり、これらのメソッドはコンテキスト自身の丸めモードで丸めます(GDA の関数はコンテキストを half-even にしたコピーを渡します)。認証に失敗すると invalid_operation 付きの NaN になります。
Decimal::try_exp_ctx, Decimal::try_ln_ctx, Decimal::try_log10_ctx, Decimal::try_power_ctx
これらは、認証の失敗をエラーとして報告する同じ関数です。
pub fn Decimal::try_exp_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_ln_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_power_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
丸めを認証できないまま精緻化の予算(12 回の精度引き上げ)を使い切ると、演算名、目標精度、最終的な作業精度、精緻化の回数を含む Err(certification_failure(...)) を返します。定義域エラーは引き続き Ok の中で NaN とフラグとして報告されます。
Decimal::normalize_ctx, Decimal::remainder_ctx
これらは IEEE の用語のために残されている別名です。
pub fn Decimal::normalize_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
normalize_ctx は reduce_ctx です。remainder_ctx は IEEE の剰余で、remainder_near に当たります。
Decimal::minimum_ctx、Decimal::maximum_ctx とその number 版および magnitude 版
これらは IEEE 754-2019 の minimum、maximum、minimumNumber、maximumNumber、minimumMagnitude、maximumMagnitude、minimumMagnitudeNumber、maximumMagnitudeNumber 演算です。
pub fn Decimal::minimum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
素の版はどちらかのオペランドが NaN なら quiet NaN を返し、number 版はちょうど一方のオペランドが NaN なら数値のほうを返します。どちらでも signaling NaN は invalid_operation を立てます。等しい値は全順序で区別されます。*_mag_ctx という名前は *_magnitude_ctx の別名です。これらは GDA の演算ではなく、GdaContext 版はありません。
///|
test "status-free layer" {
let d = (s : String) => @decimal_gda.Decimal::from_string(s).unwrap()
let ctx = @decimal_gda.DecimalContext::new(precision=5, decimal_rounding=HalfUp)
let (q, flags) = d("2").div_ctx(d("3"), ctx)
inspect(q, content="0.66667")
inspect(flags.inexact, content="true")
inspect(flags.contains(Rounded), content="true")
let floor = @decimal_gda.DecimalContext::new(
precision=3,
rounding=TowardNegative,
e_min=-999_999,
e_max=999_999,
)
inspect(d("1").exp_ctx(floor).0, content="2.71") // context rounding
let nan = @decimal_gda.Decimal::nan()
inspect(d("1").maximum_ctx(nan, ctx).0, content="nan")
inspect(d("1").maximum_number_ctx(nan, ctx).0, content="1")
let (_, zero_div) = d("0").div_ctx(d("0"), ctx)
inspect(zero_div.has_error(), content="true")
}
交換エンコーディング
GdaInterchangeFormat
GdaInterchangeFormat は IEEE 754 の 3 つの十進交換形式を指します。
pub(all) enum GdaInterchangeFormat {
Decimal32
Decimal64
Decimal128
} derive(Eq)
pub fn GdaInterchangeFormat::context(Self) -> DecimalContext
pub fn GdaInterchangeFormat::equal(Self, Self) -> Bool
pub fn GdaInterchangeFormat::not_equal(Self, Self) -> Bool
context は対応する DecimalContext のプリセット(精度 7、16、または 34、クランプあり)を返します。
GdaInterchange
GdaInterchange は、densely packed decimal(DPD)エンコーディングによる decimal32、decimal64、または decimal128 のビットパターンです。
pub struct GdaInterchange {
// private fields
}
pub fn GdaInterchange::format(Self) -> GdaInterchangeFormat
format はパターンの形式を返します。
GdaInterchange::from_decimal, GdaInterchange::to_decimal, GdaInterchange::to_decimal_ctx
これらは値をエンコード・デコードします。
pub fn GdaInterchange::from_decimal(Decimal, GdaInterchangeFormat) -> (Self, DecimalFlags)
pub fn GdaInterchange::to_decimal(Self) -> Decimal
pub fn GdaInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)
from_decimal は値を形式に合わせて丸め(丸め、オーバーフロー、アンダーフロー、クランプのフラグを報告します)、エンコードします。to_decimal は指数を保ったまま正確にデコードし、to_decimal_ctx は非正規化数の値に対して subnormal も報告します。
GdaInterchange::from_hex, GdaInterchange::to_hex
これらはビットパターンとその 16 進テキストの間で変換を行います。
pub fn GdaInterchange::from_hex(String, GdaInterchangeFormat) -> Self?
pub fn GdaInterchange::to_hex(Self) -> String
テキストは #(入力では省略可)に続くちょうど 8、16、または 32 桁の 16 進数字です。前後の空白は無視され、それ以外の入力は None を与えます。to_hex は # と大文字の数字を出力します。
GdaInterchange::canonical, GdaInterchange::is_canonical
これらはエンコーディングを正準化します。
pub fn GdaInterchange::canonical(Self) -> Self
pub fn GdaInterchange::is_canonical(Self) -> Bool
canonical はパターンをデコードして再エンコードし、非正準な declet とペイロードを正準形に置き換えます。is_canonical はそれによってパターンが変わるかどうかを判定します。
GdaInterchange::copy, GdaInterchange::copy_abs, GdaInterchange::copy_negate, GdaInterchange::copy_sign
これらはデコードせずにエンコーディングの符号ビットを操作します。
pub fn GdaInterchange::copy(Self) -> Self
pub fn GdaInterchange::copy_abs(Self) -> Self
pub fn GdaInterchange::copy_negate(Self) -> Self
pub fn GdaInterchange::copy_sign(Self, Self) -> Self
copy_sign は 2 つのパターンの形式が異なると中断します。
Decimal::from_interchange_hex, Decimal::to_interchange_hex
これらは Decimal と 16 進テキストの間で直接行う同じ変換です。
pub fn Decimal::from_interchange_hex(String, GdaInterchangeFormat) -> Self?
pub fn Decimal::to_interchange_hex(Self, GdaInterchangeFormat) -> (String, DecimalFlags)
///|
test "DPD interchange" {
let d = (s : String) => @decimal_gda.Decimal::from_string(s).unwrap()
let (bits, flags) = @decimal_gda.GdaInterchange::from_decimal(d("1.234567890"), Decimal32)
inspect(bits.to_hex(), content="#25F4D2E8")
inspect(bits.to_decimal(), content="1.234568")
inspect(flags.inexact, content="true")
let back = @decimal_gda.Decimal::from_interchange_hex("#A2300000000003D0", Decimal64).unwrap()
inspect(back, content="-7.50")
inspect(bits.copy_negate().to_decimal(), content="-1.234568")
}
トレイト実装
Luna-Flow/arithmetic の contextual トレイト
これらはステータスを持たない層を ArithmeticContext に適合させます。
pub fn Decimal::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub impl @arithmetic.AddContextual for Decimal
pub impl @arithmetic.SubContextual for Decimal
pub impl @arithmetic.MulContextual for Decimal
pub impl @arithmetic.DivContextual for Decimal
pub impl @arithmetic.AbsContextual for Decimal
pub impl @arithmetic.SqrtContextual for Decimal
pub impl @arithmetic.ExpContextual for Decimal
各関数は DecimalContext::from_arithmetic_context でコンテキストを変換し、_ctx メソッドを呼び出して、division_by_zero が立てば Err(division_by_zero) を、それ以外のエラーフラグなら Err(domain_error) を返し、そうでなければ値と診断情報 inexact、rounded、overflow、underflow、subnormal、clamped とともに Ok を返します。
NumericFormatContextual
これらは ArithmeticContext の数値形式を記述します。
pub fn Decimal::zero_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::one_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::epsilon_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::min_normal_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::max_finite_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::classify_contextual(Self) -> @arithmetic.FpClass
pub impl @arithmetic.NumericFormatContextual for Decimal
epsilon_contextual は 、min_normal_contextual は 、max_finite_contextual は です。
checked トレイト
これらはフラグの代わりに Result を返します。
pub fn Decimal::parse_checked(String, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub impl @arithmetic.ParseChecked for Decimal
pub impl @arithmetic.SqrtChecked for Decimal
pub impl @arithmetic.PowIntChecked for Decimal
pub impl @arithmetic.PowNatChecked for Decimal
pub impl @arithmetic.DivChecked for Decimal
parse_checked はコンテキスト精度での Decimal::parse です。sqrt_checked は負のオペランドに対して Err(domain_error) を返します。pow_int_checked と pow_nat_checked は整数の指数で power_ctx を呼び出します。底がゼロで指数が負なら Err(division_by_zero) を、無効な結果なら Err(domain_error) を返し、pow_nat_checked は 999,999,999 を超える指数に対して Err(unsupported) を返します。DivChecked::div_checked は与えられたコンテキストのもとで除算し、Decimal::div_checked と同じエラーを返します。
luna-generic の代数トレイト
これらにより、ジェネリックな代数コードで Decimal を使えるようになります。
pub fn[S : @luna-generic.Nat] Decimal::from_nat(S) -> Self
pub fn[S : @luna-generic.Integral] Decimal::from_integral(S) -> Self
pub impl @luna-generic.NatHomomorphism for Decimal
pub impl @luna-generic.IntegralHomomorphism for Decimal
pub impl @luna-generic.Zero for Decimal
pub impl @luna-generic.One for Decimal
pub impl @luna-generic.AddMonoid for Decimal
pub impl @luna-generic.MulMonoid for Decimal
pub impl @luna-generic.AddGroup for Decimal
pub impl @luna-generic.Semiring for Decimal
pub impl @luna-generic.Ring for Decimal
from_nat と from_integral は BigInt を経由して Decimal::from_bigint(34 桁、末尾のゼロを除去)で変換するため、正確なのは有効数字 34 桁以下の整数に限られます。Zero::zero と One::one は Decimal::zero() と Decimal::one() です。環構造はコンテキストを使わない演算子を使います。+ はオペランドの精度に丸めるため、環の法則が正確に成り立つのは和がその精度内にとどまる間だけです。
@def.Floating, Show, Debug
Decimal は def パッケージの浮動小数点の語彙、Show(Decimal::to_string を参照)、Debug を実装します。
pub impl @def.Floating for Decimal
pub fn Decimal::to_repr(Self) -> @debug.Repr
Floating のメソッドは classify、sign、precision、with_precision、normalized で、上で説明しています。to_repr は構造的な Debug 表現です。
///|
test "trait adapters" {
let d = (s : String) => @decimal_gda.Decimal::from_string(s).unwrap()
let actx = @lf_arith.ArithmeticContext::new(4)
let out = d("2").div_contextual(d("3"), actx).unwrap()
inspect(out.value, content="0.6667")
inspect(out.diagnostics.inexact, content="true")
inspect(d("1").div_contextual(d("0"), actx) is Err(_), content="true")
inspect(@decimal_gda.Decimal::epsilon_contextual(actx), content="0.001")
inspect(d("1.5").pow_int_checked(3, actx).unwrap(), content="3.375")
inspect(@decimal_gda.Decimal::from_integral(1200), content="1.2E+3")
}
公開インターフェース全体
このスナップショットは、パッケージの生成された pkg.generated.mbti です。説明文とインターフェースが食い違う場合は、こちらが正となります。
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/decimal_gda"
import {
"Luna-Flow/arithmetic",
"Luna-Flow/floating/bin_float",
"Luna-Flow/floating/def",
"Luna-Flow/luna-generic",
"moonbitlang/core/bigint",
"moonbitlang/core/debug",
}
// Values
pub fn abs(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn add(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn apply(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn class_name(Decimal, GdaContext) -> GdaOutcome[String]
pub fn compare(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn compare_signal(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn compare_total(Decimal, Decimal, GdaContext) -> GdaOutcome[Int]
pub fn compare_total_magnitude(Decimal, Decimal, GdaContext) -> GdaOutcome[Int]
pub fn context(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool) -> GdaContext
pub fn decimal128_context() -> GdaContext
pub fn decimal32_context() -> GdaContext
pub fn decimal64_context() -> GdaContext
pub fn divide(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn divide_integer(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn exp(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn fma(Decimal, Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn is_normal(Decimal, GdaContext) -> GdaOutcome[Bool]
pub fn is_subnormal(Decimal, GdaContext) -> GdaOutcome[Bool]
pub fn ln(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn log10(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logb(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_and(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_invert(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_or(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn logical_xor(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn max(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn max_mag(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn min(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn min_mag(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn minus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn multiply(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn next_minus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn next_plus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn next_toward(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn parse(String, GdaContext) -> GdaOutcome[Decimal]
pub fn plus(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn power(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn quantize(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn reduce(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn remainder(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn remainder_near(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn rescale(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn rotate(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn same_quantum(Decimal, Decimal, GdaContext) -> GdaOutcome[Bool]
pub fn scaleb(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn shift(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn sqrt(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn subtract(Decimal, Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn to_integral_exact(Decimal, GdaContext) -> GdaOutcome[Decimal]
pub fn to_integral_value(Decimal, GdaContext) -> GdaOutcome[Decimal]
// Errors
// Types and methods
pub struct Decimal {
// private fields
} derive(@debug.Debug)
pub fn Decimal::abs(Self) -> Self
pub fn Decimal::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::abs_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::add(Self, Self) -> Self
pub fn Decimal::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::add_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::apply_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Decimal::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::class_name(Self, DecimalContext) -> String
pub fn Decimal::classify(Self) -> @arithmetic.FpClass
pub fn Decimal::classify_contextual(Self) -> @arithmetic.FpClass
pub fn Decimal::coefficient(Self) -> @bigint.BigInt
pub fn Decimal::compare(Self, Self) -> Int
pub fn Decimal::compare_checked(Self, Self) -> Result[Int, @arithmetic.ArithmeticError]
pub fn Decimal::compare_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_signal_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compare_total(Self, Self) -> Int
pub fn Decimal::compare_total_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::compare_total_magnitude(Self, Self) -> Int
pub fn Decimal::compare_total_magnitude_ctx(Self, Self, DecimalContext) -> (Int, DecimalFlags)
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_abs(Self) -> Self
pub fn Decimal::copy_negate(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self
pub fn Decimal::div(Self, Self) -> Self
pub fn Decimal::div_checked(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::div_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::divide_integer(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::epsilon_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::equal(Self, Self) -> Bool
pub fn Decimal::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::exp_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exponent10(Self) -> Int
pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int) -> Self
pub fn Decimal::from_bin_float(@bin_float.BinFloat, precision? : Int) -> Self
pub fn Decimal::from_double(Double, precision? : Int) -> Self
pub fn Decimal::from_float(Float, precision? : Int) -> Self
pub fn Decimal::from_int(Int, precision? : Int) -> Self
pub fn[S : @luna-generic.Integral] Decimal::from_integral(S) -> Self
pub fn Decimal::from_interchange_hex(String, GdaInterchangeFormat) -> Self?
pub fn[S : @luna-generic.Nat] Decimal::from_nat(S) -> Self
pub fn Decimal::from_string(String, precision? : Int) -> Self?
pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::get_payload(Self) -> @bigint.BigInt
pub fn Decimal::inf(@def.Sign, precision? : Int) -> Self
pub fn Decimal::is_canonical(Self) -> Bool
pub fn Decimal::is_finite(Self) -> Bool
pub fn Decimal::is_infinite(Self) -> Bool
pub fn Decimal::is_nan(Self) -> Bool
pub fn Decimal::is_negative(Self) -> Bool
pub fn Decimal::is_negative_zero(Self) -> Bool
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_qnan(Self) -> Bool
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_signaling_nan(Self) -> Bool
pub fn Decimal::is_signed(Self) -> Bool
pub fn Decimal::is_snan(Self) -> Bool
pub fn Decimal::is_subnormal(Self, DecimalContext) -> Bool
pub fn Decimal::is_zero(Self) -> Bool
pub fn Decimal::ln_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_and(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_invert(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_or(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logical_xor(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::magnitude(Self) -> @bigint.BigInt
pub fn Decimal::make(@bigint.BigInt, Int, Int, mode? : @arithmetic.RoundingMode) -> Self
pub fn Decimal::max(Self, Self) -> Self
pub fn Decimal::max_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::max_finite_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::max_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min(Self, Self) -> Self
pub fn Decimal::min_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_normal_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::minimum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_mag_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::mul(Self, Self) -> Self
pub fn Decimal::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::mul_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::nan(precision? : Int) -> Self
pub fn Decimal::nan_payload(Self) -> @bigint.BigInt
pub fn Decimal::neg(Self) -> Self
pub fn Decimal::negative_zero(precision? : Int) -> Self
pub fn Decimal::next_minus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_plus(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_toward(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalize_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::not_equal(Self, Self) -> Bool
pub fn Decimal::one(precision? : Int) -> Self
pub fn Decimal::one_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::op_ge(Self, Self) -> Bool
pub fn Decimal::op_gt(Self, Self) -> Bool
pub fn Decimal::op_le(Self, Self) -> Bool
pub fn Decimal::op_lt(Self, Self) -> Bool
pub fn Decimal::output(Self, &Logger) -> Unit
pub fn Decimal::parse(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::parse_checked(String, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::plus_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::power_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::precision(Self) -> Int
pub fn Decimal::quantize(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::quantum(Self) -> Int
pub fn Decimal::quiet_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::reduce_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::remainder_near(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rescale(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rotate_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::same_quantum(Self, Self) -> Bool
pub fn Decimal::scaleb_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::set_payload(Self, @bigint.BigInt) -> Self
pub fn Decimal::set_payload_signaling(Self, @bigint.BigInt) -> Self
pub fn Decimal::shift_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sign(Self) -> @def.Sign
pub fn Decimal::signaling_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int) -> Self
pub fn Decimal::sqrt(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sub(Self, Self) -> Self
pub fn Decimal::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Decimal::sub_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_bin_float(Self, precision? : Int, mode? : @arithmetic.RoundingMode) -> @bin_float.BinFloat
pub fn Decimal::to_eng_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_integral_exact(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_interchange_hex(Self, GdaInterchangeFormat) -> (String, DecimalFlags)
pub fn Decimal::to_repr(Self) -> @debug.Repr
pub fn Decimal::to_sci_string(String, DecimalContext) -> (String, DecimalFlags)
pub fn Decimal::to_string(Self) -> String
pub fn Decimal::trim(Self) -> Self
pub fn Decimal::try_exp_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_ln_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_power_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self
pub fn Decimal::zero(precision? : Int) -> Self
pub fn Decimal::zero_contextual(@arithmetic.ArithmeticContext) -> Self
pub impl @arithmetic.AbsContextual for Decimal
pub impl @arithmetic.AddContextual for Decimal
pub impl @arithmetic.CompareChecked for Decimal
pub impl @arithmetic.DivChecked for Decimal
pub impl @arithmetic.DivContextual for Decimal
pub impl @arithmetic.ExpContextual for Decimal
pub impl @arithmetic.MulContextual for Decimal
pub impl @arithmetic.NumericFormatContextual for Decimal
pub impl @arithmetic.ParseChecked for Decimal
pub impl @arithmetic.PowIntChecked for Decimal
pub impl @arithmetic.PowNatChecked for Decimal
pub impl @arithmetic.SqrtChecked for Decimal
pub impl @arithmetic.SqrtContextual for Decimal
pub impl @arithmetic.SubContextual for Decimal
pub impl @def.Floating for Decimal
pub impl @luna-generic.AddGroup for Decimal
pub impl @luna-generic.AddMonoid for Decimal
pub impl @luna-generic.IntegralHomomorphism for Decimal
pub impl @luna-generic.MulMonoid for Decimal
pub impl @luna-generic.NatHomomorphism for Decimal
pub impl @luna-generic.One for Decimal
pub impl @luna-generic.Ring for Decimal
pub impl @luna-generic.Semiring for Decimal
pub impl @luna-generic.Zero for Decimal
pub impl Add for Decimal
pub impl Compare for Decimal
pub impl Div for Decimal
pub impl Eq for Decimal
pub impl Mul for Decimal
pub impl Neg for Decimal
pub impl Show for Decimal
pub impl Sub for Decimal
pub struct DecimalContext {
// private fields
} derive(Eq)
pub fn DecimalContext::clamp(Self) -> Bool
pub fn DecimalContext::decimal128() -> Self
pub fn DecimalContext::decimal32() -> Self
pub fn DecimalContext::decimal64() -> Self
pub fn DecimalContext::decimal_rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::e_max(Self) -> Int
pub fn DecimalContext::e_min(Self) -> Int
pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::exact() -> Self
pub fn DecimalContext::extended(Self) -> Bool
pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Self
pub fn DecimalContext::new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Self
pub fn DecimalContext::not_equal(Self, Self) -> Bool
pub fn DecimalContext::precision(Self) -> Int
pub fn DecimalContext::rounding(Self) -> @arithmetic.RoundingMode
pub fn DecimalContext::tininess(Self) -> DecimalTininessDetection
pub fn DecimalContext::try_new(precision? : Int, rounding? : @arithmetic.RoundingMode, decimal_rounding? : DecimalRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, tininess? : DecimalTininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalContext::with_rounding(Self, @arithmetic.RoundingMode) -> Self
pub fn DecimalContext::with_tininess(Self, DecimalTininessDetection) -> Self
pub struct DecimalFlags {
inexact : Bool
rounded : Bool
lost_digits : Bool
invalid_operation : Bool
division_by_zero : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
clamped : Bool
conversion_syntax : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
} derive(Eq)
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::contains(Self, DecimalSignal) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::has_error(Self) -> Bool
pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::not_equal(Self, Self) -> Bool
pub(all) enum DecimalRoundingMode {
HalfEven
HalfUp
HalfDown
Down
Ceiling
Floor
Up
ZeroFiveUp
} derive(Eq)
pub fn DecimalRoundingMode::equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self
pub fn DecimalRoundingMode::not_equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
pub(all) enum DecimalSignal {
ConversionSyntax
DivisionByZero
DivisionImpossible
DivisionUndefined
InvalidContext
InvalidOperation
Overflow
Underflow
Subnormal
Inexact
Rounded
Clamped
LostDigits
} derive(Eq)
pub fn DecimalSignal::equal(Self, Self) -> Bool
pub fn DecimalSignal::not_equal(Self, Self) -> Bool
pub(all) enum DecimalTininessDetection {
BeforeRounding
AfterRounding
} derive(Eq)
pub fn DecimalTininessDetection::equal(Self, Self) -> Bool
pub fn DecimalTininessDetection::not_equal(Self, Self) -> Bool
pub struct GdaContext {
// private fields
}
pub fn GdaContext::basic() -> Self
pub fn GdaContext::clamp(Self) -> Bool
pub fn GdaContext::clear_status(Self) -> Self
pub fn GdaContext::decimal128() -> Self
pub fn GdaContext::decimal32() -> Self
pub fn GdaContext::decimal64() -> Self
pub fn GdaContext::default() -> Self
pub fn GdaContext::e_max(Self) -> Int
pub fn GdaContext::e_min(Self) -> Int
pub fn GdaContext::extended(Self) -> Bool
pub fn GdaContext::new(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, traps? : GdaTrapSet) -> Self
pub fn GdaContext::precision(Self) -> Int
pub fn GdaContext::radix(Self) -> Int
pub fn GdaContext::reset(Self) -> Self
pub fn GdaContext::rounding(Self) -> GdaRoundingMode
pub fn GdaContext::status(Self) -> GdaFlags
pub fn GdaContext::trap(Self, GdaSignal, enabled? : Bool) -> Self
pub fn GdaContext::traps(Self) -> GdaTrapSet
pub fn GdaContext::try_new(precision? : Int, rounding? : GdaRoundingMode, e_min? : Int, e_max? : Int, clamp? : Bool, extended? : Bool, traps? : GdaTrapSet) -> Result[Self, @arithmetic.ArithmeticError]
pub fn GdaContext::with_traps(Self, GdaTrapSet) -> Self
pub struct GdaFlags {
conversion_syntax : Bool
division_by_zero : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
invalid_operation : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
inexact : Bool
rounded : Bool
clamped : Bool
lost_digits : Bool
} derive(Eq)
pub fn GdaFlags::combine(Self, Self) -> Self
pub fn GdaFlags::contains(Self, GdaSignal) -> Bool
pub fn GdaFlags::equal(Self, Self) -> Bool
pub fn GdaFlags::none() -> Self
pub fn GdaFlags::not_equal(Self, Self) -> Bool
pub struct GdaInterchange {
// private fields
}
pub fn GdaInterchange::canonical(Self) -> Self
pub fn GdaInterchange::copy(Self) -> Self
pub fn GdaInterchange::copy_abs(Self) -> Self
pub fn GdaInterchange::copy_negate(Self) -> Self
pub fn GdaInterchange::copy_sign(Self, Self) -> Self
pub fn GdaInterchange::format(Self) -> GdaInterchangeFormat
pub fn GdaInterchange::from_decimal(Decimal, GdaInterchangeFormat) -> (Self, DecimalFlags)
pub fn GdaInterchange::from_hex(String, GdaInterchangeFormat) -> Self?
pub fn GdaInterchange::is_canonical(Self) -> Bool
pub fn GdaInterchange::to_decimal(Self) -> Decimal
pub fn GdaInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)
pub fn GdaInterchange::to_hex(Self) -> String
pub(all) enum GdaInterchangeFormat {
Decimal32
Decimal64
Decimal128
} derive(Eq)
pub fn GdaInterchangeFormat::context(Self) -> DecimalContext
pub fn GdaInterchangeFormat::equal(Self, Self) -> Bool
pub fn GdaInterchangeFormat::not_equal(Self, Self) -> Bool
pub(all) enum GdaOutcome[T] {
Completed(T, GdaContext, GdaFlags)
Trapped(GdaSignal, T, GdaContext, GdaFlags)
}
pub fn[T] GdaOutcome::next_context(Self[T]) -> GdaContext
pub fn[T] GdaOutcome::raised(Self[T]) -> GdaFlags
pub fn[T] GdaOutcome::value(Self[T]) -> T
pub(all) enum GdaRoundingMode {
HalfEven
HalfUp
HalfDown
Down
Ceiling
Floor
Up
ZeroFiveUp
} derive(Eq)
pub fn GdaRoundingMode::equal(Self, Self) -> Bool
pub fn GdaRoundingMode::not_equal(Self, Self) -> Bool
pub(all) enum GdaSignal {
ConversionSyntax
DivisionByZero
DivisionImpossible
DivisionUndefined
InvalidContext
InvalidOperation
Overflow
Underflow
Subnormal
Inexact
Rounded
Clamped
LostDigits
} derive(Eq)
pub fn GdaSignal::equal(Self, Self) -> Bool
pub fn GdaSignal::not_equal(Self, Self) -> Bool
pub struct GdaTrapSet {
conversion_syntax : Bool
division_by_zero : Bool
division_impossible : Bool
division_undefined : Bool
invalid_context : Bool
invalid_operation : Bool
overflow : Bool
underflow : Bool
subnormal : Bool
inexact : Bool
rounded : Bool
clamped : Bool
lost_digits : Bool
} derive(Eq)
pub fn GdaTrapSet::contains(Self, GdaSignal) -> Bool
pub fn GdaTrapSet::equal(Self, Self) -> Bool
pub fn GdaTrapSet::none() -> Self
pub fn GdaTrapSet::not_equal(Self, Self) -> Bool
pub fn GdaTrapSet::with_signal(Self, GdaSignal, enabled? : Bool) -> Self
// Type aliases
// Traits
Footnotes
-
GDA のリファレンス実装はこのようなオペランドをそのまま返します。たとえば精度 3 では
12345を12345に写しますが、このパッケージはInexact付きで1.23E+4を返します。固定されたテストスイートにはそのような行はありません。 ↩