decimal API
目的
Luna-Flow/floating/decimal は floating の IEEE 754-2019 十進浮動小数点パッケージです。Decimal は任意精度の十進値で、量子(指数)、ゼロの符号、NaN のペイロードを保持します。DecimalContext は IEEE 754-2019 の形式(精度と指数範囲)に 1 つの丸め方向属性を加えたもので、すべてのコンテキスト演算は丸められた値とそれが立てた DecimalFlags を返します。このパッケージは decimal32/64/128 交換形式を DPD と BID の両方でエンコード・デコードし、認証付き丸めで初等関数を評価します。
decimal チュートリアルでは典型的な作業を順に説明し、decimal の設計では演算モデル、エンコーディング、丸め、認証を解説します。IEEE への適合を主張する根拠となる有限の証拠は decimal の適合性に記録されています。General Decimal Arithmetic のスティッキーなステータスとトラップは別パッケージ decimal_gda にあり、decimal_checked は Decimal 演算のパイプラインのフラグを蓄積します。
インポート
moon.pkg にパッケージを追加します。
import {
"Luna-Flow/floating/decimal",
}
例ではパッケージを別名 @decimal. で呼び出します。一部の例では、Luna-Flow/floating/def(共有の RoundingMode と Sign)に @def.、Luna-Flow/arithmetic に @lf_arith.、Luna-Flow/luna-generic に @lf_alg.、moonbitlang/core/bigint に @bigint. も使います。そのような例をコピーするときは、これらのパッケージもインポートしてください。ほとんどの例は局所的な補助関数 d(s) で値を作ります。これは @decimal.Decimal::from_string(s).unwrap() です。
記法
以下で用いる記法:有限値は符号 、非負整数の係数 、指数(量子) により と表されます。 はコンテキストの精度、 と は調整済み指数 に対するコンテキストの指数の上下限、 は非正規化数の最小の指数です。
値と表現
Decimal
Decimal は不変の十進浮動小数点値です。
pub struct Decimal {
// private fields
} derive(@debug.Debug)
Decimal は次のいずれかです:有限値 ( を含む)、、または符号と非負整数のペイロードを持つ quiet NaN か signaling NaN。すべての値は作業用の precision も持ち、これは素の演算子やコンテキスト引数を持たない変換で使われます。フィールドは非公開なので、以下のオブザーバーを使用してください。数学的な値が同じで指数が異なる 2 つの値(たとえば 1.2 と 1.20)は同じコホートの別のメンバーです。数値としては等しく比較されますが、quantum、same_quantum、total_order_compare、書式化、交換エンコーディングでは区別されます。
導出された Debug 実装は Decimal::to_repr として公開されています。トレイト実装を参照してください。
Decimal::precision, coefficient, exponent10, quantum
これらのオブザーバーは、値の格納された表現を返します。
pub fn Decimal::precision(Self) -> Int32
pub fn Decimal::coefficient(Self) -> @bigint.BigInt
pub fn Decimal::exponent10(Self) -> Int32
precision は値に保持される作業精度である。コンテキストが持ち得る形式の精度であり、範囲は 1..=999999999(decimal_precision_max)。Decimal を返す構築関数は、この範囲外の精度で関数名を示して中断し、Result を返す演算は Err を返す。coefficient は非負の係数 を返す。NaN ではペイロード、無限大では 0 を返す。符号は係数には含まれない。is_sign_minus を使うこと。exponent10 は保持された指数 を返し、特殊値では 0 である。IEEE 754-2019 の演算 quantum は下の quantum_ctx であり、アクセサではない。
///|
test "decimal representation observers" {
let x = @decimal.Decimal::from_string("-12.300").unwrap()
inspect(x.coefficient(), content="12300")
inspect(x.exponent10(), content="-3")
inspect(x.is_sign_minus(), content="true")
inspect(x.precision(), content="34")
}
Decimal::signum, is_sign_minus
これらのオブザーバーは値の符号を報告します。
pub fn Decimal::signum(Self) -> @def.Sign
pub fn Decimal::is_sign_minus(Self) -> Bool
signum は両方のゼロとすべての NaN に対して @def.Sign::Zero を返し、それ以外は Negative/Positive を返します。is_negative は保存された符号ビットを返すので、、、負の NaN で true になります。
Decimal::classify, class_of
classify は値の粗い分類を返し、class_of はコンテキストの下での IEEE 754-2019 の 5.7.2 項の 10 値の分類を返します。
pub fn Decimal::classify(Self) -> @arithmetic.FpClass
pub fn Decimal::class_of(Self, DecimalContext) -> @def.IeeeClass
classify は Finite、Infinity、NaN のいずれかを返します。class_of は 10 個の IeeeClass の値のいずれかを返し、正規/非正規の区別にはコンテキストの を使います。文字列形式はありません。IeeeClass を match してください(以前の class_name の文字列は "sNaN"、"NaN"、"+Zero" などでした)。
Decimal::is_finite, is_infinite, is_nan, is_zero, is_negative_zero, is_quiet_nan, is_signaling_nan, is_canonical, is_normal, is_subnormal
これらの述語は値のクラスを判定します。
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_zero(Self) -> Bool
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_signaling_nan(Self) -> Bool
pub fn Decimal::is_canonical(Self) -> Bool
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_subnormal(Self, DecimalContext) -> Bool
is_canonical は常に true を返します。Decimal には非正準な形がなく、非正準なエンコーディングは DecimalInterchange の性質です。コンテキストの下で、値が有限・非ゼロで調整後指数が 以上なら正規、有限・非ゼロで調整後指数が 未満なら非正規です。ゼロ、無限大、NaN はどちらでもありません。
Decimal::nan_payload, get_payload, set_payload, 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 は NaN のペイロードを返し、それ以外の値には 0 を返します。get_payload は IEEE 754-2019 §9.7 の getPayload です。NaN にはそのペイロードを、それ以外の値には -1 を返します。set_payload と set_payload_signaling は setPayload と setPayloadSignaling です。引数が precision - 1 桁(レシーバーの precision、交換形式の NaN の仮数部と同じ)以下の非負整数であれば、結果はそのペイロードとレシーバーの符号ビットを持つ静かな(それぞれシグナリング)NaN で、そうでなければ指数 0 の +0 です。結果はレシーバーが NaN かどうかに依存しません。
構築と変換
decimal_value_e_max, decimal_value_e_tiny
格納された有限値の限界。
pub let decimal_value_e_max : Int
pub let decimal_value_e_tiny : Int
有限の Decimal は、exponent + digits - 1 <= decimal_value_e_max(最大の調整指数 。零は 1 桁として数える)かつ exponent >= decimal_value_e_tiny(最小の指数 )を満たす値だけを保持する。これらは普通の演算子の非公開の作業コンテキストの e_max と etiny であり、e_max、e_min、etiny = e_min - p + 1 がすべて 32 ビットの指数フィールドで表せなければならないときに、そのフィールドが許す最大値と最小値である。そのため、格納された任意の値で x + 0 == x、x - 0 == x、x * 1 == x が成り立つ。厳密な構築関数(make、try_make、parse、from_string)は範囲外の値を拒否する。整数、浮動小数点数、2 進浮動小数点数からの構築関数は範囲外の値を生み出し得ない。丸めを行う演算(普通の演算子、with_precision)は、コンテキストの結果と同様に、無限大または丸め方向の最大有限値へオーバーフローするか、最小指数へアンダーフローする。これらはコンテキストの限界(decimal_context_e_max_limit、下記)ではない。コンテキストは格納できる範囲より狭く、あらゆるコンテキストの範囲の外にある値も格納でき、コンテキスト演算がそれを読むときに丸められる。
Decimal::make, try_make
make は符号付き整数の係数と指数から有限値を作り、ある精度に丸める。try_make はその Result 形式である。
pub fn Decimal::make(@bigint.BigInt, Int, Int, mode? : DecimalRoundingMode) -> Self
pub fn Decimal::try_make(@bigint.BigInt, Int, Int, mode? : DecimalRoundingMode) -> Result[Self, @arithmetic.ArithmeticError]
Decimal::make(c, q, p, mode~) は を表す。符号は c から取る。係数が p 桁以下ならば指数 q を保つ(要求されたコホートの成員は簡約されない:make(100, 0, 5) は 100、make(0, 5, 5) は 0E+5)。それより長い係数は mode(既定は RoundTiesToEven)でちょうど p 桁に丸められ、簡約されない(make(1000000, 0, 3) は 100E+4)。コンテキストの指数範囲は適用されないが、値は格納範囲の内側でなければならず、丸めの後で検査される。make は指数と二つの限界を示して中断し、try_make は定義域エラーを返す(p が 1..=999999999 の外にある場合もエラーを返す)。
Decimal::zero, negative_zero, one, inf, nan, quiet_nan, signaling_nan
これらのコンストラクタは特殊値と単位値を構築します。
pub fn Decimal::zero(precision? : Int) -> Self
pub fn Decimal::negative_zero(precision? : Int) -> Self
pub fn Decimal::one(precision? : Int) -> Self
pub fn Decimal::inf(negative? : Bool, 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
既定の精度は 34 である。zero、negative_zero、one の指数は 0 である。inf(negative=true) は 、inf() は である。nan はペイロード 0 の正の quiet NaN であり、quiet_nan と signaling_nan は既定でペイロード 0・正の符号である。ペイロードは仮数部の末尾フィールド(IEEE 754-2019 3.5.2)であり、precision - 1 桁以下の非負整数でなければならず、そうでなければ構築関数は中断する。より狭い形式への変換ではペイロードの下位の桁が保たれ、構築では切り捨てない。精度は 1..=999999999 の範囲内でなければならない。
Decimal::from_int, from_bigint
これらのコンストラクタは整数を変換します。
pub fn Decimal::from_int(Int, precision? : Int) -> Self
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int) -> Self
どちらも既定の精度 34 で convertFromInt(IEEE 754-2019 §5.4.1、優先指数 0)を実装します。precision 桁以下の整数は指数 0 を保つので、from_int(1000) は縮約された 1E+3 ではなく 1000 です。それより長い整数はちょうど precision 桁に half-even で丸められる(§5.2)ので、from_int(99999, precision=3) は 1.00E+5 です。ゼロは指数 0 の です。
Decimal::from_double, from_float
これらのコンストラクタは二進浮動小数点数を変換します。
pub fn Decimal::from_double(Double, precision? : Int) -> Self
pub fn Decimal::from_float(Float, precision? : Int) -> Self
有限の Double はすべて二進有理数 であり、したがって のとき有限の十進展開 を持ちます。変換はこの正確な展開を構成し、それが precision 桁(既定 34)に収まるときは、優先指数 0 に最も近い指数で返します(from_double(0.5) は 0.5、from_double(100.0) は 100)。そうでなければ、可能な最小の指数、つまりちょうど precision 桁に half-even で丸めます(IEEE 754-2019 §5.2)。from_double(0.1, precision=16) は 0.1000000000000000 です。符号付きゼロと無限大は保存され、NaN はすべて入力の符号を持つペイロード 0 の quiet NaN になります。from_float はまず Double に拡張しますが、これは正確です。
Decimal::from_binary, to_binary
これらの関数は Decimal と二進の Binary の間で変換を行います。
pub fn Decimal::from_binary(@binary.Binary, precision~ : Int, mode? : DecimalRoundingMode) -> Self
pub fn Decimal::to_binary(Self, precision~ : Int, mode? : @binary.BinaryRoundingMode) -> @binary.Binary
from_binary(x, precision~, mode~) は、x の十進展開が precision 桁に収まるときは正確で、指数は from_double と同じく 0 に最も近いものになります。そうでなければ mode(既定 RoundTiesToEven、結果の基数の丸めの型)でちょうど precision 桁に一度だけ丸められます。精度は必須で、十進の桁数で数えます。以前は既定で x のビット数でしたが、それは種類の違う数え方でした。二進のゼロは符号を保ち(IEEE 754-2019 §5.4.2 と §6.3 の要求どおり は になります)、NaN はペイロード 0 の quiet NaN になります。to_binary(precision~, mode~) は、正確な十進値を mode(IEEE 754-2019 4.3.1 の五つの丸め方向属性のいずれか、既定 RoundTiesToEven)で precision ビットの Binary に一度だけ丸めます。精度は必須で、ビットで数え、1 から @binary.binary_precision_max までです。範囲外では呼び出しは中止します(以前は既定で十進値の桁数でした)。ほとんどの十進小数は二進有理数ではないため、この方向の変換は通常不正確です。RoundTowardNegative と RoundTowardPositive で変換すると、十進値を包む二進の包含区間が得られます。ゼロは符号を保ち、NaN のペイロードは保持されません。decimal_gda にも同じ変換があり、十進の結果には GdaRoundingMode を使います。
Decimal::convert_format, from_binary_ctx, to_binary_ctx
これらの関数はフラグ付きの IEEE 754-2019 convertFormat(§5.4.2)で、十進形式間および基数間の変換に使います。
pub fn Decimal::convert_format(Self, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn Decimal::from_binary_ctx(@binary.Binary, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_binary_ctx(Self, @binary.BinaryContext) -> (@binary.Binary, @binary.BinaryFlags)
convert_format(format) は decimal32、decimal64、decimal128 への変換です。値はその形式の精度と指数範囲へ、最近接偶数で一度だけ丸められ、その丸めのフラグが付きます。優先指数は元の量子です(「十進形式間の変換では、優先指数は Q(source) である」)。より広い形式への変換は正確で、同値類のメンバーを保ち、より狭い形式への変換は丸められ、オーバーフローやアンダーフローが起こり得て、大きな指数は折り畳まれます。from_binary_ctx(x, ctx) は二進浮動小数点数の正確な値を十進コンテキスト(精度、指数範囲、方向)の下で一度だけ丸め、その丸めのフラグを付けます。正確な変換の優先指数は 0 です(数字を保持できる 0 に最も近い指数で、0.5 は 5E-1、96 は 96 です)。不正確な変換は precision 桁になります(「優先指数は可能な限り小さい」)。指数範囲を超える値や、範囲をはるかに下回る値は、その桁を作らずにオーバーフローまたはアンダーフローします。範囲内の値はどの二進指数でも正しく丸めて変換され、コストは指数に応じて増えません。二進指数が を超える場合は NaN と invalid_operation で拒否されます。to_binary_ctx(ctx) は正確な十進値を BinaryContext(binary16 から binary128、または任意の精度と範囲)の下で一度だけ丸め、BinaryFlags(inexact、overflow、underflow)を返します。これは Binary::from_string_ctx の変換であり、任意の指数に対して正しく丸められます。ゼロはどの方向でも符号を保ちます。シグナリング NaN は静かな NaN と無効操作例外を返します。NaN の符号は保たれ、宛先が保持できる場合はペイロードも保たれます(§6.2.3)。十進形式では p - 1 桁、二進形式では p - 2 ビットで、それ以外は下位の桁またはビットが残ります。from_binary と to_binary は変更されません。
FromNat と FromInteger の実装
Decimal は luna-generic の trait FromNat と FromInteger を実装しています。これは自然数と整数からの標準的な写像です。Decimal::from_natural や Decimal::from_integer というメソッドはありません。Decimal::from_bigint(n)(指数 0、その整数のコホート)か trait の関数を呼んでください。
trait の関数は精度 34 で from_bigint(n).normalized() を返します。つまり末尾のゼロが取り除かれます。他の Luna-Flow の整数型を変換するには、先に Integral::normalize でその代表元を取るか、lift_to を使ってください。
解析と書式化
Decimal::from_string
from_string は量子を保ったまま十進テキストを Decimal に変換します。
pub fn Decimal::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
受理される構文は、省略可能な符号、省略可能な小数点を含む数字列、省略可能な符号付きの省略可能な指数 E/e、または Inf、Infinity、NaN、sNaN(大文字小文字は問わない)のいずれかで、NaN の場合はその後に省略可能な十進のペイロード数字が続きます。変換は半偶丸めで precision(既定値 34)桁に一度だけ丸め、精度と表現が許す限り優先指数を保ちます。たとえば、"1.2300" の係数は 12300、指数は です。精度 3 では "1.0001" は 1.00 に丸められ、正確な "1.000" も係数が 4 桁で収まらないため 1.00 になります。精度 3 では "10001" は 1.00E+4 に丸められます。無効なテキストに対しては Err(parse_error) を返します。
コンテキストの指数範囲は適用されない。限界は格納範囲のものである。値の指数は少なくとも decimal_value_e_tiny()、調整指数は高々 decimal_value_e_max()でなければならず、precision への丸めの後(桁上がりを含む)に検査され、零も任意の有限値と同様に扱われる。値がこれらの外にあるテキストは、置き換えられることなく拒否される。from_string は定義域エラーを返し、エラーは指数と二つの限界を示す("1e3000000000"、"12e2147483647"、"0e-2147483646" は拒否される。精度 3 の "1249e-2147483646" は 1.25E-2147483643 で、丸めの後の指数は範囲内にある)。丸められた値(無限大、零)や overflow、underflow フラグが必要なときは、そのテキストを from_string_ctx で読むこと。
Decimal::from_string_ctx
from_string_ctx はコンテキストのもとでテキストを変換し、変換フラグを報告します。
pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)
構文は from_string と同じです。値はコンテキストの精度に丸められ(非ゼロの桁が捨てられると inexact が立ちます)、指数範囲に対して検査され(オーバーフロー、アンダーフロー)、折り畳まれます。NaN のペイロードの桁数がその形式の許す桁数(精度 桁)を超える場合は構文エラーです。無効なテキストは invalid_operation 付きの静かな NaN を返します。
///|
test "decimal from_string_ctx rounds and flags" {
let ctx = @decimal.DecimalContext::decimal32()
let (x, flags) = @decimal.Decimal::from_string_ctx("3.14159265", ctx)
inspect(x, content="3.141593")
inspect(flags.inexact(), content="true")
let (bad, bad_flags) = @decimal.Decimal::from_string_ctx("1..2", ctx)
inspect(bad.is_nan(), content="true")
inspect(bad_flags.invalid_operation(), content="true")
}
Decimal::to_sci_string, to_eng_string
これらの関数は、値に対する General Decimal Arithmetic の to-scientific-string 変換と to-engineering-string 変換を実装します。
pub fn Decimal::to_sci_string(Self) -> String
pub fn Decimal::to_eng_string(Self) -> String
どちらも呼び出された値を書式化します。コンテキストの下でテキストを変換するには、まず from_string_ctx で読みます。これは変換のフラグも返します(Decimal::from_string_ctx("1000000000", ctx).0.to_sci_string())。科学表記は、指数が正であるか調整済み指数が 未満のときは係数を指数 E±n 付きで書き、それ以外では通常の数字で書きます。工学表記は 3 の倍数の指数を使います。特殊値は Infinity、-Infinity、NaN、sNaN と書かれ、ペイロードがあれば NaN7 のようになります。
コンテキストを伴わない値は Decimal::to_string(Show 実装)で書式化され、同じ科学表記の規則を使います。Show と Debug を参照してください。
コンテキスト
DecimalContext
DecimalContext は演算パラメータの不変な集合です。
pub struct DecimalContext {
// private fields
} derive(Eq)
コンテキストは、精度 と指数範囲 ()からなる IEEE 754-2019 の形式(§3.3)に、1 つの丸め方向属性(rounding、DecimalRoundingMode)を加えたものです。コンテキスト演算の有限の結果はすべてその形式の要素です。その指数 は を満たすので となり(形式の要請どおり大きな指数は引き下げられます)、極小性は丸めの前に検出されます(§7.5)。これらにオプションはありません。どの演算も環境の状態を読みません。すべてのコンテキスト演算は、コンテキストを引数として受け取ります。
decimal_context_e_max_limit, decimal_context_e_min_limit, decimal_precision_max
DecimalContext::try_new が受け付けるコンテキストパラメーターの限界です。
pub let decimal_context_e_max_limit : Int
pub let decimal_context_e_min_limit : Int
pub let decimal_precision_max : Int
値は 、(、コンテキストの最小の )、 で、decNumber decContext.h の制限です(decimal_context_e_min_limit は 0.12 より前は でした)。try_new と new は precision と e_max をこれらの定数と照合します(precision は 1..=decimal_precision_max、e_max は 1..=decimal_context_e_max_limit)。そのため、値が検証からずれることはありません。これらが制限するのはコンテキストだけで、認証済みの初等関数には、より低い独自の制限( かつ )があり、Elementary functions に記載されています。
DecimalContext::new, try_new
new は精度と e_max から IEEE 754-2019 十進形式のコンテキストを作り、無効なら中止します。try_new は同じパラメーターを受け取り Result を返します。
pub fn DecimalContext::new(precision? : Int, e_max? : Int, rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::try_new(precision? : Int, e_max? : Int, rounding? : DecimalRoundingMode) -> Result[Self, @arithmetic.ArithmeticError]
| パラメータ | 既定値 | 意味 |
|---|---|---|
precision | 34 | 係数の桁数 |
e_max | 最大指数 。 は です | |
rounding | RoundTiesToEven | 丸め方向属性(IEEE 754-2019 §4.3) |
precision は 1..=999,999,999、e_max は 1..=999,999,999 の範囲でなければなりません。e_max の既定値は IEEE 754-2019 §3.7 に従います。精度だけで与えられる拡張可能な形式は、51 桁以上で を必要とし、999,999 はこのパッケージのすべての演算が動作する最も広い範囲です。したがって new() は decimal128 ではなく形式 であり、decimal128 には decimal128() を使ってください。精度が 999,999 を超える場合は既定の範囲がありません(1000 が制限を超えます)。e_max を渡してください。try_new は無効なフィールドを示す Err(domain_error) を返し、new は BinaryContext::new と同様にそのフィールドを示すメッセージで中止するので、外部から来るパラメーターには try_new を使ってください。§3.7 の NOTE 3 は が少なくとも 2 であるべきだと述べていますが、このライブラリは を満たす最小の値である 1 を受け入れます(§3.3)。
丸めのパラメータは 1 つだけです。有限の結果、無限大、およびコンテキストのその他の用途はすべてこれで丸められ、rounding() が報告するのは実際に適用されるモードそのものです。GDA の商業丸め(round-half-up)は RoundTiesToAway です。GDA の round-half-down、round-up、round-05up は IEEE 754-2019 の十進形式の属性ではなく、decimal_gda にのみ存在します。コンテキストには clamp、extended、tininess の設定も無制限の精度(exact() は廃止されました)もありません。IEEE 形式は常にその量子の指数範囲を持ち、General Decimal Arithmetic 付録の部分集合の算術は IEEE 形式ではなく、厳密な結果は桁を収めるのに十分な精度で得られます(digits(a) + digits(b) 桁のコンテキストと、積の指数以上の e_max により mul_ctx は厳密になります)。
DecimalContext::decimal32, decimal64, decimal128
これらのコンストラクターは IEEE 754-2019 交換形式のコンテキストを返します(§3.6)。
pub fn DecimalContext::decimal32(rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::decimal64(rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::decimal128(rounding? : DecimalRoundingMode) -> Self
| コンテキスト | |||
|---|---|---|---|
decimal32 | 7 | 96 | |
decimal64 | 16 | 384 | |
decimal128 | 34 | 6144 |
3 つとも既定では RoundTiesToEven を使います(別の属性にするには rounding~ を渡してください)。
DecimalContext::from_arithmetic_context
from_arithmetic_context は Luna-Flow 共通のコンテキストを変換します。
pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
精度と丸めはコピーされ、clamp は無視されます(これはすべての IEEE 形式の性質であり、arithmetic パッケージの既定値は false です)。指定された e_max は使われ、指定された e_min は 1 - e_max に等しくなければ、変換は Err(domain_error) を返します。e_min だけが指定されると e_max = 1 - e_min になり、どちらも指定されなければ new の既定の範囲になります。変換は AwayFromZero(§4.3 の属性ではありません)に対しても、精度や e_max が範囲外のときも Err(domain_error) を返します。GDA 1.70 自体は固定の制限を設けておらず、これらは採用された decNumber decContext.h の制限です。
DecimalContext::precision, rounding, e_min, e_max
これらのアクセサはコンテキストのフィールドを返します。
pub fn DecimalContext::precision(Self) -> Int
pub fn DecimalContext::rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::e_min(Self) -> Int
pub fn DecimalContext::e_max(Self) -> Int
e_min は常に 1 - e_max です。
DecimalContext::refinement_limit, DecimalContext::with_refinement_limit
認証付き初等関数の精緻化の上限を読み書きします。
pub fn DecimalContext::refinement_limit(Self) -> Int32?
pub fn DecimalContext::with_refinement_limit(Self, Int32?) -> Self
認証付きの初等関数は、両端の丸め結果が一致するまで、作業精度を増やしながら包含を評価します。上限は評価回数です。Some(n) は n 回まで許し(1 未満の値は 1 として扱います)、既定は Some(12)、None は回数の上限を外します。判定できないまま上限に達すると、try_*_ctx は従来どおり精緻化回数付きの CertificationFailure エラーを返し、素の形式と *_ctx 形式は invalid_operation を伴う NaN を返します。None では、作業精度が上限(8,000,000 ビットと最初の作業精度の 256 倍の大きい方)を超えるとループが停止します。既定値はどの結果も変えません。このフィールドは == の対象で、上限だけが異なる二つの文脈は別物です。
///|
test "a refinement limit makes a hard-to-round result fail" {
let context = @decimal.DecimalContext::new(precision=34, e_max=999_999)
inspect(context.refinement_limit() == Some(12), content="true")
// exp(5E-34) lies just above the midpoint 1 + 5E-34 at 34 digits.
let x = @decimal.Decimal::from_string("5E-34", precision=34).unwrap()
let short = context.with_refinement_limit(Some(1))
inspect(x.try_exp_ctx(short) is Err(_), content="true")
let unlimited = context.with_refinement_limit(None)
inspect(x.try_exp_ctx(unlimited) is Ok(_), content="true")
}
DecimalContext::elementary_precision_limit, DecimalContext::with_elementary_precision_limit
初等関数と pow 系列の精度の上限を読み取り、設定します。工学的な上限からの脱出口です。
pub fn DecimalContext::elementary_precision_limit(Self) -> Int32?
pub fn DecimalContext::with_elementary_precision_limit(Self, Int32?) -> Self
Some(n) は、精度が n 桁を超えるコンテキストでの通常のオペランドをすぐに拒否します(not_computed、try_ 形式では Err)。既定値は Some(999_999) で、None は上限を外します。既定値はライブラリが決めた上限であり、演算そのものの性質ではありません。これを超えると、ライブラリは実行時間もメモリも制限せず、その範囲は適合性ゲートの対象外で、何も保証しません。結果は同じ認証済みカーネルから得られるので、返された値は引き続き正しく丸められています。例えば pow(2, 0.5)(平方根)は 100,000 桁で 0.6 秒、1,000,000 桁で 14.7 秒、10,000,000 桁で 300 秒超かかりました(リリースビルド、負荷のあるマシン)。認証済みカーネルが作業精度を表現できない場合(80,807,093 桁超)、それを通る関数は上限にかかわらずコンテキスト制限エラーを返します。pow の平方根の経路(指数 0.5、sqrt_ctx)と正確な経路はそこでは拒否されず、実行が続きます。IEEE 754-2019 §9.2.1 が挙げる場合は、上限にかかわらず値です。このフィールドは == に加わり(細化上限と同じ)、with_precision、with_e_max、with_rounding はこれを保ちます。
///|
test "the precision limit of the elementary functions" {
let context = @decimal.DecimalContext::new(precision=101)
inspect(context.elementary_precision_limit() == Some(999_999), content="true")
let low = context.with_elementary_precision_limit(Some(100))
let two = @decimal.Decimal::from_int(2)
inspect(two.try_pow_ctx(@decimal.Decimal::from_int(3), low) is Err(_), content="true")
let open = low.with_elementary_precision_limit(None)
inspect(two.pow_ctx(@decimal.Decimal::from_int(3), open).0.to_string(), content="8")
}
DecimalContext::with_precision, with_e_max, with_rounding
これらの関数はコンテキストを派生させます。
pub fn DecimalContext::with_precision(Self, Int) -> Self
pub fn DecimalContext::with_e_max(Self, Int) -> Self
pub fn DecimalContext::with_rounding(Self, DecimalRoundingMode) -> Self
with_precision は精度を、with_e_max は指数範囲を置き換えます(e_min はそれに従います)。どちらも new の制限の外では中止します。with_rounding は丸め方向属性を置き換えます。
丸めモード
DecimalRoundingMode
DecimalRoundingMode は、十進形式が持つ IEEE 754-2019 §4.3 の 5 つの丸め方向属性を、BinaryRoundingMode と同じ綴りで列挙します。
pub(all) enum DecimalRoundingMode {
RoundTiesToEven
RoundTiesToAway
RoundTowardZero
RoundTowardPositive
RoundTowardNegative
}
が隣接する 2 つの表現可能な係数 と (最終桁の単位で)の間に厳密にあるとします。RoundTowardZero は を返します。RoundTowardPositive と RoundTowardNegative は 方向と 方向に丸めます(したがって符号に依存します)。RoundTiesToEven と RoundTiesToAway は 2 つのうち近いほうを返し、ちょうど中間のときはそれぞれ偶数の係数へ、ゼロから遠いほうへ丸めます。カーネルにはコンテキストから選べない作業用モードが 3 つあります(HalfDown、Up、ZeroFiveUp:除算の二重丸め用ガード桁と、認証済み関数の方向付き境界)。これらは内部用です。
DecimalRoundingMode::from_arithmetic, to_arithmetic
これらの関数は、各丸め方向属性と共通の @arithmetic.RoundingMode の間で対応付けを行います。
pub fn DecimalRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self?
pub fn DecimalRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
@arithmetic.RoundingMode | DecimalRoundingMode |
|---|---|
ToNearestEven | RoundTiesToEven |
TowardZero | RoundTowardZero |
TowardPositive | RoundTowardPositive |
TowardNegative | RoundTowardNegative |
AwayFromZero | なし(from_arithmetic は None を返します) |
to_arithmetic は、共通の列挙型に存在しない RoundTiesToAway に対して None を返します。DecimalContext::from_arithmetic_context と各 _contextual 形式は AwayFromZero に対して Err を返します。
どのコンテキストでも、微小性は丸めの前に検出されます(IEEE 754-2019 §7.5:「十進形式では、微小性は丸めの前に検出される」)。正確な絶対値が を下回る非ゼロの結果は、最終的に返される値にかかわらず微小です。微小な結果は不正確なとき underflow を立てます。二進形式風の丸め後の規則を選ぶオプションはありません。
ステータスフラグ
DecimalFlags
DecimalFlags は 1 回の演算で発生した条件を記録します。
pub struct DecimalFlags {
// private fields
} derive(Eq)
| フィールド | 立つ条件 |
|---|---|
inexact | 結果が正確な結果と異なる |
underflow | 結果が極小かつ不正確である |
overflow | 丸めた結果の調整済み指数が を超える |
division_by_zero | 有限のオペランドから厳密な無限大の結果が生じた(、、、、、、、、、、) |
invalid_operation | 有用に定義できる結果がない場合(シグナリング NaN、、、、不正な quantize、数でないテキスト、初等関数がサポートする範囲外のコンテキスト) |
not_computed | 実装の限界内でライブラリが計算できなかった結果(初等カーネルを超えるコンテキスト、その範囲を超えるオペランド、作業上限を超える指数の隔たりを持つ厳密な和、結論に至らなかった認証)です。値は NaN で、invalid_operation は立たず、try_ 形式は Err(認証失敗の種類)を返します |
これらは IEEE 754-2019 の 7.2 から 7.6 の五つのフラグと not_computed です。General Decimal Arithmetic のフラグ rounded、subnormal、clamped、lost_digits、conversion_syntax、division_impossible、division_undefined、invalid_context は decimal には含まれず、decimal_gda が保持します。
フィールドは非公開です。各フラグは同名のメソッドで読み取ります(例: flags.inexact()、flags.division_by_zero())。フラグが暗黙に蓄積されることはありません。
DecimalFlags::new, combine, has_error
これらの関数はフラグ集合を作成、統合、照会します。
pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::has_error(Self) -> Bool
new はすべてのフラグが下りた状態です。combine はフィールドごとの OR なので、結合的、可換、冪等であり、new() が単位元です。has_error は
つまり IEEE 754-2019 が使える数を返さない条件です(7.2:無効操作は「有用に定義できる結果がない」)。したがって、invalid_operation を立てる失敗した from_string_ctx もエラーに数えられます。has_error は overflow、underflow、inexact を含みません。これらは使える結果を返します(IEEE 754-2019 の 7.4 から 7.6 がそれを定めており、ゼロ除算については 7.3 が同様に定めています)。division_by_zero が集合に入っているのは、Luna-Flow/arithmetic の checked 形式がゼロ除算に Err を返せるようにするためだけです。
///|
test "decimal flags accumulate by combine" {
let ctx = @decimal.DecimalContext::decimal64()
let one = @decimal.Decimal::one()
let three = @decimal.Decimal::from_int(3)
let (third, f1) = one.div_ctx(three, ctx)
let (_, f2) = one.div_ctx(@decimal.Decimal::zero(), ctx)
let all = f1.combine(f2)
inspect(third, content="0.3333333333333333")
inspect(all.inexact(), content="true")
inspect(all.division_by_zero(), content="true")
inspect(all.has_error(), content="true")
}
コンテキストを使わない素の演算
このグループの演算子と関数はコンテキストを受け取らず、フラグも返しません。正確な計算や、Luna-Flow の代数トレイト上のジェネリックなコードには便利です。丸め、指数範囲、フラグが重要な場合は、常にコンテキスト演算を使用してください。
Decimal::add, sub, mul, div, 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 fn Decimal::neg(Self) -> Self
各演算子は、対応するコンテキスト演算(add_ctx、sub_ctx、mul_ctx、div_ctx)を非公開の作業コンテキストで実行し、フラグを捨てたものである。そのコンテキストは、オペランドの精度フィールドのうち大きい方の精度 、偶数への最近接丸め、値の格納範囲(decimal_value_e_max、 と decimal_value_e_tiny、)を持ち、折り返しは行わない。結果の精度フィールドは である。検査付き除算は trait メソッド DivChecked::div_checked(a, b, ctx) です(parse_checked と検査付き trait を参照)。固有の Decimal::div_checked はありません。
- 正確な結果は、優先指数に最も近いコホートの成員を取る(IEEE 754-2019 5.4.1:
addとsubは 、mulは 、divは )。1.20 + 3.40は4.60、6.0 / 2は3.0、1.25 * 2.50は3.1250、1.20 - 1.20は0.00である。 - 不正確な結果はちょうど 桁(最小の指数、5.2)で、簡約されない。7 桁の精度では
1 / 3は0.3333333であり、5 桁の値二つの積は 5 桁に丸められる。積は以前は厳密に、最大 桁で返されていた。 negは、ゼロと NaN を含むすべての値の符号ビットを反転します。
特殊値はコンテキスト演算に従う。NaN オペランドは最初の NaN のペイロードを持つ quiet NaN を与える。、、、 は NaN を与える。 は正確な商の符号を持つ無限大である(零の符号も数える:1 / -0 は )。零の積の符号は各符号の排他的論理和である。有限値 は作業コンテキストの最小の指数での符号付き零である。作業範囲を超える結果はそのコンテキストのオーバーフロー、すなわち無限大であり、範囲を下回る結果は最小の指数へ偶数への最近接丸めで丸められ、符号付き零になり得る(1E+2147483646 * 1E+2147483646 は inf、123E-2147483640 * 1E-10 は 0E-2147483645)。この範囲内の有限値では、どの指数でも x + 0 == x、x - 0 == x、x * 1 == x が成り立つ。和または積はその値であり、 桁でそれを保持できる、優先指数に最も近いコホートの成員である。
///|
test "decimal plain operators" {
let a = @decimal.Decimal::from_string("1.20").unwrap()
let b = @decimal.Decimal::from_string("3.40").unwrap()
inspect(a + b, content="4.60")
inspect(a * b, content="4.0800")
inspect(a - b, content="-2.20")
inspect(-a, content="-1.20")
inspect(@decimal.Decimal::one() / @decimal.Decimal::from_int(8), content="0.125")
}
Decimal::abs, neg, copy, copy_sign
これらの関数は符号ビットだけを変更します。
pub fn Decimal::abs(Self) -> Self
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self
これらは丸めず、フラグも立てず、指数、ペイロード、NaN の種類を保ちます。abs は符号を消し、neg は符号を反転し、copy_sign は 2 番目のオペランドの符号ビットをコピーし、copy は引数を返します。
Decimal::normalized, with_precision
これらの関数はコホートのメンバーまたは精度フィールドを変更します。
pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::with_precision(Self, Int, DecimalRoundingMode) -> Self
normalized は同値類の簡約メンバーを返します(末尾のゼロをすべて除き、ゼロの指数は 0)。係数がより長い場合は、その値自身の精度へ偶数丸めで丸めます。これが末尾のゼロを取り除く唯一の方法です。IEEE 754-2019 にはそのための演算がないため、decimal には reduce_ctx も trim もなくなりました(x.apply_ctx(ctx).0.normalized() が従来の reduce_ctx です)。with_precision(p, mode) は有限値を mode で p 桁に丸め、簡約し、p を精度フィールドとして保存します。特殊値は新しい精度フィールドだけを受け取ります。いずれもフラグを立てません。
Decimal::sqrt
sqrt は値をそれ自身の形式の下で平方根にします。
pub fn Decimal::sqrt(Self) -> Self
sqrt は普通の演算子の作業コンテキスト(精度 )での sqrt_ctx であり、負の非零オペランドには NaN を返す(IEEE 754-2019 7.2。sqrt_checked はこれを Err として報告する)。どちらも偶数への最近接丸めで正しく丸められる。
コンテキスト演算
このグループのすべての関数は DecimalContext を受け取り、(result, flags) を返します。結果は、正確な結果をコンテキストの十進丸めモードでコンテキストの精度に一度だけ丸めたもので、その後に指数範囲に照らして検査されます。オーバーフローでは設計ページにある丸めモード依存の結果が得られ、正確な絶対値が 未満の結果は非正規化数の格子 に直接丸められ(正規の結果は、正確な指数が 未満であっても 桁にのみ丸められます)、大きな指数は まで引き下げられます。正確な結果が収まる場合、指数はその演算の優先指数になるため、コホートが情報を運びます。NaN のオペランドは、最初の NaN の符号とペイロードを持つ quiet NaN として伝播します(ペイロードは下位 桁に切り詰められます。from_string_ctx や交換形式のエンコーディングと同じです)。signaling NaN のオペランドがあれば invalid_operation が立ちます。
アンダーフローの閾値付近では、一度だけの丸めが重要です。decimal32 では、正確な積 3.000001E-45 * 1.500001E-45 は で、正確な指数が を下回る正規数です。これは七桁へ一度だけ丸められ、4.500005E-90 になります。商 1 / 1.9999999999998E+101 は で、非正規化数です。ガード付きの商がグリッド へ一度だけ丸められ、inexact と underflow 付きで 1E-101 になります。
Decimal::add_ctx, sub_ctx, mul_ctx, div_ctx
これらの関数は正しく丸められた算術演算です。
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)
優先指数:加算と減算では 、乗算では 、除算では です。正確な商は優先指数に最も近いメンバーで返され、不正確な商は 桁を持ちます。ただし非正規化数の商は で終わります。ゼロの和は です。ただし Floor のもと(どちらかのオペランドが負なら )や、両方のオペランドが の場合は除きます。
特殊な場合:、、 は invalid_operation 付きの NaN を返します。 は invalid_operation 付きの NaN を返します。有限の非ゼロ に対する は division_by_zero 付きの符号付き無限大を返します。有限値 は指数 の符号付きゼロを返します。
add_ctx または sub_ctx の一方のオペランドが和のすべての丸め境界より完全に下にある場合、この演算はそれを桁ごとに揃えません。そのオペランドは、それらの境界のすぐ下にある同じ符号のスティッキーな単位に置き換えられ、和は一度だけ丸められます(設計を参照)。精度 7 では、1598617.000000000001 - 0.000000000002 は Down で 1598616、6.0000005E-73 + 1E-101 は HalfEven で 6.000001E-73 です。
///|
test "decimal context results are rounded once" {
let c32 = @decimal.DecimalContext::decimal32()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("3.000001E-45").mul_ctx(d("1.500001E-45"), c32).0, content="4.500005E-90")
let (q, flags) = d("1").div_ctx(d("1.9999999999998E+101"), c32)
inspect(q, content="1E-101")
inspect(flags.underflow(), content="true")
let down = @decimal.DecimalContext::new(precision=7, rounding=@decimal.DecimalRoundingMode::RoundTowardZero)
inspect(
d("1598617.000000000001").add_ctx(d("-0.000000000002"), down).0,
content="1598616",
)
}
///|
test "decimal context arithmetic keeps preferred exponents" {
let ctx = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("1.20").add_ctx(d("3.40"), ctx).0, content="4.60")
inspect(d("1.25").mul_ctx(d("2.50"), ctx).0, content="3.1250")
inspect(d("2.400").div_ctx(d("1.2"), ctx).0, content="2.00")
let (q, flags) = d("2").div_ctx(d("3"), ctx)
inspect(q, content="0.6666666666666667")
inspect(flags.inexact(), content="true")
}
Decimal::fma_ctx
fma_ctx は を 1 回の丸めで計算します。
pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)
積は正確に作られ、z に正確に加えられます。丸められるのは和だけです。z が数または無限大のとき、 は無効です。z が quiet NaN のときは結果はその NaN で、invalid_operation は立ちません(IEEE 754-2019 §7.2 はこのケースを実装に委ねています)。符号が逆の は無効です。
Decimal::sqrt_ctx
sqrt_ctx は正しく丸められた平方根を返します。
pub fn Decimal::sqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
優先指数は です。正確な根はそれに最も近いメンバーで返されます(sqrt(0.0400) は 0.20)。不正確な根は 桁で、inexact を立てます。 です。負の非ゼロのオペランドや は invalid_operation 付きの NaN を返します。 です。
Decimal::abs_ctx, apply_ctx
これらの関数は 1 つのオペランドをコンテキストに合わせて丸めます。
pub fn Decimal::abs_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::apply_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
apply_ctx は値をコンテキストの精度と指数範囲へ丸め( を超える指数は折り返されます)、NaN を静かにし、ゼロの符号を保ちます。従来の plus_ctx を置き換えます(minus_ctx は neg の後に apply_ctx を行うものです)。abs_ctx はコンテキストへ丸めた です。シグナリング NaN は invalid_operation を立てます。
Decimal::remainder_ctx
この関数は IEEE の剰余を計算します。
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
remainder_ctx(x, y) は です。ここで は を最近接の整数へ丸めたもの(同点は偶数へ)です(IEEE 754 の remainder。その GDA での名前は remainder-near で、decimal_gda が保持します)。剰余は収まる場合は正確で、優先指数は です。剰余がゼロのときの符号は のものです。 と は無効です( も同様です)。 です。
///|
test "decimal remainders" {
let ctx = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("10").remainder_ctx(d("6"), ctx).0, content="-2")
inspect(d("-7.5").remainder_ctx(d("2"), ctx).0, content="0.5")
}
量子と指数の演算
Decimal::quantum_ctx
quantum_ctx は IEEE 754-2019 §5.3.2 の演算 quantum です。
pub fn Decimal::quantum_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
有限の x では、結果は数 、つまり で、 は x の指数です(ゼロも含みます)。したがって quantum_ctx(1.2300) は 0.0001 です。優先指数は で、正確な結果がそれを持ちます。無限大の x では、符号にかかわらず結果は で、例外はありません。
Decimal::quantize_ctx
quantize_ctx は値を別の値の指数に合わせて丸めます。
pub fn Decimal::quantize_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
x.quantize_ctx(y, ctx) は指数 を持つ x の値を返し、桁が捨てられるときはコンテキストのモードで丸めます(捨てた桁が非ゼロなら inexact を立てます)。目標指数が の外にある場合、結果の係数が 桁を超える場合、その調整指数が を超える場合、またはちょうど一方のオペランドだけが無限大の場合、結果は invalid_operation 付きの NaN です。二つの無限大は x の無限大を返します。量子は同値類の範囲内の別の値へ黙って変わることはありません。結果が指数 を持てなければ、演算は失敗します。唯一の例外は折り畳みです。 にある目標指数は受け入れられ、結果は他のすべての結果と同様に指数 へ折り畳まれます(decimal64 で 1E+384 を 1E+384 に量子化すると 1.000000000000000E+384 になります)。
///|
test "decimal quantize_ctx to cents" {
let ctx = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
let (cents, flags) = d("12.3456").quantize_ctx(d("0.01"), ctx)
inspect(cents, content="12.35")
inspect(flags.inexact(), content="true")
let small = @decimal.DecimalContext::new(precision=3, e_max=100)
let (bad, bad_flags) = d("999.9").quantize_ctx(d("0.1"), small)
inspect(bad.is_nan(), content="true")
inspect(bad_flags.invalid_operation(), content="true")
}
Decimal::same_quantum
same_quantum は 2 つの値が同じ指数を持つかを判定します。
pub fn Decimal::same_quantum(Self, Self) -> Bool
2 つの有限値は指数が等しいとき同じ量子を持ちます。2 つの無限大どうし、2 つの NaN どうしは常に同じ量子を持ち、それ以外の組は同じ量子を持ちません。フラグを立てることはありません。
Decimal::to_integral_exact_ctx, to_integral_value_ctx
これらの関数は整数に丸めます。
pub fn Decimal::to_integral_exact_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
指数が の有限値はすでに整数であり、 桁より長くてもそのまま返されます(形式の折り畳みはその指数に引き続き適用されます)。指数が負の値は、コンテキストの丸めモードで、作業精度 により指数 0 へ量子化されるので、整数部分が 桁に丸められることはありません。精度 3 では 12345.6 は 12346 になります。to_integral_exact_ctx は非ゼロの桁が捨てられると inexact を報告し、to_integral_value_ctx は同じ値を inexact を下ろして返します。無限大はそのまま返され、NaN は静かにされます。
IEEE 754 §5.9 はコンテキストの形式に属する(高々 桁の)オペランドに対して roundToIntegral を定義しており、そのようなオペランドでは上記の結果がその結果です。 桁より長いオペランドはこの形式の値ではないため §5.9 の対象外であり、結果は実装定義です。そのようなオペランドについて上で述べた振る舞い(より長い整数はそのまま、より長い小数は 桁で quantize)は、パッケージが選んだ GDA 流の振る舞いです。General Decimal Arithmetic はオペランド自身の精度で整数値に丸めます。
Decimal::to_int_ctx, to_int64_ctx, to_uint_ctx, to_uint64_ctx
これらの関数は IEEE 754-2019 の convertToInteger(§5.4.1、§5.8)で、十進数を文脈の丸め方向で固定幅の整数に丸めます。
pub fn Decimal::to_int_ctx(Self, DecimalContext, exact? : Bool) -> (Int32?, DecimalFlags)
pub fn Decimal::to_int64_ctx(Self, DecimalContext, exact? : Bool) -> (Int64?, DecimalFlags)
pub fn Decimal::to_uint_ctx(Self, DecimalContext, exact? : Bool) -> (UInt32?, DecimalFlags)
pub fn Decimal::to_uint64_ctx(Self, DecimalContext, exact? : Bool) -> (UInt64?, DecimalFlags)
同名の Binary の関数と同じ形です。値は文脈の rounding で整数に丸められます。偶数への最近接、ゼロ方向、正方向、負方向、ゼロから遠い側への最近接が §5.8 の五つの方向です。NaN(quiet でも signaling でも)、無限大、整数型の範囲外の値は None と invalid_operation を返します。負の値がゼロに丸まる結果は 0 で(符号なしの型でも同じ)、それ以外の負の値は符号なしの型では範囲外です。exact=true(convertToIntegerExact)では丸めで値が変わると inexact が立ち、指定しなければ有効な変換のフラグは空です。文脈の精度と指数範囲は関係しません。型に収まる限り、何桁の整数でも厳密に変換されます。変換は指数に対応する 10 の冪を作りません。1E+999999 はすぐに範囲外になり、1E-999999 はすぐにゼロ(遠い側への方向では 1 単位)に丸まります。
Decimal::scaleb_ctx, logb_ctx
これらの関数は 10 の冪で拡大縮小し、調整済み指数を取り出します。
pub fn Decimal::scaleb_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
x.scaleb_ctx(n, ctx) は指数に を加えて を返します。 は指数 0 で を満たす有限の整数でなければならず、そうでなければ結果は invalid_operation 付きの NaN です(IEEE 754-2019 5.3.3 は scaleB を整数の個数に対してのみ定義し、整数でない第二オペランドは、無限大を含め、言語に委ねています。 の上限は GDA の scaleb の規則で、Binary::scaleb_ctx はより大きな個数を代わりにクランプします)。スケールされた値は、他のすべてのコンテキスト結果と同様に一度だけ丸められます。 桁より長い係数は 桁へ丸められ(decimal64 で 12345678901234567890 を 0 でスケールすると inexact 付きで 1.234567890123457E+19)、非正規化数の結果は へ丸められ、オーバーフローは丸めモードに依存する結果を overflow と inexact 付きで返し(decimal64 で TowardZero のとき、9E+384 を 1 でスケールすると 9.999999999999999E+384)、大きな指数は折り畳まれます。ゼロは符号を保ち、その指数は範囲内にクランプされます。decimal64 で 0 を 700 でスケールすると 0E+369 になります。
///|
test "decimal scaleb rounds like other context results" {
let c64 = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
let toward_zero = c64.with_rounding(@decimal.DecimalRoundingMode::RoundTowardZero)
inspect(d("9E+384").scaleb_ctx(d("1"), toward_zero).0, content="9.999999999999999E+384")
inspect(d("9E+384").scaleb_ctx(d("1"), c64).0, content="inf")
let (zero, flags) = d("0").scaleb_ctx(d("700"), c64)
inspect(zero, content="0E+369")
inspect(flags.inexact(), content="false")
inspect(d("12345678901234567890").scaleb_ctx(d("0"), c64).0, content="1.234567890123457E+19")
}
logb_ctx(x) は調整済み指数 を整数の Decimal として返します。 で division_by_zero が立ち、 です。
Adjacent value
Decimal::next_up_ctx, next_down_ctx
これらの関数は隣接する表現可能な値を返します。
pub fn Decimal::next_up_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_down_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
next_up_ctx はコンテキスト内で x より大きい最小の表現可能値、next_down_ctx は x より小さい最大の表現可能値で、 までの非正規化数と最大の有限値 を含みます。next_up_ctx(-∞) は最も小さい(最も負の)有限値です。有限の結果ではフラグを立てません。IEEE 754-2019 5.3.1 が定義するのは nextUp と nextDown だけです。GDA 1.70 の next-toward 演算は decimal_gda の next_toward であり、このパッケージには next_toward_ctx はありません。
///|
test "decimal neighbours of one" {
let ctx = @decimal.DecimalContext::decimal64()
let one = @decimal.Decimal::one()
inspect(one.next_up_ctx(ctx).0, content="1.000000000000001")
inspect(one.next_down_ctx(ctx).0, content="0.9999999999999999")
}
比較と順序
Decimal::compare
compare は、Compare、==、比較演算子が使う数値の三方比較です。
pub fn Decimal::compare(Self, Self) -> Int
compare は数値に従って 、0、1 を返し、 であり、コホートのすべてのメンバーは等しくなります。NaN には数値の順序がないため、Compare が全前順序であり続ける(ソートが中断しない)ように、すべての NaN は他のすべての NaN と等しく、すべての非 NaN より大きいと比較されます。equal(==)は compare と一致し、NaN == NaN は true です。これは IEEE の等価性ではありません。NaN を順序付けできないものとして扱う必要がある場合は、compare_checked、compare_ctx、または NaN の述語を使用してください。演算子メソッドはトレイト実装に挙げています。
///|
test "decimal numeric order is a total preorder" {
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("1.0") == d("1.00"), content="true")
inspect(d("-0").compare(d("0")), content="0")
inspect(@decimal.Decimal::nan().compare(d("1E+999")), content="1")
let sorted = [d("2"), @decimal.Decimal::nan(), d("-1")]
sorted.sort()
inspect(sorted.map(fn(x) { x.to_string() }).join(" "), content="-1 2 nan")
}
Decimal::compare_checked
compare_checked は NaN をエラーとする IEEE の数値比較です。
pub fn Decimal::compare_checked(Self, Self) -> Result[Int, @arithmetic.ArithmeticError]
どちらのオペランドも NaN でなければ Ok(compare(x, y)) を、そうでなければ Err(unordered_comparison) を返します。これは CompareChecked の実装です。
Decimal::compare_quiet, compare_signaling
IEEE 754-2019 5.11 の比較。フラグ付きの四値の関係として返します。
pub fn Decimal::compare_quiet(Self, Self) -> (@def.PartialOrder, DecimalFlags)
pub fn Decimal::compare_signaling(Self, Self) -> (@def.PartialOrder, DecimalFlags)
関係は Less、Equal、Greater、Unordered(いずれかのオペランドが NaN)のいずれかで、 であり、同じコホートのすべてのメンバーは等しいとされます。quiet 形式は signaling NaN に対してのみ invalid_operation を立て、signaling 形式は順序づけ不能な比較のすべてで立てます。これらは Binary が持つ関数で、compare_ctx と compare_signal_ctx に置き換わります。後者は Decimal の 、0、1 または NaN を返しており、IEEE ではなく General Decimal Arithmetic の結果でした。
Decimal::compare_quiet_equal とその他の比較述語
IEEE 754-2019 の表 5.1 と表 5.2 の述語のうち Binary が持つもの。
pub fn Decimal::compare_quiet_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less_equal(Self, Self) -> (Bool, DecimalFlags)
どの述語も compare_quiet または compare_signaling から定義され、そのフラグを返します。compare_quiet_unordered 以外のすべての述語は、順序づけ不能な組に対して false です。
Decimal::compare_quiet_not_equal と表 5.1・表 5.2 のその他の比較述語
上に挙げていない IEEE 754-2019 5.11 の残り 15 個の述語。
pub fn Decimal::compare_quiet_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_greater_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_greater_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_ordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_less(Self, Self) -> (Bool, DecimalFlags)
5.11 条は 22 個の述語を挙げており、表 5.1(一般的な数学記号付き)に 10 個、表 5.2 に 12 個あります。上の七つと合わせて、そのすべてに関数があります。どの述語も、真となる関係を通して compare_quiet または compare_signaling から定義され(表の定義の仕方と同じです)、その比較のフラグを返します。quiet 述語は signaling NaN に対してのみ invalid_operation を立て、signaling 述語はすべての NaN オペランドで立てます。各述語のドキュメントコメントは表の行を示します。名前の綴りは上の七つに従い、compare_、quiet または signaling、続いて表の述語名のスネークケースです。標準が互いの否定として挙げる組(表の同じ行の二つの述語)は、反対の値と同じフラグを返します。
| 表 | 述語 | 真となる関係 |
|---|---|---|
| 5.1 | Decimal::compare_quiet_equal (compareQuietEqual) | 等しい |
| 5.1 | Decimal::compare_quiet_not_equal (compareQuietNotEqual) | 小なり、大なり、順序づけ不能 |
| 5.1 | Decimal::compare_signaling_greater (compareSignalingGreater) | 大なり |
| 5.1 | Decimal::compare_signaling_not_greater (compareSignalingNotGreater) | 小なり、等しい、順序づけ不能 |
| 5.1 | Decimal::compare_signaling_greater_equal (compareSignalingGreaterEqual) | 等しい、大なり |
| 5.1 | Decimal::compare_signaling_less_unordered (compareSignalingLessUnordered) | 小なり、順序づけ不能 |
| 5.1 | Decimal::compare_signaling_less (compareSignalingLess) | 小なり |
| 5.1 | Decimal::compare_signaling_not_less (compareSignalingNotLess) | 等しい、大なり、順序づけ不能 |
| 5.1 | Decimal::compare_signaling_less_equal (compareSignalingLessEqual) | 小なり、等しい |
| 5.1 | Decimal::compare_signaling_greater_unordered (compareSignalingGreaterUnordered) | 大なり、順序づけ不能 |
| 5.2 | Decimal::compare_signaling_equal (compareSignalingEqual) | 等しい |
| 5.2 | Decimal::compare_signaling_not_equal (compareSignalingNotEqual) | 小なり、大なり、順序づけ不能 |
| 5.2 | Decimal::compare_quiet_greater (compareQuietGreater) | 大なり |
| 5.2 | Decimal::compare_quiet_not_greater (compareQuietNotGreater) | 小なり、等しい、順序づけ不能 |
| 5.2 | Decimal::compare_quiet_greater_equal (compareQuietGreaterEqual) | 等しい、大なり |
| 5.2 | Decimal::compare_quiet_less_unordered (compareQuietLessUnordered) | 小なり、順序づけ不能 |
| 5.2 | Decimal::compare_quiet_less (compareQuietLess) | 小なり |
| 5.2 | Decimal::compare_quiet_not_less (compareQuietNotLess) | 等しい、大なり、順序づけ不能 |
| 5.2 | Decimal::compare_quiet_less_equal (compareQuietLessEqual) | 小なり、等しい |
| 5.2 | Decimal::compare_quiet_greater_unordered (compareQuietGreaterUnordered) | 大なり、順序づけ不能 |
| 5.2 | Decimal::compare_quiet_unordered (compareQuietUnordered) | 順序づけ不能 |
| 5.2 | Decimal::compare_quiet_ordered (compareQuietOrdered) | 小なり、等しい、大なり |
Decimal::total_order, total_order_mag, total_order_compare
これらの関数は IEEE 754-2019 §5.10 の totalOrder と totalOrderMag の述語と、同じ順序の三方比較の形を実装します。
pub fn Decimal::total_order(Self, Self) -> Bool
pub fn Decimal::total_order_mag(Self, Self) -> Bool
pub fn Decimal::total_order_compare(Self, Self) -> Int
x が y と同じかそれより前に並ぶとき total_order(x, y) は true で、total_order_compare(x, y) は同じ順序について -1、0、1 を返します。この順序はすべての表現を対象とします。
値が等しい有限値は指数で並べます。正の値では指数が小さい方が先()、負の値では大きい方が先です。符号と種類が同じ NaN はペイロードで並べます(負の NaN では逆順)。total_order_compare は同一の表現に対してだけ 0 を返します。total_order_mag(x, y) は絶対値の total_order です。どれもコンテキストを取らず、丸めず、フラグも立てません。
Decimal::identical
identical は二つの値が同一のデータであるかを判定する。
pub fn Decimal::identical(Self, Self) -> Bool
x.identical(y) は、クラス、符号、シグナリングビット、係数(NaN ではペイロード)、指数、精度ラベルがすべて等しいときに真となる。値を比較する ==(1.20 == 1.2)より細かく、精度ラベルを無視する total_order_compare よりも細かい。1.20 と 1.2 は同一ではなく、零とその負の零も同一ではなく、ペイロードが異なる二つの NaN も同一ではない。
///|
test "decimal identical compares the representation" {
let a = @decimal.Decimal::from_string("1.20").unwrap()
inspect(a.identical(@decimal.Decimal::from_string("1.20").unwrap()), content="true")
inspect(a.identical(@decimal.Decimal::from_string("1.2").unwrap()), content="false")
inspect(a == @decimal.Decimal::from_string("1.2").unwrap(), content="true")
}
Decimal::min, max, clamp, 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 のときはもう一方のオペランドを、両方が NaN かどちらかが signaling のときは quiet NaN を、等しいときはレシーバを返します。clamp は範囲より下なら min、上なら max、それ以外では値(NaN を含む)を返します。境界が NaN であるか min > max のときは中断します。clamp_checked はそれらの場合に Err(domain_error) を返します。
Decimal::minimum_ctx, maximum_ctx, minimum_number_ctx, maximum_number_ctx, minimum_magnitude_ctx, maximum_magnitude_ctx, minimum_magnitude_number_ctx, maximum_magnitude_number_ctx
この 8 個の関数は IEEE 754-2019 §9.6 の最小値・最大値演算です。General Decimal Arithmetic の min、max、min-magnitude、max-magnitude は decimal_gda にあります。
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_magnitude_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
minimum_ctx と maximum_ctx は NaN を伝播します。NaN のオペランドがあれば静かな NaN を返します。_number_ の変種は、ちょうど一方のオペランドだけが NaN のとき数を返します。どちらでもシグナリング NaN は invalid_operation を立てます。大きさの変種は と を比べ、大きさが等しいときは符号付きの順序に戻ります。等しい場合は total_order_compare で決まるので です。選ばれた値はコンテキストに丸められます。
初等関数
すべての初等関数には 2 つの形があります。f_ctx(x, ctx) は (result, flags) を返します。try_f_ctx(x, ctx) は同じ組を Ok で返すか、結果を認証できなかったときは Err を返します。その ArithmeticError の certification_failure_detail() は、演算、目標精度、使い切った精緻化の予算を示します。認証に失敗すると、f_ctx は not_computed 付きの NaN を返し、try_f_ctx は認証失敗の種類の Err を返します。
超越関数の結果は認証付きです。実装は interval で の保証付き包含区間を評価し、両端点が同じフラグで同じ Decimal に丸められるときにだけそれを受け入れます(設計を参照)。丸めは単調なので、受け入れられた結果はすべての DecimalRoundingMode で を丸めたものです。正確なケースの一覧(、、、、、、、rootn_ctx(0.008, 3) のような正確な根、hypot_ctx(0.3, 0.4) のような正確なノルムなど)は包含区間のループの前に判定され、inexact なしで返されます。また、pow_ctx(4, 1.5) のような正確な二進の結果は包含区間そのものによって正確に返されます。整数乗は認証されません。pow_ctx は、正確な冪または精緻化された方向付きの上下界から一度だけ丸めます。
これらの演算は(try_ 形式は認証失敗の種類の Err を返し)、、、または の場合、あるいは有限のオペランドが 999,999 桁を超える場合や調整指数が約 を超える場合に、not_computed 付きの NaN を返します。このようなコンテキストでの規則は 1 つです。IEEE 754-2019 §9.2.1 または表 9.1 が挙げる場合は値であり、それ以外は not_computed です。挙げられている場合は、NaN オペランド、無限大またはゼロのオペランド、挙げられている正確な点(ln_ctx(1)、log2_ctx(1)、log10_ctx(1)、acos_ctx(1)、acospi_ctx(1)、acosh_ctx(1) は 0、atanpi_ctx(+inf) は 0.5、整数 n の sinpi_ctx(n)、cospi_ctx(n + 0.5)、整数と半整数での tanpi_ctx)、定義域エラー(invalid_operation)と極(division_by_zero)、条項が挙げるオペランドでの compound、rootn、rsqrt、そして atan2、atan2pi、atan(+-inf) の定数です。コンテキストの制限は、これらの後、最初に計算するステップの前に検査されます。条項が挙げていない、通常のオペランドの正確な結果は not_computed のままです。hypot_ctx(3, 4)、rsqrt_ctx(4)、log10_ctx(1E+5)、atanpi_ctx(1)、acospi_ctx(0)、sinpi_ctx(0.5)、cospi_ctx(1)、exp2_ctx(3)、rootn_ctx(8, 3) です。通常のオペランドにすべてのコンテキストを受け付けさせることは #478 の課題です。decimal_gda は decTest コーパスが要求する別の順序を保ちます。コスト:atan(+-inf) と atan2 の pi の倍数の定数は、コンテキストの精度で計算されます。精度 1,000,000 桁では各約 100 秒かかり、80,807,094 桁からは結果はすぐに not_computed になります。decimal_certified_work_refusal が、binary_precision_max(268,435,456 ビット、binary/context.mbt:43)を超える最初の作業精度(1 桁あたり 3.321929 ビットに保護ビット 31)を拒否します。80,807,093 桁が対応できる最大の精度です。decimal の整数冪は、正の指数で 999,999,999 まで、負の指数で -1,999,999,997 までの回数をサポートします。これらは採用した decNumber の実装上の限界であり、GDA 1.70 が課す限界ではありません。これらの回数を超える整数冪は、正確な指数の係数が 4,096 桁以下であれば、有界な二乗乗算を使います。それより大きな係数は、展開する前に invalid_operation 付きの NaN を返します。したがって pow_ctx(2, 1E+9) は DecimalContext::new() の下で有限ですが、pow_ctx(2, 1E+9999999) は固定された作業量の上限内で拒否されます。同じ大きな入力は decimal_gda では GDA アダプタの decNumber の回数制限に従い、invalid_operation を返します。そのため IEEE の decimal と decimal_gda はこの入力で意図的に異なります。pow_ctx(2, 1.5) や exp2_ctx(2) のような非整数冪は、引き続き初等関数のコンテキスト制限を受けます。
Decimal::exp_ctx, ln_ctx, log10_ctx, try_exp_ctx, try_ln_ctx, try_log10_ctx
これらの関数は General Decimal Arithmetic の指数関数と対数関数です。
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::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]
、、 です。 の と は で division_by_zero が立ちます。これは IEEE 754-2019 §9.2.1 の要求であり、log2_ctx、log1p_ctx、logb_ctx と同じ振る舞いです(decimal_gda が従う General Decimal Arithmetic はここで条件を発生させません)。 に対しては 、負の値や に対しては invalid_operation 付きの NaN です。 であり、10 の冪の は正確な整数の指数です。 が確実にオーバーフローまたはアンダーフローするほど大きい・小さい引数は、評価せずに判定されます。
Decimal::pow_ctx, pown_ctx, rootn_ctx, hypot_ctx, try_pow_ctx, try_pown_ctx, try_rootn_ctx, try_hypot_ctx
これらの関数は冪、冪根、ユークリッドノルムを計算します。
pow 系列(pow_ctx、pown_ctx、powr_ctx とその try_ 形式)には、コンテキストの精度に対する工学的な上限があります。999,999 桁の十進数を超えると(初等関数の上限のうち精度の部分、つまり DecimalContext::elementary_precision_limit。None またはより大きな値は脱出口で、保証はありません)、通常のオペランドでは何も計算せず、その精度では平方根になってしまう指数 0.5 も計算せずに、コンテキスト制限エラー(通常の形式では not_computed)をすぐに返します。理由はコストです。pow(2, 0.5) は 100,000 桁で約 0.6 秒、1,000,000 桁で 14.7 秒、10,000,000 桁で 300 秒超かかります。IEEE 754-2019 §9.2.1 が pow について挙げる特殊な場合は、どのコンテキストでも値のままです。pown_ctx は整数指数の pow_ctx で、同じ上限の下にあり、正確な整数冪も例外ではありません。rootn_ctx と compound_ctx は以前からこの上限の下にあります。sqrt_ctx にはこの上限はありません。基本演算(§5.4.1)だからです。
pub fn Decimal::pow_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pown_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rootn_ctx(Self, Int, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::hypot_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_pow_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_pown_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_rootn_ctx(Self, Int, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_hypot_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pow_ctx(x, y) は IEEE 754-2019 §9.2 のべき演算です。signaling NaN オペランドは先に quiet NaN へ変換されて invalid_operation を通知し、以下の恒等式より優先されます。それ以外では で、ゼロ、無限大、quiet NaN にも適用されます。pow(+1, y) は任意の (quiet NaN を含む)に対して 1 です。また pow(-1, ±inf)=1 です。無限大の指数は、その他の底の絶対値で分類されます。 なら指数が のときゼロへ、 のとき無限大へ近づき、 では逆になります。負の底の符号によってこれらが無効になることはありません。
ゼロの底と負の整数指数では、結果はゼロの符号と指数の偶奇で選んだ符号付き無限大で、division_by_zero が立ちます。例えば 、 です。正の整数べきは偶奇に従ってゼロの符号を保ちます:、。ゼロの負の非整数べきは、division_by_zero 付きの正の無限大です。
有界カウント内の整数べきには二進の平方と乗算を使います。 桁に収まるとき正確なべきを返し、それ以外は正しく丸めます。有界カウントを超える整数指数もサポートされます。絶対値のべきを認証し、負の底の奇数べきでは符号を戻す前に有向丸めモードを入れ替えます。大きな整数指数では、指数を展開せず符号と偶奇からゼロと無限大のケースを決めます。例えば pown_ctx(-0, Int::max_value()) は -0、pown_ctx(-0, Int::min_value()) は division_by_zero 付きの +infinity、pown_ctx(-infinity, Int::min_value()) は +0 です。
その他の整数指数では、 桁に収まるとき正確なべきを返し、それ以外は正しく丸めたべきを返します(decimal32 では pow_ctx(3.339434, 3) は 37.24077、正確な立方は です)。 は sqrt_ctx です。正の非整数べきは認証され、有限の非整数指数を持つ負の底は無効です。これらの IEEE 規則は、General Decimal Arithmetic に従う decimal_gda と意図的に異なります(その 0^0 の無効な結果や、丸められた 1.00 になる powx2015 ベクトルを含みます)。pown_ctx(x, n) は整数 n を正確に変換するので、 は精度に依存しません。rootn_ctx(x, n) は整数 に対する です。負の値の偶数根と は無効で、 は division_by_zero 付きの無限大になります。正確に表現できる根はそのまま返されます(rootn_ctx(0.008, 3) はフラグなしの 0.2)。hypot_ctx(x, y) は です。どちらか一方が無限大なら、もう一方が quiet NaN でも になり、正確に表現できるノルム、または がゼロのときの は正確に返されます(hypot_ctx(0.3, 0.4) は 0.5)。
4,096 桁を超える整数の指数は決して展開されません。、、 以外の底では がどのコンテキストをもはるかに超えるので、結果は丸め方向に応じたオーバーフローまたはアンダーフローの値になり(底が 1 より大きいか小さいか、および指数の符号で決まります)、符号は偶奇で決まり、invalid_operation にはなりません。小数部が約 4,000 桁を超えて、この境界を満たさない底は、引き続き invalid_operation 付きの NaN を返します。
正確な結果は、IEEE 754-2019 §9.2.2 の優先指数に最も近い指数を持つコホートのメンバーで返されます。優先指数は pow_ctx(x, y) では 、pown_ctx(x, n) では で、 は格納されている x の指数であり、そのメンバーは 桁に収まる必要があります。decimal64 では pown_ctx(1.00, 2) は 1.0000、pown_ctx(-1.0, 3) は -1.000、pown_ctx(-1E+5, 5) は -1E+25(正確でフラグなし)、pow_ctx(1.00, 1.5) は 1.000、pow_ctx(4.00, 1.5) は 8.000 です。負の指数では値より大きい優先指数には届きません(pown_ctx(1.00, -2) は 1)。 が無限大または NaN のときは標準が優先指数を定めていないので、pow_ctx(1.00, Infinity) は 1 のままです。decimal_gda は代わりに General Decimal Arithmetic の反復乗算の指数に従います。
Decimal::exp2_ctx, exp10_ctx, expm1_ctx, log2_ctx, log1p_ctx, try_exp2_ctx, try_exp10_ctx, try_expm1_ctx, try_log2_ctx, try_log1p_ctx
これらの関数は、IEEE 754-2019 §9.2 の底 2 および底 10 の指数関数・対数関数と、ゼロ付近のものです。いずれも本節の冒頭で述べた f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::exp2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::expm1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log1p_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_exp2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_expm1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log1p_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
Decimal::exp2m1_ctx, exp10m1_ctx, log2p1_ctx, log10p1_ctx, try_exp2m1_ctx, try_exp10m1_ctx, try_log2p1_ctx, try_log10p1_ctx
これらの関数は IEEE 754-2019 §9.2 の 、、、 で、ゼロ付近で exp2(x) - 1 の桁落ちや 1 + x の丸めを起こしません。どの関数もこの節の冒頭で説明した f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::exp2m1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp10m1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2p1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log10p1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_exp2m1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10m1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2p1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log10p1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
特殊値は §9.2.1 のものです。四つすべてで と 、exp2m1 と exp10m1 では 、log2p1 と log10p1 では で division_by_zero を伴い、その定義域は です( を含む は無効です)。正確な結果は、整数 に対する と 、および (それぞれ )のときの整数 です。これらは §9.2.2 の優先指数 0 を取るので、decimal64 では exp2m1_ctx(4) は 15、exp2m1_ctx(-1) は -0.5、exp10m1_ctx(-2.0) は -0.99、log2p1_ctx(-0.50) は -1 で、いずれもフラグはありません。正確な値を保持できないコンテキストは、それをフラグ付きで丸めます。精度 1 での log2p1_ctx(32767) は 2E+1 です(中間点、inexact)。 は正確で、 です。§9.2.1 の の規則は log、log2、log10 だけのものです。非正規化数の範囲を下回る結果は置き換えられず丸められるので、 の符号を保ちます(decimal64 で exp2m1_ctx(-1E-500) は -0E-398、 方向への丸めでは -1E-398 です)。exp_ctx と同じ制限付きコンテキストでは not_computed を返します。
///|
test "decimal exp2m1 exp10m1 log2p1 log10p1" {
let c64 = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("4").exp2m1_ctx(c64).0, content="15")
inspect(d("-2.0").exp10m1_ctx(c64).0, content="-0.99")
inspect(d("1E-10").exp2m1_ctx(c64).0, content="6.931471805839680E-11")
inspect(d("-0.50").log2p1_ctx(c64).0, content="-1")
let (pole, flags) = d("-1").log10p1_ctx(c64)
inspect(pole, content="-inf")
inspect(flags.division_by_zero(), content="true")
}
Decimal::rsqrt_ctx, compound_ctx, powr_ctx, try_rsqrt_ctx, try_compound_ctx, try_powr_ctx
これらの関数は IEEE 754-2019 §9.2 の 、Int32 の に対する 、および です。どの関数もこの節の冒頭で説明した f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::rsqrt_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::compound_ctx(Self, Int32, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::powr_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_rsqrt_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_compound_ctx(Self, Int32, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_powr_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
rsqrt_ctx の定義域は です。 を含む は無効演算、 で division_by_zero を立て、 です(§9.2.1)。 のとき結果は厳密で、§9.2.2 の優先指数 を取ります。したがって decimal64 では rsqrt_ctx(4.00) は 0.5、rsqrt_ctx(1E+2) は 0.1、rsqrt_ctx(1E-400) は 1E+200 です。
compound_ctx(x, n) は §9.2.1 の一覧に従います。 と quiet NaN に対して compound(x, 0) は 1、 は( でも)無効演算、compound(-1, n) は で division_by_zero を伴う 、 で 、compound(±0, n) は 1、compound(+∞, n) は または です。厳密な結果は優先指数 を取ります。compound_ctx(0.10, 2) は 1.2100、compound_ctx(0.00, 3) は 1.000000 です。Int32 のすべての を受け付け、Int32 の最小値 も含みます。
powr_ctx(x, y) は なので、定義域は を含みません( が quiet NaN でも無効演算)。NaN のオペランドには でも quiet NaN を返し、powr(±0, ±0)、powr(+∞, ±0)、powr(1, ±∞) は無効演算で、それ以外は に対する pow_ctx と同じです(結果、コホート、フラグ)。pow_ctx が -0 を返す powr_ctx(-0, 3) は 0 です。
///|
test "decimal rsqrt compound powr" {
let c64 = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("6.25").rsqrt_ctx(c64).0, content="0.4")
inspect(d("2").rsqrt_ctx(c64).0, content="0.7071067811865475")
inspect(d("0.05").compound_ctx(3, c64).0, content="1.157625")
inspect(d("0.05").compound_ctx(-3, c64).0, content="0.8638375985314761")
inspect(d("4").powr_ctx(d("0.5"), c64).0, content="2")
let (invalid, flags) = d("-2").powr_ctx(d("2"), c64)
inspect(invalid, content="nan")
inspect(flags.invalid_operation(), content="true")
}
Decimal::sin_ctx, cos_ctx, tan_ctx, sinpi_ctx, cospi_ctx, tanpi_ctx, try_sin_ctx, try_cos_ctx, try_tan_ctx, try_sinpi_ctx, try_cospi_ctx, try_tanpi_ctx
これらの関数は および の三角関数です。いずれも本節の冒頭で述べた f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::sin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cospi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_sin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
Decimal::asin_ctx, acos_ctx, atan_ctx, atan2_ctx, try_asin_ctx, try_acos_ctx, try_atan_ctx, try_atan2_ctx
これらの関数は逆三角関数です。atan2(y, x) は点 の偏角です。いずれも本節の冒頭で述べた f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::asin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_asin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
Decimal::asinpi_ctx, acospi_ctx, atanpi_ctx, atan2pi_ctx, try_asinpi_ctx, try_acospi_ctx, try_atanpi_ctx, try_atan2pi_ctx
これらの関数は、半回転を単位に角度を測る逆円関数(IEEE 754-2019 §9.2)で、、、、 です。最後の関数は縦座標をレシーバとし(y.atan2pi_ctx(x, ctx))、結果は にあります。各関数にはこの節の冒頭で説明した f_ctx/try_f_ctx の形があります。
pub fn Decimal::asinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acospi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2pi_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_asinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2pi_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
厳密な結果は §9.2.1 のもので、Niven の定理によりこれらが唯一です。、、、、、、、(例外なし)、ゼロと無限大のオペランドに対する の 11 行(、、、、。ゼロの横座標の符号ビットが半平面を決めます)、および有限の非ゼロオペランドの ( なら 、 なら )です。いずれも例外を通知しません。§9.2.2 の優先指数 0 を取るので、オペランドのコホートによらず は 0.5、 は 0.25、 は 0.75、1 は 1 です。定数に対してコンテキストが狭すぎる場合(精度 1)は丸めて inexact を立てます。( も含む)は asinpi と acospi では無効です。それ以外の結果はすべて不正確で( と は有限小数ではありません)、正しく丸められます。atanpi(大きい )、acospi(微小な )、atan2pi(極端な比)が片側から近づく表現可能な値 と の近くでも同様で、そこでは丸めモードがアンカーとその隣の値のどちらかを決めます。
///|
test "decimal inverse circular functions in half-revolutions" {
let c64 = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("1").atanpi_ctx(c64).0, content="0.25")
inspect(d("-1").atan2pi_ctx(d("-1"), c64).0, content="-0.75")
inspect(d("-0").atan2pi_ctx(d("-0"), c64).0, content="-1")
inspect(d("0.5").asinpi_ctx(c64).0, content="0.1666666666666667")
inspect(d("0.5").acospi_ctx(c64).0, content="0.3333333333333333")
let (value, flags) = d("2").asinpi_ctx(c64)
inspect(value, content="nan")
inspect(flags.invalid_operation(), content="true")
}
Decimal::sinh_ctx, cosh_ctx, tanh_ctx, asinh_ctx, acosh_ctx, atanh_ctx, try_sinh_ctx, try_cosh_ctx, try_tanh_ctx, try_asinh_ctx, try_acosh_ctx, try_atanh_ctx
これらの関数は双曲線関数とその逆関数です。いずれも本節の冒頭で述べた f_ctx/try_f_ctx の形を持ちます。
pub fn Decimal::sinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::try_sinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
exp2 から atanh までの上記 7 つのグループの関数の定義域と特殊値:
| 関数 | 無効(invalid_operation) | 極(division_by_zero) | 正確なケース |
|---|---|---|---|
exp2, exp10 | なし | なし | 整数の引数(pow_ctx 経由)、、、 |
expm1 | なし | なし | , , |
log2 | , | 、正確な 2 の冪()、 | |
log1p | , | , | |
exp2m1, exp10m1 | なし | なし | 、、。整数 :、 |
log2p1, log10p1 | , | 、。(それぞれ ) | |
rsqrt | , | ; | |
compound(x, n) | 、(任意の ) | 、、、 は の符号による。厳密なべき | |
powr(x, y) | , , , | NaN のオペランドには NaN。それ以外は に対する power と同じ | |
sin, cos, tan | なし | , , | |
sinpi, cospi, tanpi | 奇数の半整数における tanpi | 整数、半整数、1/4 の奇数倍での tanpi() | |
asin, acos | , | なし | , |
atan | なし | なし | ;(認証付き) |
asinpi, acospi | , | なし | , , , , |
atanpi | なし | なし | ;;(例外なし) |
atan2pi(y, x) | なし | なし | §9.2.1 の 11 個の厳密な行(、、、、)と |
atan2(y, x) | なし | なし | または のとき 、有限の に対して 。その他のゼロまたは無限大のオペランドでは、 の符号を持つ 、、、 のいずれか(認証付き) |
sinh, tanh, asinh | なし | なし | ;、 は を保持; |
cosh | なし | なし | , |
acosh | , | なし | , |
atanh | , |
これらの特殊値は IEEE 754-2019 §9.2.1 に従います。decimal64 では、atan2_ctx(-0, -1) は -3.141592653589793、atan2_ctx(+∞, -∞) は 2.356194490192345、atan2_ctx(-1, +∞) は -0 です。
///|
test "decimal exact and special elementary results" {
let c64 = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
let (norm, flags) = d("0.3").hypot_ctx(d("0.4"), c64)
inspect(norm, content="0.5")
inspect(flags.inexact(), content="false")
inspect(d("0.008").rootn_ctx(3, c64).0, content="0.2")
let c32 = @decimal.DecimalContext::decimal32()
inspect(d("3.339434").pow_ctx(d("3"), c32).0, content="37.24077")
let seven = @decimal.DecimalContext::new(precision=7)
inspect(d("-1").pown_ctx(12345679, seven).0, content="-1")
inspect(d("-0").atan2_ctx(d("-1"), c64).0, content="-3.141592653589793")
inspect(d("Inf").atan2_ctx(d("-Inf"), c64).0, content="2.356194490192345")
inspect(d("-1").atan2_ctx(d("Inf"), c64).0, content="-0")
inspect(d("-Inf").cosh_ctx(c64).0, content="inf")
inspect(d("Inf").log2_ctx(c64).0, content="inf")
}
///|
test "decimal certified elementary functions" {
let ctx = @decimal.DecimalContext::decimal64()
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("1").exp_ctx(ctx).0, content="2.718281828459045")
inspect(d("1000").log10_ctx(ctx).0, content="3")
inspect(d("0.5").sinpi_ctx(ctx).0, content="1")
let down = ctx.with_rounding(@decimal.DecimalRoundingMode::RoundTowardZero)
inspect(d("2").ln_ctx(down).0, content="0.6931471805599453")
// a context beyond the elementary kernels is not computed: `Err` in the `try_`
// form, a NaN with `not_computed` (and not `invalid_operation`) in the plain form
let beyond = @decimal.DecimalContext::new(e_max=999_999_999)
match d("2").try_ln_ctx(beyond) {
Ok(_) => fail("a context beyond the kernels must be an Err")
Err(error) => inspect(error.is_certification_failure(), content="true")
}
let (value, flags) = d("2").ln_ctx(beyond)
inspect(value.is_nan(), content="true")
inspect(flags.not_computed(), content="true")
inspect(flags.invalid_operation(), content="false")
// a domain error is a value with invalid_operation
let (nan, nan_flags) = d("-1").ln_ctx(ctx)
inspect(nan.is_nan(), content="true")
inspect(nan_flags.invalid_operation(), content="true")
}
交換形式
DecimalInterchangeFormat, DecimalInterchangeFormat::context
DecimalInterchangeFormat は IEEE 754 の十進交換形式を指します。
pub(all) enum DecimalInterchangeFormat {
Decimal32
Decimal64
Decimal128
}
pub fn DecimalInterchangeFormat::context(Self) -> DecimalContext
context は DecimalContext::decimal32()、decimal64()、decimal128() のいずれかを返します。
DecimalInterchangeEncoding
DecimalInterchangeEncoding は係数をビットにどう格納するかを選択します。
pub(all) enum DecimalInterchangeEncoding {
DPD
BID
}
DPD は 10 ビットの declet ごとに 3 桁の十進数字を格納し(densely packed decimal)、BID は係数を二進整数として格納します。エンコーディング引数を持たない関数は DPD を使用します。
Decimal::to_interchange_hex, to_interchange_hex_with_encoding
これらの関数は値を交換形式のビットにエンコードし、16 進数で書き出します。
pub fn Decimal::to_interchange_hex(Self, DecimalInterchangeFormat) -> (String, DecimalFlags)
pub fn Decimal::to_interchange_hex_with_encoding(Self, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (String, DecimalFlags)
有限値はまず形式のコンテキストのもとで apply_ctx により丸められ(そのフラグが返されます)、その指数でエンコードされるため、収まる場合はコホートが保たれます。テキストは # に続く 8、16、または 32 桁の大文字の 16 進数字です。無限大は末尾フィールドをゼロとしてエンコードされます。NaN は符号と種類を保ち、そのペイロードは値の精度フィールドとは無関係に整数として格納されます(IEEE 754-2019 §3.5.2)。 未満のペイロードはそのまま保たれ、それより長いペイロードは下位 桁が保持されます。これは DPD と BID で共通です。NaN7 はどちらのエンコーディングでも decimal64 の #7C00000000000007 になります。
Decimal::from_interchange_hex, from_interchange_hex_with_encoding
これらの関数は交換形式の 16 進テキストをデコードします。
pub fn Decimal::from_interchange_hex(String, DecimalInterchangeFormat) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_interchange_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Result[Self, @arithmetic.ArithmeticError]
テキストの前後に ASCII の空白があってもよく、先頭に # があってもかまいません。16 進数字の桁数は形式のものとちょうど一致しなければならず(大文字・小文字は問いません)、それ以外のテキストは Err(構文エラー)で、何が誤りかを示します。必要な桁数と実際の桁数(decimal32 の "#A23003D" は 8 桁ではなく 7 桁)、または最初の 16 進数字でない文字とその桁位置です。長さを先に検査します。長さが正しいビットパターンは拒否されません。デコードは正確で、指数、ゼロの符号、NaN の種類とペイロードを保持します。非正準なエンコーディングは、IEEE 754 が割り当てる値にデコードされます。非正準な DPD の declet はその数字に、 の BID 係数はゼロに、範囲外の BID の NaN ペイロードは 0 になります。無限大と NaN の未使用の指数ビットは無視されます。結果は形式の精度を持ちます。decimal_gda の GdaInterchange::from_hex は同じテキストを受理し同じものを拒否しますが、どちらの誤りも一つの文で報告します。
///|
test "decimal64 interchange in both encodings" {
let x = @decimal.Decimal::from_string("1.25").unwrap()
let fmt = @decimal.DecimalInterchangeFormat::Decimal64
let (dpd, _) = x.to_interchange_hex(fmt)
let (bid, _) = x.to_interchange_hex_with_encoding(
fmt,
@decimal.DecimalInterchangeEncoding::BID,
)
inspect(dpd, content="#22300000000000A5")
inspect(bid, content="#318000000000007D")
let back = @decimal.Decimal::from_interchange_hex(dpd, fmt).unwrap()
inspect(back, content="1.25")
// a text of the wrong length is an error that says so
match @decimal.Decimal::from_interchange_hex("#22300", fmt) {
Ok(_) => fail("expected a parse error")
Err(err) => assert_true(err.is_parse_error())
}
}
DecimalInterchange, DecimalInterchange::format, encoding, to_hex
DecimalInterchange は、1 つの交換形式の値の生のビットを、その形式とエンコーディングとともに保持します。
pub struct DecimalInterchange {
// private fields
}
pub fn DecimalInterchange::format(Self) -> DecimalInterchangeFormat
pub fn DecimalInterchange::encoding(Self) -> DecimalInterchangeEncoding
pub fn DecimalInterchange::to_hex(Self) -> String
ビットを調べたり正確に保持したりする必要があるときに使用します。これには Decimal では表現できない非正準なエンコーディングも含まれます。format と encoding はビットが属する形式とエンコーディングを返します。to_hex は # と全幅の大文字の 16 進数字を書き出します。
DecimalInterchange::from_hex, from_hex_with_encoding, from_decimal, from_decimal_with_encoding
これらの関数はテキストまたは Decimal から交換形式の値を構築します。
pub fn DecimalInterchange::from_hex(String, DecimalInterchangeFormat) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalInterchange::from_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalInterchange::from_decimal(Decimal, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_decimal_with_encoding(Decimal, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (Self, DecimalFlags)
from_hex はビットを変更せずに格納します(テキストの規則とエラーは from_interchange_hex と同じ)。from_decimal は to_interchange_hex と同様にエンコードし、同じフラグを返します。エンコーディングを指定しない版は DPD を使用します。
DecimalInterchange::to_decimal, to_decimal_ctx
これらの関数は格納されたビットをデコードします。
pub fn DecimalInterchange::to_decimal(Self) -> Decimal
pub fn DecimalInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)
デコードは正確です。to_decimal_ctx はフラグを立てません。
DecimalInterchange::canonical, is_canonical
これらの関数は格納されたビットを正準化します。
pub fn DecimalInterchange::canonical(Self) -> Self
pub fn DecimalInterchange::is_canonical(Self) -> Bool
canonical は同じ形式とエンコーディングでデコードして再エンコードします。非正準な declet、範囲外の BID 係数、無限大や NaN の未使用ビットはすべて正準形に置き換えられます。これは冪等です。is_canonical はビットがすでに正準かどうかを判定します。
DecimalInterchange::copy, copy_abs, copy_negate, copy_sign
これらの関数は格納されたビットの符号ビットだけを変更します。
pub fn DecimalInterchange::copy(Self) -> Self
pub fn DecimalInterchange::abs(Self) -> Self
pub fn DecimalInterchange::neg(Self) -> Self
pub fn DecimalInterchange::copy_sign(Self, Self) -> Self
それ以外のビットは、正準かどうかにかかわらずすべて保持されます。copy_sign は両方のオペランドが同じ形式とエンコーディングでなければ中断します。
トレイト実装
Zero、One、Ring と演算子トレイト
Decimal は素の演算子を通じて Luna-Flow の代数トレイトを実装します。
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
pub impl @luna-generic.FromNat for Decimal
pub impl @luna-generic.FromInteger for Decimal
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
pub impl Eq for Decimal
pub impl Compare for Decimal
Zero::zero() と One::one() は Decimal::zero() と Decimal::one() です。結果が丸められない限り(正確な係数がオペランドの大きい方の精度に収まる和または積)、環の法則は +、-、* で正確に成り立ちます。丸められた結果は近似的にしか結合的ではありません。FromNat と FromInteger は構築で説明しています。
@def.Floating
Decimal は floating のスカラートレイトを実装します。
pub impl @def.Floating for Decimal
トレイトメソッドは classify、signum、precision、with_precision、normalized で、いずれも上で説明しています。@def.is_finite(x) などのジェネリックな述語はこれを通じて動作します。
Decimal::add_contextual, sub_contextual, mul_contextual, div_contextual, abs_contextual, sqrt_contextual, exp_contextual, zero_contextual, one_contextual, epsilon_contextual, min_normal_contextual, max_finite_contextual, classify_contextual
これらの関数は Luna-Flow/arithmetic の contextual トレイトを実装します。
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 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.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
pub impl @arithmetic.NumericFormatContextual for Decimal
各 *_contextual 演算は、DecimalContext::from_arithmetic_context でコンテキストを変換し、対応する *_ctx 演算を実行します。division_by_zero が立った場合は Err(division_by_zero) を、他の has_error フラグが立った場合は Err(domain_error) を返し、それ以外は Ok を返して、診断の inexact、overflow、underflow をフラグからコピーします。変換後のコンテキストは既定の指数範囲を持ち、認証済みの関数は 999 までの精度に対してその範囲を受け付けるので、exp_contextual は既定の範囲で動作します。明示的な e_max が 999,999 を超えると、certification_failure(not_computed)で失敗します。invalid_operation を伴う結果は domain_error、not_computed を伴う結果は certification_failure で、try_ 形式は後者にだけ Err を返します。
zero_contextual と one_contextual はコンテキストの精度を持ちます。epsilon_contextual は (next_up_ctx(1) - 1)です。min_normal_contextual は変換後のコンテキストの で、その既定の は 、つまり new の既定の範囲(精度 34)では です。max_finite_contextual は です。classify_contextual は classify です。
Decimal::parse_checked, sqrt_checked, pow_nat_checked, pow_int_checked
parse_checked(s, ctx) は ctx を DecimalContext に変換して Decimal::from_string_ctx を使用し、コンテキストの精度、丸め方向、指数範囲、clamp 設定を適用します。変換後の値を返し、オーバーフローなどのフラグは from_string_ctx から取得できます。構文が無効な場合は Err(parse_error) を返します。 DivChecked::div_checked(x, y, ctx) は変換後のコンテキストのもとでの div_ctx で、div_checked と同様に Err(division_by_zero) と Err(domain_error) を返します。sqrt_checked は変換後のコンテキストのもとでの sqrt_ctx で、負のオペランドに対して失敗します。pow_nat_checked と pow_int_checked は、整数の指数を Decimal へ厳密に変換した(少なくとも 10 桁で、受け付けるすべての指数を収められます)power_ctx です。したがって精度 7 では (-1).pow_int_checked(12345679, ctx) は -1 です。底がゼロで指数が負なら Err(division_by_zero) を、無効な冪なら Err(domain_error) を返し、pow_nat_checked は 999,999,999 を超える指数に対して Err(unsupported) を返します。CompareChecked は compare_checked です。
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_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub impl @arithmetic.ParseChecked for Decimal
pub impl @arithmetic.DivChecked for Decimal
pub impl @arithmetic.CompareChecked for Decimal
pub impl @arithmetic.SqrtChecked for Decimal
pub impl @arithmetic.PowNatChecked for Decimal
pub impl @arithmetic.PowIntChecked for Decimal
parse_checked(s, ctx) は ctx を DecimalContext に変換して Decimal::from_string_ctx を使うため、コンテキストの精度、丸め方向、指数範囲が適用されます。変換後の値を返し、オーバーフローなどのフラグは from_string_ctx から取得できます。構文が無効なら Err(parse_error) を返します。DivChecked::div_checked(x, y, ctx) は変換後のコンテキストで div_ctx を実行し、ゼロ除算フラグには Err(division_by_zero)、無効演算フラグには Err(domain_error) を返します。sqrt_checked は変換後のコンテキストで sqrt_ctx を実行し、負のオペランドでは失敗します。pow_nat_checked と pow_int_checked は整数指数を正確に(受け付けるすべての指数を収める少なくとも 10 桁で)変換して pow_ctx を呼ぶので、精度 7 では (-1).pow_int_checked(12345679, ctx) は -1 です。ゼロまたは quiet NaN の底とゼロ指数には Ok(1)、ゼロの底と負の指数には Err(division_by_zero) を返し、signaling NaN オペランドなど無効な結果には Err(domain_error) を返します。pow_nat_checked は 999,999,999 を超える指数に Err(unsupported) を返します。CompareChecked は compare_checked です。
Eq と Compare:Decimal::equal、not_equal、op_lt、op_le、op_gt、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
これらは compare によって定義されます。x == y は compare(x, y) == 0、x < y は compare(x, y) < 0 であり、以下同様です。コホートのメンバーは等しく(1.0 == 1.00)、 であり、すべての NaN はすべての NaN と等しく、すべての数より大きくなります。表現を区別するには total_order_compare を使用してください。
導出された等価性:DecimalContext::equal、DecimalContext::not_equal、DecimalFlags::equal、DecimalFlags::not_equal、DecimalRoundingMode::equal、DecimalRoundingMode::not_equal、DecimalSignal::equal、DecimalSignal::not_equal、DecimalInterchangeFormat::equal、DecimalInterchangeFormat::not_equal、DecimalInterchangeEncoding::equal、DecimalInterchangeEncoding::not_equal
これらは、コンテキスト、フラグ、列挙型の導出された Eq メソッドです。
pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::not_equal(Self, Self) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::not_equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::equal(Self, Self) -> Bool
pub fn DecimalRoundingMode::not_equal(Self, Self) -> Bool
pub fn DecimalSignal::equal(Self, Self) -> Bool
pub fn DecimalSignal::not_equal(Self, Self) -> Bool
pub fn DecimalInterchangeFormat::equal(Self, Self) -> Bool
pub fn DecimalInterchangeFormat::not_equal(Self, Self) -> Bool
pub fn DecimalInterchangeEncoding::equal(Self, Self) -> Bool
pub fn DecimalInterchangeEncoding::not_equal(Self, Self) -> Bool
コンテキストはフィールドごとに比較されます(精度、丸め、指数の上下限、精緻化の上限)。フラグ集合は 6 個のフィールドすべてを比較します。DecimalContext::from_arithmetic_context(ArithmeticContext::decimal64()) は DecimalContext::decimal64() と等しくなります。
Show と Debug:Decimal::to_string、output、to_repr
Decimal は Show と Debug を実装します。
pub impl Show for Decimal
pub fn Decimal::to_string(Self) -> String
pub fn Decimal::output(Self, &Logger) -> Unit
pub fn Decimal::to_repr(Self) -> @debug.Repr
to_string はコンテキストなしで値を科学表記で書式化します。有限値には to_sci_string の科学表記文字列の規則が使われるため、末尾のゼロと指数が見えます:1.20、1E+3、1.2E-7。特殊値は小文字で書かれます:inf、-inf、nan、snan、-nan12。output は同じテキストをロガーに書き込みます。to_repr は debug_inspect と assert_eq が使う導出された構造的表現です。
///|
test "decimal to_string" {
let d = fn(s : String) { @decimal.Decimal::from_string(s).unwrap() }
inspect(d("123E+2"), content="1.23E+4")
inspect(d("0.0000001"), content="1E-7")
inspect(d("-0.00"), content="-0.00")
inspect(d("-sNaN7"), content="-snan7")
}
公開インターフェース全体
このスナップショットは、パッケージの生成された pkg.generated.mbti です。説明文とインターフェースが食い違う場合は、こちらが正となります。
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/decimal"
import {
"Luna-Flow/arithmetic",
"Luna-Flow/floating/binary",
"Luna-Flow/floating/def",
"Luna-Flow/luna-generic",
"moonbitlang/core/bigint",
"moonbitlang/core/debug",
}
// Values
pub let decimal_context_e_max_limit : Int32
pub let decimal_context_e_min_limit : Int32
pub let decimal_precision_max : Int32
pub let decimal_value_e_max : Int32
pub let decimal_value_e_tiny : Int32
// Errors
// Types and methods
#derive(@debug.Debug)
pub struct Decimal {
// private fields
}
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::acos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::acospi_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::asin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::asinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan2pi_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::atanpi_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_of(Self, DecimalContext) -> @def.IeeeClass
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) -> Int32
pub fn Decimal::compare_checked(Self, Self) -> Result[Int32, @arithmetic.ArithmeticError]
pub fn Decimal::compare_quiet(Self, Self) -> (@def.PartialOrder, DecimalFlags)
pub fn Decimal::compare_quiet_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_greater_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_greater_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_less_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_not_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_ordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_quiet_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling(Self, Self) -> (@def.PartialOrder, DecimalFlags)
pub fn Decimal::compare_signaling_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_greater_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_less_unordered(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_equal(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_greater(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compare_signaling_not_less(Self, Self) -> (Bool, DecimalFlags)
pub fn Decimal::compound_ctx(Self, Int32, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::convert_format(Self, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn Decimal::copy(Self) -> Self
pub fn Decimal::copy_sign(Self, Self) -> Self
pub fn Decimal::cos_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cosh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::cospi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::div(Self, Self) -> Self
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::epsilon_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::equal(Self, Self) -> Bool
pub fn Decimal::exp10_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp10m1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exp2m1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
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::expm1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::exponent10(Self) -> Int32
pub fn Decimal::fma_ctx(Self, Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::from_bigint(@bigint.BigInt, precision? : Int32) -> Self
pub fn Decimal::from_binary(@binary.Binary, precision~ : Int32, mode? : DecimalRoundingMode) -> Self
pub fn Decimal::from_binary_ctx(@binary.Binary, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::from_double(Double, precision? : Int32) -> Self
pub fn Decimal::from_float(Float, precision? : Int32) -> Self
pub fn Decimal::from_int(Int32, precision? : Int32) -> Self
pub fn Decimal::from_interchange_hex(String, DecimalInterchangeFormat) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_interchange_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::from_string_ctx(String, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::get_payload(Self) -> @bigint.BigInt
pub fn Decimal::hypot_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::identical(Self, Self) -> Bool
pub fn Decimal::inf(negative? : Bool, precision? : Int32) -> 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_zero(Self) -> Bool
pub fn Decimal::is_normal(Self, DecimalContext) -> Bool
pub fn Decimal::is_quiet_nan(Self) -> Bool
pub fn Decimal::is_sign_minus(Self) -> Bool
pub fn Decimal::is_signaling_nan(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::log10p1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log1p_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::log2p1_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::logb_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::make(@bigint.BigInt, Int32, Int32, mode? : DecimalRoundingMode) -> Self
pub fn Decimal::max_finite_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::max_num(Self, Self) -> Self
pub fn Decimal::maximum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_magnitude_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::maximum_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::min_normal_contextual(@arithmetic.ArithmeticContext) -> Self
pub fn Decimal::min_num(Self, Self) -> Self
pub fn Decimal::minimum_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_magnitude_number_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::minimum_number_ctx(Self, 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? : Int32) -> Self
pub fn Decimal::nan_payload(Self) -> @bigint.BigInt
pub fn Decimal::neg(Self) -> Self
pub fn Decimal::negative_zero(precision? : Int32) -> Self
pub fn Decimal::next_down_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::next_up_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::normalized(Self) -> Self
pub fn Decimal::not_equal(Self, Self) -> Bool
pub fn Decimal::one(precision? : Int32) -> 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_checked(String, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::pow_int_checked(Self, Int32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pow_nat_checked(Self, UInt32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::pown_ctx(Self, Int32, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::powr_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::precision(Self) -> Int32
pub fn Decimal::quantize_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::quantum_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::quiet_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int32) -> Self
pub fn Decimal::remainder_ctx(Self, Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rootn_ctx(Self, Int32, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::rsqrt_ctx(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::signaling_nan(payload? : @bigint.BigInt, negative? : Bool, precision? : Int32) -> Self
pub fn Decimal::signum(Self) -> @def.Sign
pub fn Decimal::sin_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sinpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::sqrt(Self) -> Self
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::tan_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanh_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::tanpi_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_binary(Self, precision~ : Int32, mode? : @binary.BinaryRoundingMode) -> @binary.Binary
pub fn Decimal::to_binary_ctx(Self, @binary.BinaryContext) -> (@binary.Binary, @binary.BinaryFlags)
pub fn Decimal::to_eng_string(Self) -> String
pub fn Decimal::to_int64_ctx(Self, DecimalContext, exact? : Bool) -> (Int64?, DecimalFlags)
pub fn Decimal::to_int_ctx(Self, DecimalContext, exact? : Bool) -> (Int32?, DecimalFlags)
pub fn Decimal::to_integral_exact_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_integral_value_ctx(Self, DecimalContext) -> (Self, DecimalFlags)
pub fn Decimal::to_interchange_hex(Self, DecimalInterchangeFormat) -> (String, DecimalFlags)
pub fn Decimal::to_interchange_hex_with_encoding(Self, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (String, DecimalFlags)
pub fn Decimal::to_repr(Self) -> @debug.Repr
pub fn Decimal::to_sci_string(Self) -> String
pub fn Decimal::to_string(Self) -> String
pub fn Decimal::to_uint64_ctx(Self, DecimalContext, exact? : Bool) -> (UInt64?, DecimalFlags)
pub fn Decimal::to_uint_ctx(Self, DecimalContext, exact? : Bool) -> (UInt32?, DecimalFlags)
pub fn Decimal::total_order(Self, Self) -> Bool
pub fn Decimal::total_order_compare(Self, Self) -> Int32
pub fn Decimal::total_order_mag(Self, Self) -> Bool
pub fn Decimal::try_acos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_acospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_asinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan2pi_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_atanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_compound_ctx(Self, Int32, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cos_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cosh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_cospi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp10m1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp2m1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_exp_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_expm1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_hypot_ctx(Self, 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_log10p1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log1p_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_log2p1_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_make(@bigint.BigInt, Int32, Int32, mode? : DecimalRoundingMode) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Decimal::try_pow_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_pown_ctx(Self, Int32, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_powr_ctx(Self, Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_rootn_ctx(Self, Int32, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_rsqrt_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sin_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_sinpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tan_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanh_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::try_tanpi_ctx(Self, DecimalContext) -> Result[(Self, DecimalFlags), @arithmetic.ArithmeticError]
pub fn Decimal::with_precision(Self, Int32, DecimalRoundingMode) -> Self
pub fn Decimal::zero(precision? : Int32) -> 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.FromInteger for Decimal
pub impl @luna-generic.FromNat for Decimal
pub impl @luna-generic.MulMonoid 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
#derive(Eq)
pub struct DecimalContext {
// private fields
}
pub fn DecimalContext::decimal128(rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::decimal32(rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::decimal64(rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::e_max(Self) -> Int32
pub fn DecimalContext::e_min(Self) -> Int32
pub fn DecimalContext::elementary_precision_limit(Self) -> Int32?
pub fn DecimalContext::equal(Self, Self) -> Bool
pub fn DecimalContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalContext::new(precision? : Int32, e_max? : Int32, rounding? : DecimalRoundingMode) -> Self
pub fn DecimalContext::not_equal(Self, Self) -> Bool
pub fn DecimalContext::precision(Self) -> Int32
pub fn DecimalContext::refinement_limit(Self) -> Int32?
pub fn DecimalContext::rounding(Self) -> DecimalRoundingMode
pub fn DecimalContext::try_new(precision? : Int32, e_max? : Int32, rounding? : DecimalRoundingMode) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalContext::with_e_max(Self, Int32) -> Self
pub fn DecimalContext::with_elementary_precision_limit(Self, Int32?) -> Self
pub fn DecimalContext::with_precision(Self, Int32) -> Self
pub fn DecimalContext::with_refinement_limit(Self, Int32?) -> Self
pub fn DecimalContext::with_rounding(Self, DecimalRoundingMode) -> Self
#derive(Eq)
pub struct DecimalFlags {
// private fields
}
pub fn DecimalFlags::combine(Self, Self) -> Self
pub fn DecimalFlags::division_by_zero(Self) -> Bool
pub fn DecimalFlags::equal(Self, Self) -> Bool
pub fn DecimalFlags::has_error(Self) -> Bool
pub fn DecimalFlags::inexact(Self) -> Bool
pub fn DecimalFlags::invalid_operation(Self) -> Bool
pub fn DecimalFlags::new() -> Self
pub fn DecimalFlags::not_computed(Self) -> Bool
pub fn DecimalFlags::not_equal(Self, Self) -> Bool
pub fn DecimalFlags::overflow(Self) -> Bool
pub fn DecimalFlags::underflow(Self) -> Bool
pub struct DecimalInterchange {
// private fields
}
pub fn DecimalInterchange::abs(Self) -> Self
pub fn DecimalInterchange::canonical(Self) -> Self
pub fn DecimalInterchange::copy(Self) -> Self
pub fn DecimalInterchange::copy_sign(Self, Self) -> Self
pub fn DecimalInterchange::encoding(Self) -> DecimalInterchangeEncoding
pub fn DecimalInterchange::format(Self) -> DecimalInterchangeFormat
pub fn DecimalInterchange::from_decimal(Decimal, DecimalInterchangeFormat) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_decimal_with_encoding(Decimal, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> (Self, DecimalFlags)
pub fn DecimalInterchange::from_hex(String, DecimalInterchangeFormat) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalInterchange::from_hex_with_encoding(String, DecimalInterchangeFormat, DecimalInterchangeEncoding) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecimalInterchange::is_canonical(Self) -> Bool
pub fn DecimalInterchange::neg(Self) -> Self
pub fn DecimalInterchange::to_decimal(Self) -> Decimal
pub fn DecimalInterchange::to_decimal_ctx(Self) -> (Decimal, DecimalFlags)
pub fn DecimalInterchange::to_hex(Self) -> String
#derive(Eq)
pub(all) enum DecimalInterchangeEncoding {
DPD
BID
}
pub fn DecimalInterchangeEncoding::equal(Self, Self) -> Bool
pub fn DecimalInterchangeEncoding::not_equal(Self, Self) -> Bool
#derive(Eq)
pub(all) enum DecimalInterchangeFormat {
Decimal32
Decimal64
Decimal128
}
pub fn DecimalInterchangeFormat::context(Self) -> DecimalContext
pub fn DecimalInterchangeFormat::equal(Self, Self) -> Bool
pub fn DecimalInterchangeFormat::not_equal(Self, Self) -> Bool
#derive(Eq)
pub(all) enum DecimalRoundingMode {
RoundTiesToEven
RoundTiesToAway
RoundTowardZero
RoundTowardPositive
RoundTowardNegative
}
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?
// Type aliases
// Traits