@def
This page tracks the current repository implementation and is written as the 0.2.0 API baseline.
pub(all) enum Sign
enum Sign {
Negative
Zero
Positive
}Description Represents the sign classification shared by all floating packages.
Semantic Notes
Zeromeans "numerically zero or sign-indeterminate zero-like result" in the current package set.ball_floatmay returnZerowhen the enclosure straddles both negative and positive values.
pub(all) enum FpClass
enum FpClass {
Finite
Infinity
NaN
}- Description Shared floating-point class used by
bin_float,decimal, andball_float.
pub(all) enum RoundingMode
enum RoundingMode {
ToNearestEven
TowardZero
TowardPositive
TowardNegative
AwayFromZero
}Description Requests a rounding direction when precision reduction or approximate conversion is required.
Semantic Notes
ToNearestEvenis the repository default for precision-controlled constructors and conversions unless a method documents otherwise.ball_floatuses outward-oriented rounding choices internally when widening an enclosure.
pub(open) trait Floating
trait Floating {
fn classify(Self) -> FpClass
fn sign(Self) -> Sign
fn precision(Self) -> Int
fn with_precision(Self, Int, RoundingMode) -> Self
fn normalized(Self) -> Self
}- Description The shared capability boundary for Luna Flow floating-like values.
Required Methods
fn classify(Self) -> FpClassReturns the current classification: finite, infinity, or NaN.fn sign(Self) -> SignReturns the sign classification for the current value.fn precision(Self) -> IntReturns the current working precision stored on the value.fn with_precision(Self, Int, RoundingMode) -> SelfRetunes the value to a requested precision using the given rounding mode.fn normalized(Self) -> SelfReturns the canonical normalized form for the value.
Current Implementations
@bin_float.BinFloat@decimal.Decimal@ball_float.BallFloat
Helper Predicates
fn[F : Floating] is_finite(x : F) -> BoolReturnstruewhenclassify(x) == FpClass::Finite.fn[F : Floating] is_nan(x : F) -> BoolReturnstruewhenclassify(x) == FpClass::NaN.fn[F : Floating] is_infinite(x : F) -> BoolReturnstruewhenclassify(x) == FpClass::Infinity.fn[F : Floating] is_zero(x : F) -> BoolReturnstruewhenxis finite andsign(x) == Sign::Zero.