binary API
Purpose
binary is the binary floating-point core of floating. A Binary is
a signed dyadic number with an arbitrary-precision
coefficient, an attached working precision, and the IEEE 754 special values
(signed zero, infinities, quiet and signaling NaNs with payloads). Every
arithmetic operation rounds the exact result once. A BinaryContext gives the
precision, exponent range, rounding direction and tininess rule of one
operation, and the *_ctx methods return the IEEE status flags with the value.
The tutorial shows the common workflows and the
design page derives the rounding, range and
certification rules used below. The verified IEEE 754 scope is listed in
conformance.
Throughout this page, is a precision in bits, is the rounding of
the real number under the active context, and “the flags” are the five IEEE
exception flags of a BinaryFlags value.
Importing
Add the package to your moon.pkg, together with the two packages whose types
appear in its signatures:
import {
"Luna-Flow/floating/binary",
"Luna-Flow/floating/def",
"Luna-Flow/arithmetic" @lf_arith,
}
The examples call the package as @binary.. @lf_arith is
Luna-Flow/arithmetic: its RoundingMode, ArithmeticContext and
ArithmeticError types appear in several signatures, where the interface file
prints the package as @arithmetic. @def is Luna-Flow/floating/def, which
provides Sign, PartialOrder and the Floating trait. No helper functions
are shared between examples.
Three ways to call an operation
Most operations come in up to three forms with one numerical algorithm behind them.
| Form | Example | Context | Result |
|---|---|---|---|
| plain | x + y, x.exp() | BinaryContext::new(precision=p), nearest-even, p the precision of the operands | the value only |
| contextual | x.add_ctx(y, ctx), x.exp_ctx(ctx) | the given BinaryContext | (value, flags) |
| checked | x.try_exp_ctx(ctx), DivChecked::div_checked(x, y, ctx) | the given context | Result with an @lf_arith.ArithmeticError |
The plain form of a binary operation works at the larger precision of the two
operands (the largest of three for fma). Its context is the extendable
precision format of IEEE 754-2019 3.7 given by alone (see BinaryContext),
whose exponent range is the implementation range below, so it overflows to an
infinity and underflows to a signed zero or a tiny value only at about
.
Values and limits
binary_value_e_max, binary_value_e_min
The largest and smallest exponent of the leading bit that a finite Binary
may carry.
pub let binary_value_e_max : Int32
pub let binary_value_e_min : Int32
They are and , so as IEEE 754-2019 3.3 requires of every format. A context given by its precision alone, and every plain operation, uses them as and : a result whose leading bit would lie above overflows, and below the value is subnormal with quantum . The range of a context given by its precision alone is this range, so every stored value is a member of that context.
binary_precision_max
The largest precision a BinaryContext accepts and the largest precision a
Binary may carry. Every constructor that takes a precision checks it
against 1..=binary_precision_max: a value-returning constructor aborts with a
message that names the constructor, the range and the offending value, and a
constructor that returns a Result (from_string, from_hex, and the
constructors of BinaryChecked) returns an ArithmeticError of kind
DomainError. A precision is never replaced by another one.
pub let binary_precision_max : Int32
It is bits. Together with the exponent range it keeps
every coefficient exponent inside the 32-bit Int range.
Exact coefficients
BinCoeff
A non-negative arbitrary-precision integer, used as the coefficient of a
Binary and as the bit pattern of an interchange encoding.
type BinCoeff
The inner type @binary_kernel.Coeff belongs to the internal package
internal/binary_kernel, which only code inside Luna-Flow/floating can import.
It carries no compatibility promise and a user cannot call a method on it, read
it, compare it or build one: from outside the module a BinCoeff is abstract.
Neither its constructor nor its field is visible outside binary; the other
packages of the library reach the kernel type through the bridge to_kernel and
from_kernel (below).
The value is exact: on the native, LLVM and Wasm targets an inline
64- or 128-bit word or an array of 64-bit limbs, on JavaScript a host
bigint; the representation is not observable, and the algorithm selection
(schoolbook, Karatsuba, Toom-3, number-theoretic transform, staged division) is
described in the design page.
Debug prints the integer value.
BinCoeff::to_kernel, BinCoeff::from_kernel (internal bridge)
The bridge between BinCoeff and the kernel type, for the packages of this
module only. Code outside Luna-Flow/floating cannot name the kernel type and
has no use for them; they carry no compatibility promise, and the kernel type
they exchange may change in any release.
pub fn BinCoeff::to_kernel(Self) -> @binary_kernel.Coeff
pub fn BinCoeff::from_kernel(@binary_kernel.Coeff) -> Self
Both carry #internal, which changes neither the generated interface nor the documentation tool, so this heading and the doc comments are what mark them as internal. Both are free: BinCoeff is a one-field tuple structure over the kernel type, and the bridge reads and wraps that field.
BinCoeff::zero, BinCoeff::one, BinCoeff::from_uint64
Build a coefficient from a machine value.
pub fn BinCoeff::zero() -> Self
pub fn BinCoeff::one() -> Self
pub fn BinCoeff::from_uint64(UInt64) -> Self
BinCoeff::parse, BinCoeff::to_string, BinCoeff::to_radix_string
Convert between a coefficient and digits.
pub fn BinCoeff::parse(String, radix? : Int32) -> Result[Self, String]
pub fn BinCoeff::to_string(Self) -> String
pub fn BinCoeff::to_radix_string(Self, Int32) -> String
parse reads a digit string in base radix (default 10, letters for digits
above 9, an optional leading +); an empty string, a - sign, a digit
outside the radix or a radix outside is an Err. to_string prints
base 10 and to_radix_string any radix in , in lower case without a
prefix; it aborts for another radix.
BinCoeff::from_bytes_be, BinCoeff::to_bytes_be
Convert between a coefficient and big-endian bytes.
pub fn BinCoeff::from_bytes_be(BytesView) -> Self
pub fn BinCoeff::to_bytes_be(Self) -> Bytes
to_bytes_be uses the minimal number of bytes; leading zero bytes are ignored
by from_bytes_be.
BinCoeff::to_uint64
Returns the value as a UInt64, or None when it needs more than 64 bits.
pub fn BinCoeff::to_uint64(Self) -> UInt64?
BinCoeff::is_zero, BinCoeff::bit_length
Queries.
pub fn BinCoeff::is_zero(Self) -> Bool
pub fn BinCoeff::bit_length(Self) -> Int32
bit_length is for and for zero.
BinCoeff::compare, BinCoeff::equal
Exact comparison.
pub fn BinCoeff::compare(Self, Self) -> Int32
pub fn BinCoeff::equal(Self, Self) -> Bool
compare returns , or ; equal is numerical equality, which for
natural numbers is the same as equality of representations. The operators
<, <=, >, >=, == and != use them (see
Trait implementations).
BinCoeff also implements Eq, Compare, Show and Debug; the promoted
trait methods are listed under Trait implementations.
It has no arithmetic, shifts, bit operations or GCD: they are internal to the
library (the package internal/binary_kernel), and arithmetic on values is done
with Binary or, on a coefficient read with coefficient(), after
converting it with to_string or to_bytes_be.
///|
test "BinCoeff converts and compares exact natural numbers" {
let c = @binary.BinCoeff::parse("ff", radix=16).unwrap()
let ten = @binary.BinCoeff::from_uint64(10UL)
inspect("\{c} \{ten} \{c.bit_length()}", content="255 10 8")
inspect(c.compare(ten), content="1")
inspect(c.to_bytes_be(), content="b\"\\xff\"")
inspect(@binary.BinCoeff::parse("-1") is Err(_), content="true")
}
The value type
Binary
A binary floating-point value: a finite dyadic number, a signed infinity or a
NaN, with a working precision. Its representation is an internal type
(@binary_kernel.BinRepr, like the coefficient of BinCoeff) that carries no
compatibility promise and is read only inside the package; a value is one heap
object.
pub struct Binary(@binary_kernel.BinRepr) derive(@debug.Debug)
A finite value is with the sign bit, a
BinCoeff and = exponent2(). Every value built through this API is
normalized: a nonzero is odd (factors of two are moved into ), a zero
has and and keeps its sign, and has at most precision()
bits. The precision is an attribute of the value: plain operations work at the
larger precision of their operands, and contextual operations stamp the
context precision on their result.
== agrees with compare: a == b exactly when a.compare(b) == 0, so two values
are equal when they are the same number, whatever their precisions
(one(precision=53) == one(precision=24), -0 == +0), and every NaN equals every
other NaN. This is the total preorder in which <, <= and sorting work (every NaN
equal to every NaN and above every number), the rule of Decimal too. It is not IEEE
equality: use compare_quiet_equal (IEEE Std 754-2019 5.6.1, 5.11) when a NaN must be
unordered. Binary has no Hash. identical is the structural question.
Binary::identical
pub fn Binary::identical(Self, Self) -> Bool
The structural equality of two values: the same class, sign (the sign of a zero
included), coefficient, exponent and precision, and for a NaN the same signaling
bit and payload. It distinguishes -0 from +0, a value of precision 53 from the
same value of precision 24, and two NaNs of different kind or payload, and a NaN
is identical to an identical NaN. It is what == was before 0.12; use it where a
result is checked as a datum (a test of the sign of a zero or of the precision
stamped by a contextual operation), and == where the number is meant.
Binary::make
Builds a finite value rounded to
precision bits.
pub fn Binary::make(BinCoeff, Int32, Int32, negative? : Bool, mode? : BinaryRoundingMode) -> Self
The arguments are the coefficient, the exponent and the precision. When
the coefficient has more significant bits than the precision it is rounded
with mode (default RoundTiesToEven). The result is normalized. A precision
outside 1..=binary_precision_max aborts. A value outside the implementation exponent range is
replaced as an overflow or underflow would be: above it by or, for
a mode that rounds toward zero, the largest finite magnitude
; below the smallest implementation subnormal
by or, for a mode that rounds away from zero
(and for nearest when the value exceeds half of it), by that subnormal.
make rounds precision and range together, in mode: a value between the
smallest subnormal and keeps only the bits on the subnormal
grid (at least one), so the stored value never has a bit
below that grid. This matters only at magnitudes near ; apply_ctx
additionally reports the flags.
Binary::from_coefficient, Binary::from_int
Build a value from an integer.
pub fn Binary::from_coefficient(BinCoeff, precision? : Int32, negative? : Bool) -> Self
pub fn Binary::from_int(Int32, precision? : Int32) -> Self
The default precision is 53. The integer is rounded to nearest-even when it
has more significant bits than the precision; from_int(n) is exact for every
Int at the default precision.
Binary::from_double, Binary::from_float
Decode a host binary64 or binary32 value exactly.
pub fn Binary::from_double(Double, precision? : Int32) -> Self
pub fn Binary::from_float(Float, precision? : Int32) -> Self
The defaults are 53 and 24 bits, so the conversion is exact. from_double
preserves signed zeros, infinities, the NaN sign, the quiet/signaling
distinction and the NaN payload (the fraction field without the quiet bit).
from_float first widens the Float to a Double on the host and then
decodes that: numbers, zeros and infinities are unaffected, but a NaN keeps
the payload of the widened binary64 encoding (the binary32 payload times
), and on the native target a signaling Float NaN arrives as a quiet
NaN. Use BinaryInterchange::from_hex with Binary32 to decode binary32 NaNs
bit-exactly. The value is the one the host already rounded: from_double(0.1) is
, not one tenth. Use from_string to round a
decimal literal directly.
Binary::zero, Binary::negative_zero, Binary::one, Binary::inf
Build the constants , , and .
pub fn Binary::zero(precision? : Int32) -> Self
pub fn Binary::negative_zero(precision? : Int32) -> Self
pub fn Binary::one(precision? : Int32) -> Self
pub fn Binary::inf(negative? : Bool, precision? : Int32) -> Self
The default precision is 53, and it must be within
1..=binary_precision_max (see binary_precision_max). inf(negative=true) is
; the default is , as Decimal::inf has it.
Binary::nan, Binary::quiet_nan, Binary::signaling_nan
Build NaNs.
pub fn Binary::nan(precision? : Int32) -> Self
pub fn Binary::quiet_nan(payload? : BinCoeff, negative? : Bool, precision? : Int32) -> Self
pub fn Binary::signaling_nan(payload? : BinCoeff, negative? : Bool, precision? : Int32) -> Self
nan() is a positive quiet NaN with payload 0. A signaling NaN always has a
nonzero payload (the default and a requested 0 both become 1).
A NaN of precision has payload bits (IEEE 754-2019 6.2.1: the
trailing significand field has bits and the first is the quiet bit), so
none for . quiet_nan and signaling_nan abort when the payload is
wider, and signaling_nan aborts for , where no signaling NaN exists
(a signaling NaN needs a non-zero payload bit). Conversions never abort: a
payload that the destination cannot hold keeps its low bits (6.2.3), and a
signaling NaN whose payload does not survive becomes quiet. This is the rule of
with_precision, from_double, from_float, from_hex (a snan literal below
precision 3 is a quiet NaN), every operation that returns a quiet NaN under a
context (the payload is cut to the context precision) and the interchange
encodings.
Observing a value
Binary::classify, Binary::signum, Binary::is_sign_minus
Report the class and sign of a value.
pub fn Binary::classify(Self) -> @arithmetic.FpClass
pub fn Binary::signum(Self) -> @def.Sign
pub fn Binary::is_sign_minus(Self) -> Bool
classify returns Finite, Infinity or NaN (zeros are Finite). signum
is Zero for every zero and every NaN, and Positive or Negative otherwise.
is_sign_minus returns the sign bit itself, which is set for ,
and negative NaNs. @def.is_finite, @def.is_nan, @def.is_infinite and
@def.is_zero work on Binary through the Floating trait; the
methods of the next section give the same answers without the trait.
Binary::class_of, Binary::is_normal, Binary::is_subnormal, Binary::is_finite, Binary::is_infinite, Binary::is_nan
The ten-valued class of IEEE 754-2019 clause 5.7.2 and its predicates.
pub fn Binary::class_of(Self, BinaryContext) -> @def.IeeeClass
pub fn Binary::is_normal(Self, BinaryContext) -> Bool
pub fn Binary::is_subnormal(Self, BinaryContext) -> Bool
pub fn Binary::is_finite(Self) -> Bool
pub fn Binary::is_infinite(Self) -> Bool
pub fn Binary::is_nan(Self) -> Bool
class_of returns one of the ten values of IeeeClass:
SignalingNaN, QuietNaN, NegativeInfinity, NegativeNormal,
NegativeSubnormal, NegativeZero, PositiveZero, PositiveSubnormal,
PositiveNormal and PositiveInfinity. A nonzero finite value is normal when
the exponent of its leading bit is at least the context’s and
subnormal when it is below; a Binary carries no format, so the context
decides, and BinaryInterchangeFormat::context gives the one of a binary
interchange format. A context given by its precision alone has the implementation limit
binary_value_e_min as e_min. is_normal and is_subnormal are true exactly
for the normal and subnormal classes; is_finite is true for zeros,
subnormals and normals, is_infinite for the two infinities and is_nan for
both NaNs. None of them rounds or raises a flag, and classify keeps its
three-valued meaning.
Binary::is_zero, Binary::is_negative_zero, Binary::is_quiet_nan, Binary::is_signaling_nan, Binary::nan_payload
Special-value predicates.
pub fn Binary::is_zero(Self) -> Bool
pub fn Binary::is_negative_zero(Self) -> Bool
pub fn Binary::is_quiet_nan(Self) -> Bool
pub fn Binary::is_signaling_nan(Self) -> Bool
pub fn Binary::nan_payload(Self) -> BinCoeff
nan_payload is zero for a value that is not a NaN.
Binary::coefficient, Binary::exponent2, Binary::precision
Return the stored representation.
pub fn Binary::coefficient(Self) -> BinCoeff
pub fn Binary::exponent2(Self) -> Int32
pub fn Binary::precision(Self) -> Int32
For a finite value the number is coefficient()
with the sign applied. The coefficient and exponent of an infinity or NaN
carry no meaning.
coefficient() builds a BinCoeff on each call for a value of at most 128
coefficient bits (the value stores its coefficient as one or two machine
words), so it allocates there; for a wider value it returns the stored
coefficient. A loop that reads the coefficient of many small values pays one
allocation per call. Binary has no public word reader; the result’s
BinCoeff::to_uint64 gives the value when it fits 64 bits. The exponent of the
leading bit, which is what most callers read the coefficient for, is
ilogb(), which does not allocate.
Binary::normalized
Returns the canonical representation of a finite value at its own precision.
pub fn Binary::normalized(Self) -> Self
Values built through the public API are already canonical, so this is the identity on them; infinities and NaNs are returned unchanged.
Binary::with_precision
Rounds a value to a new working precision.
pub fn Binary::with_precision(Self, Int32, BinaryRoundingMode) -> Self
A finite value with more significant bits than the new precision is rounded
in the given direction (a BinaryRoundingMode, ties to away included). Zeros, infinities and NaNs only change their
precision attribute. No flags are reported; use apply_ctx when they matter.
Binary::ulp
Returns the unit in the last place of a finite value at its own precision.
pub fn Binary::ulp(Self) -> Self
For with leading-bit exponent the result is . For zero it is , and for an infinity or NaN it is a quiet NaN. The spacing ignores any context exponent range, so it is not the subnormal spacing of an IEEE format.
///|
test "make normalizes and rounds to the precision" {
let twelve = @binary.Binary::make(
@binary.BinCoeff::from_uint64(12UL),
0,
2,
)
inspect(
"\{twelve} \{twelve.coefficient()} \{twelve.exponent2()}",
content="3p2 3 2",
)
// 13 needs four bits; at two bits it rounds to nearest-even 12.
let thirteen = @binary.Binary::make(
@binary.BinCoeff::from_uint64(13UL),
0,
2,
)
inspect(thirteen, content="3p2")
inspect(@binary.Binary::one().ulp(), content="1p-52")
}
Plain arithmetic
Binary::add, Binary::sub, Binary::mul, Binary::div, Binary::neg
The four operations and negation, also available as +, -, *, / and
unary -.
pub fn Binary::add(Self, Self) -> Self
pub fn Binary::sub(Self, Self) -> Self
pub fn Binary::mul(Self, Self) -> Self
pub fn Binary::div(Self, Self) -> Self
pub fn Binary::neg(Self) -> Self
pub impl Add for Binary
pub impl Sub for Binary
pub impl Mul for Binary
pub impl Div for Binary
pub impl Neg for Binary
The result is the exact sum, difference, product or quotient rounded once to
nearest-even at the larger operand precision, with the implementation exponent
range. Special values follow IEEE 754: NaNs propagate (the first NaN operand,
quieted), , , and are
NaN, and a nonzero number divided by zero is a signed infinity. Flags are
discarded; use the contextual forms to observe them.
neg flips the sign bit of every value, including zeros and NaNs, and never
rounds.
Binary::abs, Binary::copy_sign
Clear or copy the sign bit.
pub fn Binary::abs(Self) -> Self
pub fn Binary::copy_sign(Self, Self) -> Self
Both are quiet IEEE sign-bit operations: they never round, never raise a flag
and keep NaN payloads. x.copy_sign(y) has the magnitude of x and the sign
bit of y.
Binary::sqrt
Correctly rounded square root.
pub fn Binary::sqrt(Self) -> Self
x.sqrt() rounds to nearest-even at the precision of x: it is
sqrt_ctx under the working context and never fails. An invalid operation (IEEE
754-2019 7.2: a negative nonzero argument, included, or a signaling NaN)
is a quiet NaN, and the flag is read through sqrt_ctx(...).1.invalid_operation().
, and a quiet NaN of either sign gives a quiet NaN. For a square root at another precision
or rounding direction use sqrt_ctx; its results under RoundTowardNegative
and RoundTowardPositive enclose and coincide when the root is
exact.
Binary::pown
Raise a value to an integer power.
pub fn Binary::pown(Self, Int32) -> Self
The result is correctly rounded to
nearest-even at the precision of x, computed as in pown_ctx, and never fails. A zero
base with a negative exponent is an infinity (the sign of the base for an odd
exponent; pown_ctx(...).1.division_by_zero() is the pole), and a signaling
NaN base a quiet NaN for every exponent, zero included (IEEE 754-2019
§9.2.1 excludes it from ; invalid_operation through pown_ctx);
for every other , a quiet NaN included.
Binary::fma
Fused multiply-add: with a single rounding.
pub fn Binary::fma(Self, Self, Self) -> Self
The precision is the largest of the three operand precisions. See
fma_ctx for the special cases.
Binary::remainder
IEEE 754 remainder , where is the integer nearest with ties to even.
pub fn Binary::remainder(Self, Self) -> Self
The result is exact whenever it fits the larger operand precision, which is
always the case for operands of that precision (the proof is on the
design page). See
remainder_ctx.
///|
test "plain arithmetic rounds once at the operand precision" {
let one = @binary.Binary::one()
let three = @binary.Binary::from_int(3)
let third = one / three
inspect(third, content="6004799503160661p-54")
inspect(third.to_shortest_string(), content="0.3333333333333333")
inspect(one / @binary.Binary::zero(), content="inf")
inspect(@binary.Binary::from_int(7).remainder(@binary.Binary::from_int(2)), content="-1p0")
inspect(@binary.Binary::from_int(3).pown(-2).to_shortest_string(), content="0.1111111111111111")
}
Contexts, rounding and flags
BinaryRoundingMode
The rounding-direction attribute of a context.
pub(all) enum BinaryRoundingMode {
RoundTiesToEven
RoundTiesToAway
RoundTowardZero
RoundTowardPositive
RoundTowardNegative
} derive(Eq, @debug.Debug)
These are the five IEEE 754-2019 rounding-direction attributes (clauses 4.3.1
and 4.3.2); RoundTiesToAway is not required of a binary format but is defined.
There is no away-from-zero mode: @lf_arith.RoundingMode::AwayFromZero has no
IEEE 754-2019 counterpart and is refused by from_arithmetic and
from_arithmetic_context. Each mode is a monotone
map ; the
design page defines them.
BinaryRoundingMode::from_arithmetic, BinaryRoundingMode::to_arithmetic
Convert to and from @lf_arith.RoundingMode.
pub fn BinaryRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self?
pub fn BinaryRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
to_arithmetic(RoundTiesToAway) is None, because @lf_arith.RoundingMode
has no ties-to-away mode, and from_arithmetic(AwayFromZero) is None, because
IEEE 754-2019 4.3 has no such attribute; the other modes map one to one.
TininessDetection
When a nonzero result counts as tiny for the underflow flag.
pub(all) enum TininessDetection {
BeforeRounding
AfterRounding
} derive(Eq, @debug.Debug)
BeforeRounding calls a result tiny when the exact value has
. AfterRounding calls it tiny when rounded to
bits with an unbounded exponent range has magnitude below
(IEEE 754-2019 clause 7.5). The default is AfterRounding. Underflow is
signaled only for a tiny result that is also inexact.
BinaryContext
The format and the attributes of one operation: the precision , the exponent (with , IEEE 754-2019 3.3), the rounding-direction attribute and the tininess rule.
pub struct BinaryContext {
// private fields
} derive(Eq, @debug.Debug)
A context is an immutable value; there is no global or thread state.
and are exponents of the leading bit, as in IEEE 754: a
normal number satisfies , the largest
finite value is and the smallest positive
subnormal is . A context has no separate : it is
. Without an e_max the context is the extendable precision
format of IEEE 754-2019 3.7 specified by alone, and is
binary_value_e_max.
BinaryContext::new, BinaryContext::try_new
Build a context.
pub fn BinaryContext::new(precision=precision? : Int32, e_max? : Int32, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::try_new(precision=precision? : Int32, e_max? : Int32, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
Defaults: , e_max = binary_value_e_max, RoundTiesToEven,
AfterRounding; new() is therefore the extendable format of 53 bits, and every
operation of the package runs in it. new aborts when is outside or is outside
, naming the parameter; try_new
returns a domain_error in those cases. is what makes
; IEEE 754-2019 3.7 NOTE 3 recommends
and , which are not enforced. There is no one-sided or
asymmetric range: unbounded(p) and the e_min argument no longer exist.
BinaryContext::binary16, BinaryContext::binary32, BinaryContext::binary64, BinaryContext::binary128
Contexts of the IEEE 754 interchange formats.
pub fn BinaryContext::binary16(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary32(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary64(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary128(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
Each is BinaryInterchangeFormat::context of the format:
| Context | |||
|---|---|---|---|
binary16 | 11 | −14 | 15 |
binary32 | 24 | −126 | 127 |
binary64 | 53 | −1022 | 1023 |
binary128 | 113 | −16382 | 16383 |
BinaryContext::from_arithmetic_context
Converts an @lf_arith.ArithmeticContext.
pub fn BinaryContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
Precision and rounding are copied; the clamp field has no binary meaning and is
ignored; tininess is AfterRounding. A given e_min must equal ,
and e_min alone gives . The result is an Err for
AwayFromZero, an e_min that is not , and a precision or
e_max outside the limits of try_new.
BinaryContext::precision, BinaryContext::rounding, BinaryContext::e_min, BinaryContext::e_max, BinaryContext::tininess
Read the fields of a context.
pub fn BinaryContext::precision(Self) -> Int32
pub fn BinaryContext::rounding(Self) -> BinaryRoundingMode
pub fn BinaryContext::e_min(Self) -> Int32
pub fn BinaryContext::e_max(Self) -> Int32
pub fn BinaryContext::tininess(Self) -> TininessDetection
e_min is always ; both are plain integers.
BinaryContext::with_precision, with_rounding, with_e_max, with_tininess
Copy a context with one parameter changed.
pub fn BinaryContext::with_precision(Self, Int32) -> Self
pub fn BinaryContext::with_rounding(Self, BinaryRoundingMode) -> Self
pub fn BinaryContext::with_e_max(Self, Int32) -> Self
pub fn BinaryContext::with_tininess(Self, TininessDetection) -> Self
with_precision and with_e_max abort outside the limits of new; there is no
try_with_*.
BinaryContext::refinement_limit, BinaryContext::with_refinement_limit
Read and set the refinement limit of the certified elementary functions.
pub fn BinaryContext::refinement_limit(Self) -> Int32?
pub fn BinaryContext::with_refinement_limit(Self, Int32?) -> Self
Every certified elementary function (exp, ln, the trigonometric,
hyperbolic and inverse functions, pow, rootn, hypot, atan2 and their
try_*_ctx forms) evaluates an enclosure at a growing working precision until
both ends round alike. The limit is the number of refinement steps: Some(n)
allows n of them (a value below 1 counts as 1), the default is Some(12),
and None removes the count limit. When the limit is reached without a
decision, try_*_ctx returns the CertificationFailure error with the
refinement count, and the plain and *_ctx forms return a quiet
NaN with not_computed. With None the loop still stops when the working
precision passes a cap, the larger of 8,000,000 bits and 256 times the first
working precision, and the trigonometric work limit of 8,000,000 bits still
refuses an argument that would need more. The default changes no result.
The field takes part in ==: two contexts that differ only in the limit are
different.
///|
test "a refinement limit makes a hard-to-round result fail" {
let wide = @binary.BinaryContext::new(precision=330)
let one = @binary.Binary::from_int(1, precision=330)
let midpoint = one.add_ctx(one.scaleb_ctx(@binary.Binary::from_int(-53), wide).0, wide).0
// exp(x) is within 2^-330 of the midpoint 1 + 2^-53.
let x = midpoint.try_ln_ctx(wide).unwrap().0
let context = @binary.BinaryContext::new(precision=53)
inspect(context.refinement_limit() == Some(12), content="true")
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")
}
BinaryFlags
The five IEEE 754 exception flags raised by one or more operations, and
not_computed, which reports a result the library could not compute.
pub struct BinaryFlags {
// private fields
} derive(Eq, @debug.Debug)
Two flag sets are == when all six flags agree.
BinaryFlags::new, BinaryFlags::inexact, BinaryFlags::underflow, BinaryFlags::overflow, BinaryFlags::division_by_zero, BinaryFlags::invalid_operation, BinaryFlags::not_computed
Build an empty flag set and read the individual flags.
pub fn BinaryFlags::new() -> Self
pub fn BinaryFlags::inexact(Self) -> Bool
pub fn BinaryFlags::underflow(Self) -> Bool
pub fn BinaryFlags::overflow(Self) -> Bool
pub fn BinaryFlags::division_by_zero(Self) -> Bool
pub fn BinaryFlags::invalid_operation(Self) -> Bool
pub fn BinaryFlags::not_computed(Self) -> Bool
new() has every flag clear. There is no contains: that method exists only where a package has a signal enum, and the six accessors cover the six flags. A contextual operation returns only the flags it
raised itself; nothing is sticky until you combine flags. The flags mean:
inexact, the returned value differs from the exact result; underflow, the
result is tiny and inexact; overflow, the rounded result exceeded the
largest finite value (always together with inexact); division_by_zero, an
exact infinite result from finite operands (such as or );
invalid_operation, no useful real result exists and a quiet NaN was
returned, or a signaling NaN was an operand. The elementary
functions also raise it when they return NaN for a domain case, in the try_
forms as in the plain ones.
not_computed, the operation could not be carried out within a limit of the
implementation (a certification that did not conclude, a context beyond what the
kernels support) and the value is a NaN; it is not a flag of IEEE 754-2019 and
is distinct from invalid_operation. The non-try elementary functions raise it
when the try_ form returns an Err of the certification-failure kind, and
the checked tiers turn it into that Err.
BinaryFlags::combine
Returns the union of two flag sets.
pub fn BinaryFlags::combine(Self, Self) -> Self
combine is a bitwise OR: associative, commutative and idempotent with
new() as identity, so the flags of a computation can be accumulated in any
order.
Contextual arithmetic
Every method in this group returns (value, flags), rounds the exact result
once under the context, and applies the context exponent range: an overflow
returns or the largest finite magnitude depending on the rounding
direction, and a tiny result is rounded on the subnormal grid with quantum
. The returned value carries the context precision. A NaN
operand produces the first NaN operand quieted, with its sign and payload, and
invalid_operation only when some operand was a signaling NaN.
Binary::apply_ctx
Rounds a value into a context.
pub fn Binary::apply_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
This is the IEEE conversion of a wider value to a narrower format. Finite
values are rounded with the full overflow, subnormal and tininess rules;
infinities are kept; a signaling NaN is quieted with invalid_operation.
Binary::add_ctx, Binary::sub_ctx, Binary::mul_ctx, Binary::div_ctx
The four operations under a context.
pub fn Binary::add_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::sub_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::mul_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::div_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
Invalid operations ( with equal signs after sub’s
negation, , , ) give a quiet NaN with
invalid_operation; a nonzero finite number divided by zero gives a signed
infinity with division_by_zero. An exact zero sum of operands with opposite
signs is , except under RoundTowardNegative;
(IEEE 754-2019 clause 6.3).
Binary::sqrt_ctx
Square root under a context.
pub fn Binary::sqrt_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
, , and a negative nonzero
argument gives a quiet NaN with invalid_operation.
Binary::fma_ctx
Fused multiply-add under a context.
pub fn Binary::fma_ctx(Self, Self, Self, BinaryContext) -> (Self, BinaryFlags)
The product is formed exactly and the sum is rounded once (IEEE 754-2019
clause 5.4.1). A NaN operand propagates the first NaN of self, multiplier,
addend. invalid_operation is raised for a signaling NaN, for
(also when the addend is a quiet NaN, as SoftFloat does), and
for .
Binary::remainder_ctx
IEEE 754 remainder under a context.
pub fn Binary::remainder_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
The result is with ,
so . A zero result has the sign of . or
gives a quiet NaN with invalid_operation; or
returns rounded into the context. The exact is then rounded; for
operands representable in the context this rounding is exact and no flag is
raised. The quotient is never formed: the operands are reduced modulo ,
so huge exponent gaps cost multiplications.
Binary::pown_ctx
Integer power under a context.
pub fn Binary::pown_ctx(Self, Int32, BinaryContext) -> (Self, BinaryFlags)
This is IEEE 754 pown. without a
flag for every except a signaling NaN (a quiet NaN included); a signaling
NaN base gives a quiet NaN with its payload and invalid_operation for every
exponent, zero included (§9.2.1, §7.2 a); (sign for odd ) with
division_by_zero; is an infinity or zero with the sign of an
odd power. Small powers are computed exactly; otherwise a Ziv loop rounds an
enclosure, with an exact fallback, so the result is always correctly rounded.
///|
test "contextual operations return value and flags" {
let ctx = @binary.BinaryContext::binary32()
let one = @binary.Binary::one()
let (third, flags) = one.div_ctx(@binary.Binary::from_int(3), ctx)
inspect(third.to_shortest_string_ctx(ctx).0, content="0.33333334")
inspect(flags.inexact(), content="true")
let (inf, zero_flags) = one.div_ctx(@binary.Binary::zero(), ctx)
inspect("\{inf} \{zero_flags.division_by_zero()}", content="inf true")
}
IEEE 754 operations
Binary::to_integral_value_ctx, Binary::to_integral_exact_ctx
Round to an integral value in the context’s rounding direction.
pub fn Binary::to_integral_value_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::to_integral_exact_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
These are IEEE roundToIntegral (in the context’s direction) and
roundToIntegralExact. Only the rounding direction of the context is used;
the result keeps the operand’s precision and the sign of a zero result.
to_integral_exact_ctx raises inexact when the value changed;
to_integral_value_ctx never raises it. Infinities are returned unchanged and
a signaling NaN is quieted with invalid_operation.
Binary::floor, Binary::ceil, Binary::trunc, Binary::round, Binary::round_ties_to_even
Round to an integral value in a fixed direction.
pub fn Binary::floor(Self) -> Self
pub fn Binary::ceil(Self) -> Self
pub fn Binary::trunc(Self) -> Self
pub fn Binary::round(Self) -> Self
pub fn Binary::round_ties_to_even(Self) -> Self
They are roundToIntegralTowardNegative, …TowardPositive, …TowardZero,
…TiesToAway and …TiesToEven. round rounds halfway cases away from zero:
round(-2.5) = -3, while round_ties_to_even(-2.5) = -2.
Binary::to_int_ctx, Binary::to_int64_ctx, Binary::to_uint_ctx, Binary::to_uint64_ctx
IEEE convertToInteger to a machine integer, rounding in the context’s
direction.
pub fn Binary::to_int_ctx(Self, BinaryContext, exact? : Bool) -> (Int32?, BinaryFlags)
pub fn Binary::to_int64_ctx(Self, BinaryContext, exact? : Bool) -> (Int64?, BinaryFlags)
pub fn Binary::to_uint_ctx(Self, BinaryContext, exact? : Bool) -> (UInt32?, BinaryFlags)
pub fn Binary::to_uint64_ctx(Self, BinaryContext, exact? : Bool) -> (UInt64?, BinaryFlags)
The value is first rounded to an integer. If that integer fits the target type
the result is Some; with exact=true (convertToIntegerExact) inexact is
raised when rounding changed the value. A NaN, an infinity or an integer
outside the target range gives None with invalid_operation, where a C
implementation would return an unspecified sentinel. A negative value that
rounds to zero converts to 0 for the unsigned targets.
Binary::next_up_ctx, Binary::next_down_ctx
IEEE nextUp and nextDown in the context’s format.
pub fn Binary::next_up_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::next_down_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
next_up_ctx(x) is the least value of the context’s format (precision and
exponent range, subnormals included) that is greater than ; next_down_ctx
is . The context’s rounding direction is ignored. The
operations are quiet: is the smallest positive
subnormal, is the most negative finite value,
with no overflow flag, and only a
signaling NaN raises invalid_operation. An operand with more bits than the
context precision is accepted.
Binary::scaleb_ctx, Binary::logb_ctx, Binary::ilogb
IEEE scaleB and logB.
pub fn Binary::scaleb_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::logb_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::ilogb(Self) -> Int32?
x.scaleb_ctx(n, ctx) is with the usual overflow and
underflow handling; it is exact unless the result leaves the normal range. The
count n is a Binary, the kind logb_ctx returns, as in Decimal::scaleb_ctx
and decimal_gda: it must be an integer value. A NaN count propagates (invalid
for a signaling NaN); an infinite or non-integer count is a NaN with
invalid_operation, whatever the receiver is (an infinite receiver with a
finite count is returned as it is); an integer count beyond the Int range
acts as the largest count of its sign, which overflows or underflows every
finite non-zero value of any format. IEEE 754-2019 5.3.3 defines scaleB for integral counts only and leaves a
non-integral second operand (an infinity is not integral) to the language: the
NaN with invalid_operation is this library’s choice, as in decimal.
x.logb_ctx(ctx) is as an exact integral value
(also for subnormal ): with
division_by_zero, , and a NaN
propagates.
x.ilogb() is the same exponent as an integer: the with
, that is , read from the value without
building its coefficient. It is logB of IEEE 754-2019 5.3.3 with an integral
logBFormat: the standard defines as the exponent of
“determined as though x were represented with infinite range and minimum
exponent”, so a subnormal gives the exponent of its leading bit. For
, and
with an integer logBFormat the standard
returns language-defined values outside and signals
the invalid operation exception (5.3.3 and 7.2); ilogb renders those three
cases as None and raises no flag. logb_ctx is the operation with a
floating-point logBFormat ( with division_by_zero, , NaN).
///|
test "ilogb" {
inspect(@binary.Binary::from_int(12).ilogb().unwrap(), content="3")
inspect(@binary.Binary::zero().ilogb() is None, content="true")
}
///|
test "IEEE integral, integer and neighbour operations" {
let ctx = @binary.BinaryContext::binary64()
let x = @binary.Binary::from_string("-2.5").unwrap()
inspect(
"\{x.floor()} \{x.ceil()} \{x.trunc()} \{x.round()} \{x.round_ties_to_even()}",
content="-3p0 -1p1 -1p1 -3p0 -1p1",
)
let (n, flags) = x.to_int_ctx(ctx, exact=true)
inspect("\{n.unwrap()} \{flags.inexact()}", content="-2 true")
let (up, _) = @binary.Binary::one().next_up_ctx(ctx)
inspect(up.to_hex(), content="0x10000000000001p-52")
let (tiny, _) = @binary.Binary::zero().next_up_ctx(ctx)
inspect(tiny.to_shortest_string_ctx(ctx).0, content="5e-324")
}
Comparison and ordering
Binary::compare
Numerical three-way comparison that is total on every value.
pub fn Binary::compare(Self, Self) -> Int32
pub impl Compare for Binary
compare returns , or by numerical value, with and
precision ignored. NaN has no numerical order, so compare places every NaN
equal to every other NaN and above every non-NaN value; it never aborts. The
result is a total preorder, which is what Compare (and sorting) needs, but
it is not the IEEE comparison: under it nan > 1 holds. The operators <,
<=, >, >= and the promoted op_* methods use compare. For IEEE
semantics use compare_checked, the quiet and signaling predicates below, or
total_order. The design page
explains the choice.
Binary::compare_checked
Numerical comparison that rejects NaN.
pub fn Binary::compare_checked(Self, Self) -> Result[Int32, @arithmetic.ArithmeticError]
pub impl @arithmetic.CompareChecked for Binary
Returns the same value as compare when neither operand is a NaN, and an
unordered_comparison error otherwise.
Binary::compare_quiet, Binary::compare_signaling
IEEE comparison as a four-valued relation with flags.
pub fn Binary::compare_quiet(Self, Self) -> (@def.PartialOrder, BinaryFlags)
pub fn Binary::compare_signaling(Self, Self) -> (@def.PartialOrder, BinaryFlags)
The relation is Less, Equal, Greater or Unordered (some operand is a
NaN), with . The quiet form raises invalid_operation only for a
signaling NaN; the signaling form raises it for every unordered comparison
(IEEE 754-2019 clause 5.11).
Binary::compare_quiet_equal, Binary::compare_quiet_less, Binary::compare_quiet_less_equal, Binary::compare_quiet_unordered, Binary::compare_signaling_equal, Binary::compare_signaling_less, Binary::compare_signaling_less_equal
The IEEE comparison predicates.
pub fn Binary::compare_quiet_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less_equal(Self, Self) -> (Bool, BinaryFlags)
compareQuietEqual, compareQuietLess, compareQuietLessEqual,
compareQuietUnordered and the signaling Equal, Less, LessEqual. Each is
derived from compare_quiet or compare_signaling and returns its flags; every
predicate except compare_quiet_unordered is false on an unordered pair.
Binary::compare_quiet_not_equal and the other comparison predicates of Tables 5.1 and 5.2
The fifteen predicates of IEEE 754-2019 5.11 not listed above.
pub fn Binary::compare_quiet_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_greater_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_greater_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_ordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_less(Self, Self) -> (Bool, BinaryFlags)
Clause 5.11 lists 22 predicates, 10 in Table 5.1 (with the common mathematical
symbols) and 12 in Table 5.2; with the seven above every one of them has a
function. Each is defined from compare_quiet or compare_signaling through
the relations that make it true, which is how the tables define it, and returns
the flags of that comparison: a quiet predicate raises invalid_operation for
a signaling NaN only, a signaling predicate for every NaN operand. The
doc comment of each names its row. Name spelling follows the seven above:
compare_, quiet or signaling, then the predicate name of the table in
snake case. The pairs the standard states as negations of one another (the two
predicates of one line of a table) return opposite values and the same flags.
| Table | predicate | true relations |
|---|---|---|
| 5.1 | Binary::compare_quiet_equal (compareQuietEqual) | equal |
| 5.1 | Binary::compare_quiet_not_equal (compareQuietNotEqual) | less, greater, unordered |
| 5.1 | Binary::compare_signaling_greater (compareSignalingGreater) | greater |
| 5.1 | Binary::compare_signaling_not_greater (compareSignalingNotGreater) | less, equal, unordered |
| 5.1 | Binary::compare_signaling_greater_equal (compareSignalingGreaterEqual) | equal, greater |
| 5.1 | Binary::compare_signaling_less_unordered (compareSignalingLessUnordered) | less, unordered |
| 5.1 | Binary::compare_signaling_less (compareSignalingLess) | less |
| 5.1 | Binary::compare_signaling_not_less (compareSignalingNotLess) | equal, greater, unordered |
| 5.1 | Binary::compare_signaling_less_equal (compareSignalingLessEqual) | less, equal |
| 5.1 | Binary::compare_signaling_greater_unordered (compareSignalingGreaterUnordered) | greater, unordered |
| 5.2 | Binary::compare_signaling_equal (compareSignalingEqual) | equal |
| 5.2 | Binary::compare_signaling_not_equal (compareSignalingNotEqual) | less, greater, unordered |
| 5.2 | Binary::compare_quiet_greater (compareQuietGreater) | greater |
| 5.2 | Binary::compare_quiet_not_greater (compareQuietNotGreater) | less, equal, unordered |
| 5.2 | Binary::compare_quiet_greater_equal (compareQuietGreaterEqual) | equal, greater |
| 5.2 | Binary::compare_quiet_less_unordered (compareQuietLessUnordered) | less, unordered |
| 5.2 | Binary::compare_quiet_less (compareQuietLess) | less |
| 5.2 | Binary::compare_quiet_not_less (compareQuietNotLess) | equal, greater, unordered |
| 5.2 | Binary::compare_quiet_less_equal (compareQuietLessEqual) | less, equal |
| 5.2 | Binary::compare_quiet_greater_unordered (compareQuietGreaterUnordered) | greater, unordered |
| 5.2 | Binary::compare_quiet_unordered (compareQuietUnordered) | unordered |
| 5.2 | Binary::compare_quiet_ordered (compareQuietOrdered) | less, equal, greater |
Binary::total_order, Binary::total_order_mag, Binary::total_order_compare
The IEEE 754 totalOrder relation.
pub fn Binary::total_order(Self, Self) -> Bool
pub fn Binary::total_order_mag(Self, Self) -> Bool
pub fn Binary::total_order_compare(Self, Self) -> Int32
total_order_compare orders all values as
with NaNs of one sign and kind ordered by payload (reversed for the negative
side). x.total_order(y) is total_order_compare(x, y) <= 0 and
total_order_mag compares absolute values. Values that are numerically equal
but differ in precision compare equal. The operations are quiet.
Binary::min_num, Binary::max_num
The smaller or larger of two values, ignoring a NaN operand.
pub fn Binary::min_num(Self, Self) -> Self
pub fn Binary::max_num(Self, Self) -> Self
When exactly one operand is a NaN the other is returned (the IEEE 754-2008
minNum/maxNum convention for quiet NaNs); a signaling NaN is ignored in the
same way, without quieting or a flag, and two NaNs give the argument. When the operands compare equal
under compare (for example and ) the receiver is returned. No flags
are produced.
Binary::clamp, Binary::clamp_checked
Restrict a value to [min, max].
pub fn Binary::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Binary::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]
A NaN receiver is returned unchanged. clamp aborts when a bound is a NaN or
min > max; clamp_checked returns a domain_error in those cases.
///|
test "three different orders on Binary" {
let nan = @binary.Binary::nan()
let zero = @binary.Binary::zero()
let neg_zero = @binary.Binary::negative_zero()
inspect(nan.compare(zero), content="1")
inspect(nan.compare_checked(zero) is Err(_), content="true")
let (unordered, flags) = zero.compare_quiet_unordered(nan)
inspect("\{unordered} \{flags.invalid_operation()}", content="true false")
inspect(neg_zero.compare(zero), content="0")
inspect(neg_zero.total_order_compare(zero), content="-1")
inspect(neg_zero == zero, content="true")
inspect(neg_zero.identical(zero), content="false")
inspect(nan == nan, content="true")
let values = [nan, @binary.Binary::inf(), zero, @binary.Binary::from_int(-3)]
values.sort()
inspect(values.map(fn(v) { v.to_string() }).join(" "), content="-3p0 0 inf nan")
}
Text and hexadecimal conversion
Binary::to_string
Prints the exact stored value as coefficient p exponent.
pub fn Binary::to_string(Self) -> String
pub impl Show for Binary
A finite nonzero value prints as [-]<c>p<e> with in decimal, meaning
(for example 3p-1 is ). Zeros print as 0 and -0,
infinities as inf and -inf, and every NaN as nan. The form is exact and
unambiguous but not a decimal rendering; use to_shortest_string for that.
Binary::from_string, Binary::from_string_ctx
Parse a decimal literal with correct rounding (IEEE
convertFromDecimalCharacter).
pub fn Binary::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::from_string_ctx(String, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The accepted syntax is [+-]digits[.digits][e[+-]digits] (a leading or
trailing point is allowed, the exponent marker is e or E), and the
case-insensitive words inf, infinity, nan, qnan and snan, with
surrounding whitespace ignored. Anything else is a parse_error. The exact
decimal value is rounded once under the context, for any number
of digits and any exponent; overflow, underflow and inexact are reported as for
arithmetic. from_string(s, precision=p) uses BinaryContext::new(precision=p) (default 53) and
drops the flags.
Binary::to_decimal_string_ctx
Formats a value with a fixed number of significant decimal digits (IEEE
convertToDecimalCharacter).
pub fn Binary::to_decimal_string_ctx(Self, Int, BinaryContext) -> (String, BinaryFlags)
The output is [-]d.ddd…e±x with exactly digits significant digits
(at least 1), correctly rounded in the context’s rounding direction;
inexact is raised when nonzero digits were dropped. Only the rounding
direction of the context is used. Zero prints as 0.00…e+0 with its sign,
infinities as inf/-inf, NaNs as nan/snan with their sign. The text
parses back with from_string_ctx.
Binary::to_shortest_string, Binary::to_shortest_string_ctx
Formats the shortest decimal that reads back as the same value.
pub fn Binary::to_shortest_string(Self) -> String
pub fn Binary::to_shortest_string_ctx(Self, BinaryContext) -> (String, BinaryFlags)
to_shortest_string_ctx(x, ctx) returns the decimal with the fewest
significant digits that from_string_ctx(_, ctx) maps back to under
round-to-nearest-even (the context’s own rounding direction is ignored). When
two candidates of that length read back, the nearer one is chosen, then the
one with an even last digit. The layout follows ECMAScript Number#toString:
positional notation for decimal exponents in , otherwise
d.ddde±x; unlike ECMAScript, prints as -0. For binary64 values in
BinaryContext::binary64() the result equals the host Double formatter.
to_shortest_string() uses BinaryContext::new(precision=precision()), so it is the shortest
string that from_string(text, precision=x.precision()) maps back to x. An
operand that is not representable in the context is first rounded into it
(apply_ctx, in the rounding direction of the context, with the overflow and
underflow of the context), and the result is the shortest string of that
rounded value: inf or -inf on overflow, 0 or -0 on underflow (the
largest finite value for a direction that rounds toward zero). A value of the
format prints as itself. The second component is the flags of that rounding
(inexact, overflow, underflow); it is empty for a value of the format, a
NaN or an infinity.
Binary::from_hex, Binary::from_hex_ctx, Binary::to_hex
Read and write the exact value with a hexadecimal coefficient.
pub fn Binary::from_hex(String, Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::from_hex_ctx(String, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::to_hex(Self) -> String
The syntax is the IEEE 754-2019 §5.12.3 hexSequence: an optional sign, 0x
or 0X, hexadecimal digits with at most one point (1.8, .8 or 1.), and a
required p or P exponent with an optional sign and decimal digits. The
value is the hexadecimal significand times , so 0x3p-1
and 0x1.8p0 are both . from_hex(s, p) rounds once to precision p
with nearest-even and reports no flags; a p outside
1..=binary_precision_max is an Err. from_hex_ctx(s, context) is the
§5.12.3 conversion: it rounds the exact value once under the rounding direction,
precision, exponent range and tininess rule of context and returns the
inexact, underflow and overflow flags, like from_string_ctx. An exponent
field of any length is a valid text: it is read with saturation at , as the
decimal reader does, so an exponent outside the 32-bit range overflows or
underflows there (the result of the context with its flags, in every rounding
direction) instead of being a parse error, and a zero significand is the zero
of the sign for any exponent. from_hex, which stores the exact value, reports
an exponent outside the 32-bit range as a parse error (a zero significand is
still a zero). Both accept
inf, infinity, nan and snan in any case with an optional sign
(§5.12.1); snan gives a signaling NaN. Surrounding whitespace is trimmed;
any other text is a parse_error. to_hex prints the stored coefficient in
lower case, 0x0p0 or -0x0p0 for a zero, and nan/inf with a sign.
///|
test "decimal and hexadecimal text" {
let tenth = @binary.Binary::from_string("0.1").unwrap()
inspect(tenth, content="3602879701896397p-55")
inspect(tenth.to_hex(), content="0xccccccccccccdp-55")
inspect(tenth.to_shortest_string(), content="0.1")
let ctx = @binary.BinaryContext::binary64()
let (digits, flags) = tenth.to_decimal_string_ctx(25, ctx)
inspect("\{digits} \{flags.inexact()}", content="1.000000000000000055511151e-1 true")
let (single, _) = @binary.Binary::from_string_ctx("0.1", @binary.BinaryContext::binary32()).unwrap()
inspect(single, content="13421773p-27")
inspect(@binary.Binary::from_hex("0x3p-1", 53).unwrap(), content="3p-1")
// 0x1.00000000000008p0 has 57 significant bits: binary64 rounds it, inexact.
let (rounded, hex_flags) = @binary.Binary::from_hex_ctx("0x1.00000000000008p0", ctx).unwrap()
inspect(rounded, content="1p0")
inspect(hex_flags.inexact(), content="true")
}
Interchange encodings
BinaryInterchangeFormat
The four IEEE 754 binary interchange formats.
pub(all) enum BinaryInterchangeFormat {
Binary16
Binary32
Binary64
Binary128
} derive(Eq, @debug.Debug)
BinaryInterchangeFormat::precision, BinaryInterchangeFormat::e_min, BinaryInterchangeFormat::e_max, BinaryInterchangeFormat::bias, BinaryInterchangeFormat::exponent_field_width, BinaryInterchangeFormat::trailing_significand_field_width, BinaryInterchangeFormat::storage_width
The parameters of a format.
pub fn BinaryInterchangeFormat::precision(Self) -> Int
pub fn BinaryInterchangeFormat::e_min(Self) -> Int
pub fn BinaryInterchangeFormat::e_max(Self) -> Int
pub fn BinaryInterchangeFormat::bias(Self) -> Int
pub fn BinaryInterchangeFormat::exponent_field_width(Self) -> Int
pub fn BinaryInterchangeFormat::trailing_significand_field_width(Self) -> Int
pub fn BinaryInterchangeFormat::storage_width(Self) -> Int
| Format | total_bits | exponent_bits | fraction_bits | precision | bias | e_min |
|---|---|---|---|---|---|---|
Binary16 | 16 | 5 | 10 | 11 | 15 | −14 |
Binary32 | 32 | 8 | 23 | 24 | 127 | −126 |
Binary64 | 64 | 11 | 52 | 53 | 1023 | −1022 |
Binary128 | 128 | 15 | 112 | 113 | 16383 | −16382 |
BinaryInterchangeFormat::context
Returns the BinaryContext of the format.
pub fn BinaryInterchangeFormat::context(Self, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> BinaryContext
BinaryInterchange
An encoded value: a format and its bit pattern.
pub struct BinaryInterchange {
// private fields
} derive(Eq)
Equality compares the format and the bits, so two encodings of NaN with different payloads differ and differ.
BinaryInterchange::format, BinaryInterchange::bits
Return the format and the bit pattern of an encoding.
pub fn BinaryInterchange::format(Self) -> BinaryInterchangeFormat
pub fn BinaryInterchange::bits(Self) -> BinCoeff
bits() is the encoding as a natural number below , = total_bits:
the sign bit is bit , the biased exponent field the next bits and the
trailing significand field the low bits.
BinaryInterchange::from_bits, BinaryInterchange::from_hex, BinaryInterchange::to_hex
Build or print an encoding.
pub fn BinaryInterchange::from_bits(BinCoeff, BinaryInterchangeFormat) -> Self
pub fn BinaryInterchange::from_hex(String, BinaryInterchangeFormat) -> Self?
pub fn BinaryInterchange::to_hex(Self) -> String
from_bits keeps the low total_bits bits. from_hex needs exactly
total_bits / 4 hexadecimal digits, optionally prefixed with 0x or #, and
returns None otherwise. to_hex prints upper-case digits padded to the full
width.
BinaryInterchange::to_binary
Decodes an encoding exactly.
pub fn BinaryInterchange::to_binary(Self) -> Binary
The result has the format precision. Normal and subnormal numbers, signed
zeros and infinities decode exactly; a NaN keeps its sign and payload (the
fraction without the quiet bit), and a signaling NaN stays signaling. No host
Float or Double is involved.
Binary::convert_format
Convert a value to a binary interchange format and return it as a Binary.
pub fn Binary::convert_format(Self, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (Self, BinaryFlags)
The IEEE 754-2019 §5.4.2 formatOf-convertFormat operation, with the parameters of
to_interchange and the value instead of the encoding. A conversion to a wider
precision and range is exact and raises nothing; to a narrower one the value is
rounded under rounding and tininess with inexact, underflow and
overflow. A signaling NaN gives a quiet NaN and invalid_operation, also when
the source already has the destination’s precision (the canonicalizing
conversion). A NaN payload is kept when the destination holds it and truncated to
its low bits otherwise (§6.2.3), so the result is exactly what decoding
to_interchange returns. apply_ctx and to_interchange stay.
///|
test "convert a value between formats" {
let b32 = @binary.BinaryInterchangeFormat::Binary32
let tenth = @binary.Binary::from_string("0.1", precision=200).unwrap()
let (single, flags) = tenth.convert_format(b32)
inspect(single.precision(), content="24")
inspect(flags.inexact(), content="true")
let (up, _) = tenth.convert_format(
b32,
rounding=@binary.BinaryRoundingMode::RoundTowardPositive,
)
inspect(up.compare(single), content="0")
}
BinaryInterchange::from_binary, Binary::to_interchange
Round a value into a format and encode it.
pub fn BinaryInterchange::from_binary(Binary, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (Self, BinaryFlags)
pub fn Binary::to_interchange(Self, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (BinaryInterchange, BinaryFlags)
The two are the same operation: apply_ctx with the format’s context, then
encoding. A signaling NaN is encoded as a quiet NaN with invalid_operation,
and a payload is truncated to the payload field.
///|
test "encode and decode interchange bits" {
let b32 = @binary.BinaryInterchangeFormat::Binary32
let tenth = @binary.Binary::from_string("0.1", precision=200).unwrap()
let (nearest, flags) = tenth.to_interchange(b32)
inspect("\{nearest.to_hex()} \{flags.inexact()}", content="3DCCCCCD true")
let (chopped, _) = tenth.to_interchange(
b32,
rounding=@binary.BinaryRoundingMode::RoundTowardZero,
)
inspect(chopped.to_hex(), content="3DCCCCCC")
let snan = @binary.BinaryInterchange::from_hex("7F800001", b32)
.unwrap()
.to_binary()
let (quieted, nan_flags) = snan.to_interchange(b32)
inspect("\{quieted.to_hex()} \{nan_flags.invalid_operation()}", content="7FC00001 true")
}
Elementary functions
Each elementary function has three forms:
f(x)rounds to nearest-even at the precision ofx(the larger precision for two operands) with the implementation exponent range;f_ctx(x, ctx)rounds underctxand returns(value, flags);try_f_ctx(x, ctx)returns the same pair inOk, or an@lf_arith.ArithmeticError.
All three run the same certified algorithm. It computes an enclosure
whose every internal operation is rounded downward for
and upward for , at a working precision that starts at bits
(or at the operand precision plus 16 when that is larger, for rootn, the
inverse trigonometric and the hyperbolic functions). If and round to
the same value with the same flags, that value is returned; otherwise
grows by , for at most as many attempts as the
refinement limit of the context allows (default 12, None for no limit). Because
rounding is monotone, a returned value is the correctly rounded result
, never an uncertified approximation; the
design page gives the
argument for the value and the flags.
When the attempts run out, try_f_ctx returns a certification_failure
error whose CertificationFailureDetail names the operation, the stage
(RangeReduction or TargetRounding), the reason and the last working
precision. An argument outside the real domain of ln, log2, log10, log1p, log2p1,
log10p1, asin, acos, acosh, atanh, asinpi and acospi, and an infinite
argument of the trigonometric functions (sin, cos, tan, sinpi, cospi,
tanpi), is a value of try_f_ctx, a NaN with invalid_operation, as it is for the
plain form, and so is a domain case of rootn, pow, powr, rsqrt and
compound: try_f_ctx returns Err only for a result that could not be computed. The non-try forms turn that Err into a quiet NaN with not_computed. NaN operands propagate quietly (a signaling NaN
raises invalid_operation), and poles return a signed infinity with
division_by_zero (for example ,
). Exactly representable results that an
enclosure cannot isolate are detected before the loop, for example
, for integral , for integral ,
dyadic powers such as , exact roots such as
, and
; each function lists its own cases below.
They are rounded once from their exact value, so their flags are right in
every rounding mode.
Every result that reaches the loop is not a rounding breakpoint, so an
enclosure end that is itself representable (such as for or for
at a tiny ) cannot be the result. The functions other than
rootn move such an end just inside the enclosure before rounding it; pow
does so once its exactness test has excluded a breakpoint.
In addition, sin, tan, asin, sinh, tanh, asinh and atanh decide
an argument with below the target spacing at directly from
, and cos, cosh, expm1 and log1p do the same with
(around for cos and cosh, around for the others), before the
loop. Tiny arguments are therefore certified in every rounding mode: sin of
at 53 bits is with inexact, and
rounded toward zero is with inexact.
Binary::exp, Binary::exp_ctx, Binary::try_exp_ctx
The exponential .
pub fn Binary::exp(Self) -> Self
pub fn Binary::exp_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_exp_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Defined on all of : exactly, and . Results certainly beyond the exponent range are decided from certified bounds on before the main loop, so huge arguments overflow or underflow with the correct flags instead of failing.
Binary::expm1, Binary::expm1_ctx, Binary::try_expm1_ctx
without the cancellation of exp(x) - 1 near zero.
pub fn Binary::expm1(Self) -> Self
pub fn Binary::expm1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_expm1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
, and . For the value lies within above , and the result is decided from the rounding direction alone: , or when rounding toward zero or , always inexact.
Binary::exp2m1, Binary::exp2m1_ctx, Binary::try_exp2m1_ctx
without the cancellation of exp2(x) - 1 near zero.
pub fn Binary::exp2m1(Self) -> Self
pub fn Binary::exp2m1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_exp2m1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
IEEE 754-2019 §9.2: ,
and ,
with no exception. An integral gives the exact integer (or
for ), rounded as a dyadic: exact or a rounding tie while
it has at most bits, and otherwise the neighbour of chosen by the
rounding direction without forming . For the value
lies within above and the rounding direction alone decides
(as for expm1). A result certainly beyond the exponent range is decided before
the main loop, so near overflows with the correct flags.
Binary::exp10m1, Binary::exp10m1_ctx, Binary::try_exp10m1_ctx
without the cancellation of exp10(x) - 1 near zero.
pub fn Binary::exp10m1(Self) -> Self
pub fn Binary::exp10m1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_exp10m1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
IEEE 754-2019 §9.2: the special values of exp2m1. A positive integer
gives the exact integer , rounded as a dyadic.
Saturation towards and the overflow decision follow exp2m1, with
in place of 1.
Binary::exp2, Binary::exp2_ctx, Binary::try_exp2_ctx
The power of two .
pub fn Binary::exp2(Self) -> Self
pub fn Binary::exp2_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_exp2_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
An integral with gives the exact , rounded into the
context only when it leaves the exponent range. The other special values are
those of exp.
Binary::exp10, Binary::exp10_ctx, Binary::try_exp10_ctx
The power of ten .
pub fn Binary::exp10(Self) -> Self
pub fn Binary::exp10_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_exp10_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
An integral in gives the exact ,
rounded once. For a larger integral the odd part has more than
bits, so the result is neither representable nor a midpoint, and a
negative integral gives a value that is never dyadic; both are always
inexact. The other special values are those of exp.
Binary::ln, Binary::ln_ctx, Binary::try_ln_ctx
The natural logarithm .
pub fn Binary::ln(Self) -> Self
pub fn Binary::ln_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_ln_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is . exactly; with
division_by_zero; . A negative argument, finite or
, is a domain case: a quiet NaN with invalid_operation, also from
try_ln_ctx.
Binary::try_exp_directed_pair, Binary::try_ln_directed_pair
The two directed roundings of or in one call, for the interval types.
pub fn Binary::try_exp_directed_pair(Self, Int32) -> Result[(Self, Self), @arithmetic.ArithmeticError]
pub fn Binary::try_ln_directed_pair(Self, Int32) -> Result[(Self, Self), @arithmetic.ArithmeticError]
x.try_exp_directed_pair(p) returns the values of x.try_exp_ctx at precision under RoundTowardNegative and under RoundTowardPositive, as (low, high), and the error of the first of the two calls that fails; try_ln_directed_pair is the same for try_ln_ctx. For every operand the result is exactly what the two calls give. Where one certified enclosure can decide both roundings (a finite with an in-range result for exp, a finite positive for ln) it costs one evaluation instead of two; every other operand is answered by the two calls themselves.
Binary::log1p, Binary::log1p_ctx, Binary::try_log1p_ctx
without the rounding of 1 + x.
pub fn Binary::log1p(Self) -> Self
pub fn Binary::log1p_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_log1p_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is . ,
with division_by_zero, a finite
and are a domain case, a quiet NaN with
invalid_operation.
Binary::log2p1, Binary::log2p1_ctx, Binary::try_log2p1_ctx
without the rounding of 1 + x.
pub fn Binary::log2p1(Self) -> Self
pub fn Binary::log2p1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_log2p1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is (Table 9.1). ,
,
with division_by_zero, a finite and are a domain case, a
quiet NaN with invalid_operation. (and
) gives the exact integer (and ).
Binary::log10p1, Binary::log10p1_ctx, Binary::try_log10p1_ctx
without the rounding of 1 + x.
pub fn Binary::log10p1(Self) -> Self
pub fn Binary::log10p1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_log10p1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The special values of log2p1. for an integer gives
the exact integer .
Binary::log2, Binary::log2_ctx, Binary::try_log2_ctx
The binary logarithm .
pub fn Binary::log2(Self) -> Self
pub fn Binary::log2_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_log2_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Special values and domain as for ln. A power of two gives the exact
integer , rounded into the context.
Binary::log10, Binary::log10_ctx, Binary::try_log10_ctx
The decimal logarithm .
pub fn Binary::log10(Self) -> Self
pub fn Binary::log10_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_log10_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Special values and domain as for ln. with (stored as
the coefficient and exponent ) gives the exact integer , rounded
into the context, at any precision that holds .
Binary::pow, Binary::pow_ctx, Binary::try_pow_ctx
The real power .
pub fn Binary::pow(Self, Self) -> Self
pub fn Binary::pow_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_pow_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The cases are tried in this order, as in IEEE 754-2019 §9.2.1:
- for every , and for every , NaN included
(also a signaling NaN, without
invalid_operation). - An integral with is
pown_ctx(x, y). - A NaN operand propagates.
- An infinite : ; otherwise the result is when and or and , and in the other two cases, included (). No flag is raised.
- An infinite : is a zero and an infinity, negative only for and an odd integral . No flag is raised.
- A zero : is an infinity with
division_by_zeroand a zero, negative only for and an odd integral ; so . - A negative finite with a non-integral is a domain case, a quiet NaN
with
invalid_operation. With an integral (here ) the result is for an even and for an odd one, computed with the directed rounding modes swapped. - with is
try_rootn_ctx(x, n)with . - A result certainly outside the exponent range is decided from certified bounds on .
- An exactly dyadic result is computed and rounded once. For
and (, odd, ) it
exists exactly when divides and is a perfect -th power
(tested as for
rootn, for coefficients of any size); then , which is dyadic for only when . So withoutinexact. A dyadic result whose odd part would need more than bits is not a rounding breakpoint and is left to the next step. - Otherwise the value is certified from enclosures of .
Integrality and parity of are read from its odd coefficient: a finite
nonzero is integral when exponent2() and odd when it is .
When step 10 has shown that the result is not a rounding breakpoint, step 11
moves a representable enclosure end just inside before rounding, so an
exponent so small that lies closer to than the target spacing is
still certified: in binary128() is with inexact. A
few results with a power-of-two base that step 10 cannot classify (an
exponent of magnitude at least , or a scale outside the 32-bit range)
keep the plain test.
Binary::rootn, Binary::rootn_ctx, Binary::try_rootn_ctx
The real -th root .
pub fn Binary::rootn(Self, Int) -> Self
pub fn Binary::rootn_ctx(Self, Int, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_rootn_ctx(Self, Int, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
is a domain case, an invalid operation, for every , a quiet NaN and included (IEEE 754-2019 Table 9.1, “n = 0: invalid operation”); it is not division_by_zero, which IEEE 754-2019 7.3 keeps for an exact infinite result on finite operands, here with . rootn_ctx then returns a quiet NaN with invalid_operation. Every other Int degree is supported, including
Int.min; a NaN propagates. A negative gives .
| odd | even | odd | even | |
|---|---|---|---|---|
| domain case | domain case | |||
, division_by_zero | , division_by_zero | |||
, division_by_zero | , division_by_zero | |||
| finite | domain case | domain case |
So . rounds into the context and
is the correctly rounded . For any other degree an exact root is
detected when divides the exponent of and the odd
coefficient (of any size) is a perfect -th power ; the
result is then rounded once, or for the
correctly rounded reciprocal of it. So
without inexact in every rounding mode, and an exact square root of a
6001-bit coefficient is found as well.
Binary::rsqrt, Binary::rsqrt_ctx, Binary::try_rsqrt_ctx
The reciprocal square root (rSqrt of IEEE 754-2019 §9.2).
pub fn Binary::rsqrt(Self) -> Self
pub fn Binary::rsqrt_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_rsqrt_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
§9.2.1: with no exception and
with division_by_zero, so
(MPFR’s mpfr_rec_sqrt returns
there by its own convention, and the oracle rows follow the standard). A
negative finite and are a domain case (Table 9.1,
”: invalid operation”); a signaling NaN is invalid and a quiet NaN
propagates. A positive finite is rootn_ctx(x, -2): a power of four
gives the exact without inexact, and an exponent far outside
the range is decided without forming the root.
Binary::compound, Binary::compound_ctx, Binary::try_compound_ctx
The compound factor for an integer , with the exact sum
(interest and growth rates, without the rounding of 1 + x).
pub fn Binary::compound(Self, Int) -> Self
pub fn Binary::compound_ctx(Self, Int, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_compound_ctx(Self, Int, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The special values of §9.2.1 are decided first, a signaling NaN before any of them:
| quiet NaN | quiet NaN | quiet NaN | |
| , finite | domain case | domain case | domain case |
, division_by_zero | |||
Otherwise is formed exactly (for any operand up to bits) and
the result is pown_ctx(1 + x, n), so the exact cases, the range decision and
the single rounding are those of pown. When is below
the result is the neighbour of (or ) that the rounding
direction chooses, always inexact and never an underflow. A wider operand
(beyond bits) is not representable in the context and is certified
from .
Binary::powr, Binary::powr_ctx, Binary::try_powr_ctx
The real power defined as , so that the domain excludes a
negative (powr of IEEE 754-2019 §9.2).
pub fn Binary::powr(Self, Self) -> Self
pub fn Binary::powr_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_powr_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The cases are tried in this order, as in IEEE 754-2019 9.2.1; every domain case below is
a quiet NaN with invalid_operation, from powr_ctx and try_powr_ctx alike:
- A signaling NaN operand is invalid; a quiet NaN base gives a quiet NaN.
- A negative ( included, a quiet NaN exponent too) is invalid: for is never a real number.
- A quiet NaN gives a quiet NaN.
- : is invalid; gives with no
exception; a finite gives with
division_by_zero; gives . - : is invalid; gives ; gives .
- : is invalid, any other gives .
- gives .
- Otherwise and is finite and nonzero:
try_pow_ctx(x, y), which owns the exact dyadic cases, the range decision and the rounding.
So ,
and are invalid operations, where
pow gives for the first two and for (§9.2.1).
Binary::hypot, Binary::hypot_ctx, Binary::try_hypot_ctx
without intermediate overflow or underflow.
pub fn Binary::hypot(Self, Self) -> Self
pub fn Binary::hypot_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_hypot_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The squares are formed exactly and one correctly rounded square root is
taken, so the result is and exact when the root is.
even when is a NaN
(invalid_operation is raised only for a signaling NaN). When the smaller
operand is too small to move past the next rounding
breakpoint above , it is replaced by a power of two that rounds the same
way: for with leading bit and
, every becomes . The
exact sum stays small however far apart the exponents are:
is with inexact. The exact sum is refused with a
certification_failure only when its two squares would still be shifted
against each other by more than bits, which needs an operand or target
precision near bits.
Binary::sin, Binary::sin_ctx, Binary::try_sin_ctx
The sine of an argument in radians.
pub fn Binary::sin(Self) -> Self
pub fn Binary::sin_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_sin_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
exactly; an infinite argument is a domain case. The
argument is reduced by an enclosure of computed at a working precision
of at least bits, so the
quadrant is certain for every finite input. When that starting precision
exceeds 8,000,000 bits, that is for , the result is a
certification_failure with stage RangeReduction and reason
ResourceLimit, returned at once; no attempt goes beyond 8,000,000 bits.
Binary::cos, Binary::cos_ctx, Binary::try_cos_ctx
The cosine of an argument in radians.
pub fn Binary::cos(Self) -> Self
pub fn Binary::cos_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_cos_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
exactly. Reduction, domain and limits as for sin.
Binary::tan, Binary::tan_ctx, Binary::try_tan_ctx
The tangent of an argument in radians.
pub fn Binary::tan(Self) -> Self
pub fn Binary::tan_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_tan_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
exactly. Reduction, domain and limits as for sin. No
binary argument is an odd multiple of , so there is no pole; an
enclosure of the cosine that contains zero is refined like any other.
Binary::sinpi, Binary::sinpi_ctx, Binary::try_sinpi_ctx
.
pub fn Binary::sinpi(Self) -> Self
pub fn Binary::sinpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_sinpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The period is reduced exactly on the binary representation, so huge arguments cost nothing extra. For integral , is with the sign of ; at it is . An infinite argument is a domain case. By Niven’s theorem these are the only dyadic arguments with a dyadic result.
Binary::cospi, Binary::cospi_ctx, Binary::try_cospi_ctx
.
pub fn Binary::cospi(Self) -> Self
pub fn Binary::cospi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_cospi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
for integral and
. Reduction and domain as for
sinpi.
Binary::tanpi, Binary::tanpi_ctx, Binary::try_tanpi_ctx
.
pub fn Binary::tanpi(Self) -> Self
pub fn Binary::tanpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_tanpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
For integral , is a zero with the sign of
: for positive odd and
negative even (including ), otherwise, so tanpi(1) is
and tanpi(-1) is . is for
even and for odd , with division_by_zero;
exactly. Reduction and domain
as for sinpi.
Binary::asin, Binary::asin_ctx, Binary::try_asin_ctx
The arcsine, with values in .
pub fn Binary::asin(Self) -> Self
pub fn Binary::asin_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_asin_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is ; a finite argument outside it and both infinities are a domain case. and correctly rounded.
Binary::acos, Binary::acos_ctx, Binary::try_acos_ctx
The arccosine, with values in .
pub fn Binary::acos(Self) -> Self
pub fn Binary::acos_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_acos_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is ; a finite argument outside it and both infinities are
a domain case, and a NaN propagates as for asin. On the result
is evaluated as one enclosure;
exactly and
correctly rounded.
Binary::atan, Binary::atan_ctx, Binary::try_atan_ctx
The arctangent, with values in .
pub fn Binary::atan(Self) -> Self
pub fn Binary::atan_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_atan_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Defined on all of : and correctly rounded.
Binary::atan2, Binary::atan2_ctx, Binary::try_atan2_ctx
The angle of the point for y.atan2(x), in .
pub fn Binary::atan2(Self, Self) -> Self
pub fn Binary::atan2_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_atan2_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The receiver is the ordinate . The special cases follow IEEE 754-2019 §9.2.1; below means or a positive , means or a negative , infinities included:
| result | ||
|---|---|---|
| (exact) | ||
| finite | ||
| finite | (sign of ) | |
| finite | (sign of , exact) | |
| finite | (sign of ) |
A NaN operand propagates. Multiples of are correctly rounded and
inexact. So and
.
Binary::asinpi, Binary::asinpi_ctx, Binary::try_asinpi_ctx
, the angle in half-revolutions (asinPi of IEEE 754-2019 §9.2).
pub fn Binary::asinpi(Self) -> Self
pub fn Binary::asinpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_asinpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is (Table 9.1): and are a
domain case, a quiet NaN with invalid_operation.
with no exception, and
exactly. is rational but not dyadic, so it is rounded and inexact like every
other argument (by Niven’s theorem these are the only rational values).
For a tiny the result is up to a relative error of order and
is rounded from a certified enclosure whatever the exponent range, down to the
implementation subnormal limit.
Binary::acospi, Binary::acospi_ctx, Binary::try_acospi_ctx
.
pub fn Binary::acospi(Self) -> Self
pub fn Binary::acospi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_acospi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is as for asinpi. ,
and ,
exact and without exception (§9.2.1). For a tiny the result is with , so it clusters at the representable :
when the rounding direction alone decides between and
its neighbour on that side (below for , above for ), before the
main loop, and the result is always inexact.
Binary::atanpi, Binary::atanpi_ctx, Binary::try_atanpi_ctx
.
pub fn Binary::atanpi(Self) -> Self
pub fn Binary::atanpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_atanpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Defined on all of . with no exception, with no exception (§9.2.1) and exactly. For the result is with for , so the rounding direction alone decides between and its neighbour inside, without forming a value that close to . A tiny gives rounded from a certified enclosure (underflow with the flags of §7.5 and §7.6).
Binary::atan2pi, Binary::atan2pi_ctx, Binary::try_atan2pi_ctx
for y.atan2pi(x), in .
pub fn Binary::atan2pi(Self, Self) -> Self
pub fn Binary::atan2pi_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_atan2pi_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The receiver is the ordinate . Every special case of §9.2.1 is an exact constant that signals no exception:
| result | ||
|---|---|---|
| finite | ||
| finite | (sign of ) | |
| finite | (sign of ) | |
| finite | (sign of ) |
For finite nonzero operands is
for and
for , with the sign of . gives the exact or
. With the difference of the leading-bit exponents of and
(so ), an extreme ratio is decided from the anchors
before the main loop, from : gives
( for ) with , and
with gives with , each rounded by
direction alone. With and a tiny ratio the result is ;
when is below a quarter of the smallest subnormal ()
it is the tiny nonzero result of the direction with underflow and inexact.
The ratio itself is never formed outside the range where it is
representable, so operands at the two ends of the exponent range are handled.
Binary::sinh, Binary::sinh_ctx, Binary::try_sinh_ctx
The hyperbolic sine.
pub fn Binary::sinh(Self) -> Self
pub fn Binary::sinh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_sinh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
and . Certain overflow is decided before the loop from , which holds for (and overflow needs far above that).
Binary::cosh, Binary::cosh_ctx, Binary::try_cosh_ctx
The hyperbolic cosine.
pub fn Binary::cosh(Self) -> Self
pub fn Binary::cosh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_cosh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
and ; certain overflow is
decided as for sinh.
Binary::tanh, Binary::tanh_ctx, Binary::try_tanh_ctx
The hyperbolic tangent.
pub fn Binary::tanh(Self) -> Self
pub fn Binary::tanh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_tanh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
and exactly.
Binary::asinh, Binary::asinh_ctx, Binary::try_asinh_ctx
The inverse hyperbolic sine.
pub fn Binary::asinh(Self) -> Self
pub fn Binary::asinh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_asinh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
Defined on all of ; and .
Binary::acosh, Binary::acosh_ctx, Binary::try_acosh_ctx
The inverse hyperbolic cosine.
pub fn Binary::acosh(Self) -> Self
pub fn Binary::acosh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_acosh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is ; any smaller argument, included, is a domain case. and .
Binary::atanh, Binary::atanh_ctx, Binary::try_atanh_ctx
The inverse hyperbolic tangent.
pub fn Binary::atanh(Self) -> Self
pub fn Binary::atanh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::try_atanh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
The domain is ; outside it, infinities included, the result is a
domain case. and
with division_by_zero.
///|
test "elementary functions are correctly rounded" {
let ctx = @binary.BinaryContext::binary64()
let one = @binary.Binary::one()
inspect(one.exp_ctx(ctx).0.to_shortest_string(), content="2.718281828459045")
inspect(@binary.Binary::from_int(8).log2(), content="3p0")
let (big, flags) = @binary.Binary::from_int(1000).exp_ctx(ctx)
inspect("\{big} \{flags.overflow()}", content="inf true")
// a domain case is a value in the try_ form too: a NaN with invalid_operation
match @binary.Binary::from_int(-1).try_ln_ctx(ctx) {
Ok((value, flags)) => inspect("\{value} \{flags.invalid_operation()}", content="nan true")
Err(_) => fail("a domain case is not an Err")
}
let (nan, nan_flags) = @binary.Binary::from_int(-1).ln_ctx(ctx)
inspect("\{nan} \{nan_flags.invalid_operation()}", content="nan true")
let (root, root_flags) = @binary.Binary::from_int(-8).rootn_ctx(3, ctx)
inspect("\{root} \{root_flags.inexact()}", content="-1p1 false")
let (pole, pole_flags) = @binary.Binary::from_string("0.5")
.unwrap()
.tanpi_ctx(ctx)
inspect("\{pole} \{pole_flags.division_by_zero()}", content="inf true")
let rz = @binary.BinaryContext::binary64(
rounding=@binary.BinaryRoundingMode::RoundTowardZero,
)
let three_quarters = @binary.Binary::from_string("0.75").unwrap()
let (eight, eight_flags) = @binary.Binary::from_int(16).pow_ctx(
three_quarters, rz,
)
inspect("\{eight} \{eight_flags.inexact()}", content="1p3 false")
let (half, half_flags) = @binary.Binary::from_int(8).rootn_ctx(-3, rz)
inspect("\{half} \{half_flags.inexact()}", content="1p-1 false")
inspect(@binary.Binary::from_int(1).tanpi(), content="-0")
let negative_zero = @binary.Binary::negative_zero()
inspect(negative_zero.atan2(negative_zero), content="-884279719003555p-48")
let tiny = @binary.Binary::make(@binary.BinCoeff::one(), -6000, 53)
inspect(tiny.sin(), content="1p-6000")
}
Trait implementations
Binary::equal, Binary::not_equal
The numerical equality of compare, the hand-written Eq.
pub fn Binary::equal(Self, Self) -> Bool
pub fn Binary::not_equal(Self, Self) -> Bool
See Binary: == and != compare numbers, so -0 == +0,
precisions are ignored and every NaN equals every NaN; identical is the
structural question.
Binary::op_lt, Binary::op_le, Binary::op_gt, Binary::op_ge
The Compare methods behind <, <=, > and >=.
pub fn Binary::op_lt(Self, Self) -> Bool
pub fn Binary::op_le(Self, Self) -> Bool
pub fn Binary::op_gt(Self, Self) -> Bool
pub fn Binary::op_ge(Self, Self) -> Bool
They use compare, so NaN is greater than every number:
nan > x is true. Use the IEEE predicates
when NaN must be unordered.
Binary::output, Binary::to_repr
The Show and Debug methods.
pub fn Binary::output(Self, &Logger) -> Unit
pub fn Binary::to_repr(Self) -> @debug.Repr
output writes the exact c p e form of to_string.
to_repr (used by debug_inspect) shows every private field.
@def.Floating
The shared floating-point vocabulary of floating.
pub impl @def.Floating for Binary
classify, signum, precision, with_precision and normalized are the
inherent methods above. Generic code uses @def.is_finite, @def.is_nan,
@def.is_infinite and @def.is_zero.
Binary::sqrt_checked, Binary::pow_nat_checked, Binary::pow_int_checked
@lf_arith traits whose methods return Result.
pub impl @arithmetic.SqrtChecked for Binary
pub impl @arithmetic.DivChecked for Binary
pub impl @arithmetic.CompareChecked for Binary
pub impl @arithmetic.PowNatChecked for Binary
pub impl @arithmetic.PowIntChecked for Binary
pub fn Binary::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
Each converts the ArithmeticContext with
BinaryContext::from_arithmetic_context (an Err for AwayFromZero, a range
that is not of the IEEE 754-2019 3.3 shape or a precision above
binary_precision_max) and runs the contextual operation. The invalid flag
becomes a domain_error and the division-by-zero flag a division_by_zero
error; the other flags are dropped, so a NaN, an infinity, an overflow or an
underflow is the IEEE 754-2019 default result in Ok, as for the Double
instances of Luna-Flow/arithmetic. sqrt_checked is a domain_error for a
negative nonzero argument (including ) and a signaling NaN; a quiet
NaN of either sign is Ok. DivChecked::div_checked is a domain_error
for , and a signaling NaN operand, and a
division_by_zero error for a finite non-zero dividend over a signed zero;
NaN and are Ok. pow_int_checked is a division_by_zero
error for a zero base with a negative exponent, and both powers are a
domain_error for a signaling NaN base, zero exponent included. There is no
inherent div_checked: the trait form takes the context, and BinaryChecked::div
is the chained form at the larger precision of the operands.
CompareChecked::compare_checked is the inherent
compare_checked.
Binary::add_contextual, Binary::sub_contextual, Binary::mul_contextual, Binary::div_contextual, Binary::abs_contextual, Binary::sqrt_contextual, Binary::exp_contextual
@lf_arith traits that return an ArithmeticOutcome with diagnostics.
pub impl @arithmetic.AddContextual for Binary
pub impl @arithmetic.SubContextual for Binary
pub impl @arithmetic.MulContextual for Binary
pub impl @arithmetic.DivContextual for Binary
pub impl @arithmetic.AbsContextual for Binary
pub impl @arithmetic.SqrtContextual for Binary
pub impl @arithmetic.ExpContextual for Binary
pub fn Binary::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
Each runs the matching *_ctx method (for abs, abs followed by
apply_ctx; for exp, try_exp_ctx) under the converted context. A result
with division_by_zero becomes a division_by_zero error and one with
invalid_operation a domain_error, one with not_computed a
certification_failure; a certification failure of exp is returned as is. Otherwise the value is returned with ArithmeticDiagnostics
whose inexact and rounded are the inexact flag and whose overflow and
underflow are the matching flags.
BinCoeff::op_lt, BinCoeff::op_le, BinCoeff::op_gt, BinCoeff::op_ge, BinCoeff::not_equal
The Compare and Eq methods of BinCoeff, behind <, <=, >, >= and
!=.
pub fn BinCoeff::op_lt(Self, Self) -> Bool
pub fn BinCoeff::op_le(Self, Self) -> Bool
pub fn BinCoeff::op_gt(Self, Self) -> Bool
pub fn BinCoeff::op_ge(Self, Self) -> Bool
pub fn BinCoeff::not_equal(Self, Self) -> Bool
pub impl Compare for BinCoeff
pub impl Eq for BinCoeff
pub impl Show for BinCoeff
pub impl @debug.Debug for BinCoeff
They agree with BinCoeff::compare.
BinCoeff::output, BinCoeff::to_repr
The Show and Debug methods of BinCoeff; to_repr is the integer value.
pub fn BinCoeff::output(Self, &Logger) -> Unit
pub fn BinCoeff::to_repr(Self) -> @debug.Repr
output writes the decimal digits of to_string.
BinaryRoundingMode::equal, BinaryRoundingMode::not_equal, BinaryRoundingMode::to_repr
The derived Eq and Debug methods of BinaryRoundingMode.
pub fn BinaryRoundingMode::equal(Self, Self) -> Bool
pub fn BinaryRoundingMode::not_equal(Self, Self) -> Bool
pub fn BinaryRoundingMode::to_repr(Self) -> @debug.Repr
TininessDetection::equal, TininessDetection::not_equal, TininessDetection::to_repr
The derived Eq and Debug methods of TininessDetection.
pub fn TininessDetection::equal(Self, Self) -> Bool
pub fn TininessDetection::not_equal(Self, Self) -> Bool
pub fn TininessDetection::to_repr(Self) -> @debug.Repr
BinaryContext::equal, BinaryContext::not_equal, BinaryContext::to_repr
The derived Eq and Debug methods of BinaryContext.
pub fn BinaryContext::equal(Self, Self) -> Bool
pub fn BinaryContext::not_equal(Self, Self) -> Bool
pub fn BinaryContext::to_repr(Self) -> @debug.Repr
Equality compares the fields, so BinaryContext::new(precision=53) equals
BinaryContext::new(precision=53, e_max=binary_value_e_max): there is
one representation of every context.
BinaryFlags::equal, BinaryFlags::not_equal, BinaryFlags::to_repr
The derived Eq and Debug methods of BinaryFlags.
pub fn BinaryFlags::equal(Self, Self) -> Bool
pub fn BinaryFlags::not_equal(Self, Self) -> Bool
pub fn BinaryFlags::to_repr(Self) -> @debug.Repr
BinaryInterchangeFormat::equal, BinaryInterchangeFormat::not_equal, BinaryInterchangeFormat::to_repr
The derived Eq and Debug methods of BinaryInterchangeFormat.
pub fn BinaryInterchangeFormat::equal(Self, Self) -> Bool
pub fn BinaryInterchangeFormat::not_equal(Self, Self) -> Bool
pub fn BinaryInterchangeFormat::to_repr(Self) -> @debug.Repr
BinaryInterchange::equal, BinaryInterchange::not_equal
The derived Eq of BinaryInterchange: format and bits must agree.
pub fn BinaryInterchange::equal(Self, Self) -> Bool
pub fn BinaryInterchange::not_equal(Self, Self) -> Bool
Complete public interface
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/binary"
import {
"Luna-Flow/arithmetic",
"Luna-Flow/floating/def",
"Luna-Flow/floating/internal/binary_kernel",
"moonbitlang/core/debug",
}
// Values
pub let binary_precision_max : Int32
pub let binary_value_e_max : Int32
pub let binary_value_e_min : Int32
// Errors
// Types and methods
type BinCoeff
pub fn BinCoeff::bit_length(Self) -> Int32
pub fn BinCoeff::compare(Self, Self) -> Int32
pub fn BinCoeff::equal(Self, Self) -> Bool
pub fn BinCoeff::from_bytes_be(BytesView) -> Self
pub fn BinCoeff::from_kernel(@binary_kernel.Coeff) -> Self
pub fn BinCoeff::from_uint64(UInt64) -> Self
pub fn BinCoeff::is_zero(Self) -> Bool
pub fn BinCoeff::not_equal(Self, Self) -> Bool
pub fn BinCoeff::one() -> Self
pub fn BinCoeff::op_ge(Self, Self) -> Bool
pub fn BinCoeff::op_gt(Self, Self) -> Bool
pub fn BinCoeff::op_le(Self, Self) -> Bool
pub fn BinCoeff::op_lt(Self, Self) -> Bool
pub fn BinCoeff::output(Self, &Logger) -> Unit
pub fn BinCoeff::parse(String, radix? : Int32) -> Result[Self, String]
pub fn BinCoeff::to_bytes_be(Self) -> Bytes
pub fn BinCoeff::to_kernel(Self) -> @binary_kernel.Coeff
pub fn BinCoeff::to_radix_string(Self, Int32) -> String
pub fn BinCoeff::to_repr(Self) -> @debug.Repr
pub fn BinCoeff::to_string(Self) -> String
pub fn BinCoeff::to_uint64(Self) -> UInt64?
pub fn BinCoeff::zero() -> Self
pub impl Compare for BinCoeff
pub impl Eq for BinCoeff
pub impl Show for BinCoeff
pub impl @debug.Debug for BinCoeff
#derive(@debug.Debug)
pub struct Binary(@binary_kernel.BinRepr)
pub fn Binary::abs(Self) -> Self
pub fn Binary::abs_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::acos(Self) -> Self
pub fn Binary::acos_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::acosh(Self) -> Self
pub fn Binary::acosh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::acospi(Self) -> Self
pub fn Binary::acospi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::add(Self, Self) -> Self
pub fn Binary::add_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::add_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::apply_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::asin(Self) -> Self
pub fn Binary::asin_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::asinh(Self) -> Self
pub fn Binary::asinh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::asinpi(Self) -> Self
pub fn Binary::asinpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::atan(Self) -> Self
pub fn Binary::atan2(Self, Self) -> Self
pub fn Binary::atan2_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::atan2pi(Self, Self) -> Self
pub fn Binary::atan2pi_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::atan_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::atanh(Self) -> Self
pub fn Binary::atanh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::atanpi(Self) -> Self
pub fn Binary::atanpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::ceil(Self) -> Self
pub fn Binary::clamp(Self, min~ : Self, max~ : Self) -> Self
pub fn Binary::clamp_checked(Self, min~ : Self, max~ : Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::class_of(Self, BinaryContext) -> @def.IeeeClass
pub fn Binary::classify(Self) -> @arithmetic.FpClass
pub fn Binary::coefficient(Self) -> BinCoeff
pub fn Binary::compare(Self, Self) -> Int32
pub fn Binary::compare_checked(Self, Self) -> Result[Int32, @arithmetic.ArithmeticError]
pub fn Binary::compare_quiet(Self, Self) -> (@def.PartialOrder, BinaryFlags)
pub fn Binary::compare_quiet_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_greater_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_greater_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_less_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_not_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_ordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_quiet_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling(Self, Self) -> (@def.PartialOrder, BinaryFlags)
pub fn Binary::compare_signaling_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_greater_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_less_unordered(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_equal(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_greater(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compare_signaling_not_less(Self, Self) -> (Bool, BinaryFlags)
pub fn Binary::compound(Self, Int32) -> Self
pub fn Binary::compound_ctx(Self, Int32, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::convert_format(Self, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (Self, BinaryFlags)
pub fn Binary::copy_sign(Self, Self) -> Self
pub fn Binary::cos(Self) -> Self
pub fn Binary::cos_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::cosh(Self) -> Self
pub fn Binary::cosh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::cospi(Self) -> Self
pub fn Binary::cospi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::div(Self, Self) -> Self
pub fn Binary::div_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::div_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::equal(Self, Self) -> Bool
pub fn Binary::exp(Self) -> Self
pub fn Binary::exp10(Self) -> Self
pub fn Binary::exp10_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::exp10m1(Self) -> Self
pub fn Binary::exp10m1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::exp2(Self) -> Self
pub fn Binary::exp2_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::exp2m1(Self) -> Self
pub fn Binary::exp2m1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::exp_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::exp_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::expm1(Self) -> Self
pub fn Binary::expm1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::exponent2(Self) -> Int32
pub fn Binary::floor(Self) -> Self
pub fn Binary::fma(Self, Self, Self) -> Self
pub fn Binary::fma_ctx(Self, Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::from_coefficient(BinCoeff, precision? : Int32, negative? : Bool) -> Self
pub fn Binary::from_double(Double, precision? : Int32) -> Self
pub fn Binary::from_float(Float, precision? : Int32) -> Self
pub fn Binary::from_hex(String, Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::from_hex_ctx(String, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::from_int(Int32, precision? : Int32) -> Self
pub fn Binary::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::from_string_ctx(String, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::hypot(Self, Self) -> Self
pub fn Binary::hypot_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::identical(Self, Self) -> Bool
pub fn Binary::ilogb(Self) -> Int32?
pub fn Binary::inf(negative? : Bool, precision? : Int32) -> Self
pub fn Binary::is_finite(Self) -> Bool
pub fn Binary::is_infinite(Self) -> Bool
pub fn Binary::is_nan(Self) -> Bool
pub fn Binary::is_negative_zero(Self) -> Bool
pub fn Binary::is_normal(Self, BinaryContext) -> Bool
pub fn Binary::is_quiet_nan(Self) -> Bool
pub fn Binary::is_sign_minus(Self) -> Bool
pub fn Binary::is_signaling_nan(Self) -> Bool
pub fn Binary::is_subnormal(Self, BinaryContext) -> Bool
pub fn Binary::is_zero(Self) -> Bool
pub fn Binary::ln(Self) -> Self
pub fn Binary::ln_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::log10(Self) -> Self
pub fn Binary::log10_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::log10p1(Self) -> Self
pub fn Binary::log10p1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::log1p(Self) -> Self
pub fn Binary::log1p_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::log2(Self) -> Self
pub fn Binary::log2_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::log2p1(Self) -> Self
pub fn Binary::log2p1_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::logb_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::make(BinCoeff, Int32, Int32, negative? : Bool, mode? : BinaryRoundingMode) -> Self
pub fn Binary::max_num(Self, Self) -> Self
pub fn Binary::min_num(Self, Self) -> Self
pub fn Binary::mul(Self, Self) -> Self
pub fn Binary::mul_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::mul_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::nan(precision? : Int32) -> Self
pub fn Binary::nan_payload(Self) -> BinCoeff
pub fn Binary::neg(Self) -> Self
pub fn Binary::negative_zero(precision? : Int32) -> Self
pub fn Binary::next_down_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::next_up_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::normalized(Self) -> Self
pub fn Binary::not_equal(Self, Self) -> Bool
pub fn Binary::one(precision? : Int32) -> Self
pub fn Binary::op_ge(Self, Self) -> Bool
pub fn Binary::op_gt(Self, Self) -> Bool
pub fn Binary::op_le(Self, Self) -> Bool
pub fn Binary::op_lt(Self, Self) -> Bool
pub fn Binary::output(Self, &Logger) -> Unit
pub fn Binary::pow(Self, Self) -> Self
pub fn Binary::pow_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::pow_int_checked(Self, Int32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::pow_nat_checked(Self, UInt32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::pown(Self, Int32) -> Self
pub fn Binary::pown_ctx(Self, Int32, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::powr(Self, Self) -> Self
pub fn Binary::powr_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::precision(Self) -> Int32
pub fn Binary::quiet_nan(payload? : BinCoeff, negative? : Bool, precision? : Int32) -> Self
pub fn Binary::remainder(Self, Self) -> Self
pub fn Binary::remainder_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::rootn(Self, Int32) -> Self
pub fn Binary::rootn_ctx(Self, Int32, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::round(Self) -> Self
pub fn Binary::round_ties_to_even(Self) -> Self
pub fn Binary::rsqrt(Self) -> Self
pub fn Binary::rsqrt_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::scaleb_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::signaling_nan(payload? : BinCoeff, negative? : Bool, precision? : Int32) -> Self
pub fn Binary::signum(Self) -> @def.Sign
pub fn Binary::sin(Self) -> Self
pub fn Binary::sin_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::sinh(Self) -> Self
pub fn Binary::sinh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::sinpi(Self) -> Self
pub fn Binary::sinpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::sqrt(Self) -> Self
pub fn Binary::sqrt_checked(Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Binary::sqrt_contextual(Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::sqrt_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::sub(Self, Self) -> Self
pub fn Binary::sub_contextual(Self, Self, @arithmetic.ArithmeticContext) -> Result[@arithmetic.ArithmeticOutcome[Self], @arithmetic.ArithmeticError]
pub fn Binary::sub_ctx(Self, Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::tan(Self) -> Self
pub fn Binary::tan_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::tanh(Self) -> Self
pub fn Binary::tanh_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::tanpi(Self) -> Self
pub fn Binary::tanpi_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::to_decimal_string_ctx(Self, Int32, BinaryContext) -> (String, BinaryFlags)
pub fn Binary::to_hex(Self) -> String
pub fn Binary::to_int64_ctx(Self, BinaryContext, exact? : Bool) -> (Int64?, BinaryFlags)
pub fn Binary::to_int_ctx(Self, BinaryContext, exact? : Bool) -> (Int32?, BinaryFlags)
pub fn Binary::to_integral_exact_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::to_integral_value_ctx(Self, BinaryContext) -> (Self, BinaryFlags)
pub fn Binary::to_interchange(Self, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (BinaryInterchange, BinaryFlags)
pub fn Binary::to_repr(Self) -> @debug.Repr
pub fn Binary::to_shortest_string(Self) -> String
pub fn Binary::to_shortest_string_ctx(Self, BinaryContext) -> (String, BinaryFlags)
pub fn Binary::to_string(Self) -> String
pub fn Binary::to_uint64_ctx(Self, BinaryContext, exact? : Bool) -> (UInt64?, BinaryFlags)
pub fn Binary::to_uint_ctx(Self, BinaryContext, exact? : Bool) -> (UInt32?, BinaryFlags)
pub fn Binary::total_order(Self, Self) -> Bool
pub fn Binary::total_order_compare(Self, Self) -> Int32
pub fn Binary::total_order_mag(Self, Self) -> Bool
pub fn Binary::trunc(Self) -> Self
pub fn Binary::try_acos_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_acosh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_acospi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_asin_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_asinh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_asinpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_atan2_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_atan2pi_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_atan_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_atanh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_atanpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_compound_ctx(Self, Int32, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_cos_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_cosh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_cospi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp10_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp10m1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp2_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp2m1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_exp_directed_pair(Self, Int32) -> Result[(Self, Self), @arithmetic.ArithmeticError]
pub fn Binary::try_expm1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_hypot_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_ln_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_ln_directed_pair(Self, Int32) -> Result[(Self, Self), @arithmetic.ArithmeticError]
pub fn Binary::try_log10_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_log10p1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_log1p_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_log2_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_log2p1_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_pow_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_powr_ctx(Self, Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_rootn_ctx(Self, Int32, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_rsqrt_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_sin_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_sinh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_sinpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_tan_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_tanh_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::try_tanpi_ctx(Self, BinaryContext) -> Result[(Self, BinaryFlags), @arithmetic.ArithmeticError]
pub fn Binary::ulp(Self) -> Self
pub fn Binary::with_precision(Self, Int32, BinaryRoundingMode) -> Self
pub fn Binary::zero(precision? : Int32) -> Self
pub impl @arithmetic.AbsContextual for Binary
pub impl @arithmetic.AddContextual for Binary
pub impl @arithmetic.CompareChecked for Binary
pub impl @arithmetic.DivChecked for Binary
pub impl @arithmetic.DivContextual for Binary
pub impl @arithmetic.ExpContextual for Binary
pub impl @arithmetic.MulContextual for Binary
pub impl @arithmetic.PowIntChecked for Binary
pub impl @arithmetic.PowNatChecked for Binary
pub impl @arithmetic.SqrtChecked for Binary
pub impl @arithmetic.SqrtContextual for Binary
pub impl @arithmetic.SubContextual for Binary
pub impl @def.Floating for Binary
pub impl Add for Binary
pub impl Compare for Binary
pub impl Div for Binary
pub impl Eq for Binary
pub impl Mul for Binary
pub impl Neg for Binary
pub impl Show for Binary
pub impl Sub for Binary
#derive(Eq, @debug.Debug)
pub struct BinaryContext {
// private fields
}
pub fn BinaryContext::binary128(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary16(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary32(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::binary64(rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::e_max(Self) -> Int32
pub fn BinaryContext::e_min(Self) -> Int32
pub fn BinaryContext::equal(Self, Self) -> Bool
pub fn BinaryContext::from_arithmetic_context(@arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BinaryContext::new(precision? : Int32, e_max? : Int32, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Self
pub fn BinaryContext::not_equal(Self, Self) -> Bool
pub fn BinaryContext::precision(Self) -> Int32
pub fn BinaryContext::refinement_limit(Self) -> Int32?
pub fn BinaryContext::rounding(Self) -> BinaryRoundingMode
pub fn BinaryContext::tininess(Self) -> TininessDetection
pub fn BinaryContext::to_repr(Self) -> @debug.Repr
pub fn BinaryContext::try_new(precision? : Int32, e_max? : Int32, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BinaryContext::with_e_max(Self, Int32) -> Self
pub fn BinaryContext::with_precision(Self, Int32) -> Self
pub fn BinaryContext::with_refinement_limit(Self, Int32?) -> Self
pub fn BinaryContext::with_rounding(Self, BinaryRoundingMode) -> Self
pub fn BinaryContext::with_tininess(Self, TininessDetection) -> Self
#derive(Eq)
pub struct BinaryFlags(FlagBits)
pub fn BinaryFlags::combine(Self, Self) -> Self
pub fn BinaryFlags::division_by_zero(Self) -> Bool
pub fn BinaryFlags::equal(Self, Self) -> Bool
pub fn BinaryFlags::inexact(Self) -> Bool
pub fn BinaryFlags::invalid_operation(Self) -> Bool
pub fn BinaryFlags::new() -> Self
pub fn BinaryFlags::not_computed(Self) -> Bool
pub fn BinaryFlags::not_equal(Self, Self) -> Bool
pub fn BinaryFlags::overflow(Self) -> Bool
pub fn BinaryFlags::to_repr(Self) -> @debug.Repr
pub fn BinaryFlags::underflow(Self) -> Bool
pub impl @debug.Debug for BinaryFlags
#derive(Eq)
pub struct BinaryInterchange {
// private fields
}
pub fn BinaryInterchange::bits(Self) -> BinCoeff
pub fn BinaryInterchange::equal(Self, Self) -> Bool
pub fn BinaryInterchange::format(Self) -> BinaryInterchangeFormat
pub fn BinaryInterchange::from_binary(Binary, BinaryInterchangeFormat, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> (Self, BinaryFlags)
pub fn BinaryInterchange::from_bits(BinCoeff, BinaryInterchangeFormat) -> Self
pub fn BinaryInterchange::from_hex(String, BinaryInterchangeFormat) -> Self?
pub fn BinaryInterchange::not_equal(Self, Self) -> Bool
pub fn BinaryInterchange::to_binary(Self) -> Binary
pub fn BinaryInterchange::to_hex(Self) -> String
#derive(Eq, @debug.Debug)
pub(all) enum BinaryInterchangeFormat {
Binary16
Binary32
Binary64
Binary128
}
pub fn BinaryInterchangeFormat::bias(Self) -> Int32
pub fn BinaryInterchangeFormat::context(Self, rounding? : BinaryRoundingMode, tininess? : TininessDetection) -> BinaryContext
pub fn BinaryInterchangeFormat::e_max(Self) -> Int32
pub fn BinaryInterchangeFormat::e_min(Self) -> Int32
pub fn BinaryInterchangeFormat::equal(Self, Self) -> Bool
pub fn BinaryInterchangeFormat::exponent_field_width(Self) -> Int32
pub fn BinaryInterchangeFormat::not_equal(Self, Self) -> Bool
pub fn BinaryInterchangeFormat::precision(Self) -> Int32
pub fn BinaryInterchangeFormat::storage_width(Self) -> Int32
pub fn BinaryInterchangeFormat::to_repr(Self) -> @debug.Repr
pub fn BinaryInterchangeFormat::trailing_significand_field_width(Self) -> Int32
#derive(Eq, @debug.Debug)
pub(all) enum BinaryRoundingMode {
RoundTiesToEven
RoundTiesToAway
RoundTowardZero
RoundTowardPositive
RoundTowardNegative
}
pub fn BinaryRoundingMode::equal(Self, Self) -> Bool
pub fn BinaryRoundingMode::from_arithmetic(@arithmetic.RoundingMode) -> Self?
pub fn BinaryRoundingMode::not_equal(Self, Self) -> Bool
pub fn BinaryRoundingMode::to_arithmetic(Self) -> @arithmetic.RoundingMode?
pub fn BinaryRoundingMode::to_repr(Self) -> @debug.Repr
#derive(Eq)
type FlagBits
#derive(Eq, @debug.Debug)
pub(all) enum TininessDetection {
BeforeRounding
AfterRounding
}
pub fn TininessDetection::equal(Self, Self) -> Bool
pub fn TininessDetection::not_equal(Self, Self) -> Bool
pub fn TininessDetection::to_repr(Self) -> @debug.Repr
// Type aliases
// Traits