pub struct Float(/* private fields */);Implementations§
Source§impl Float
impl Float
Sourcepub fn as_hex_js(&self) -> String
pub fn as_hex_js(&self) -> String
Returns the 32-byte hexadecimal string representation of the float.
§Returns
String- The 32-byte hex string.
§Example
const float = Float.fromHex("0x0000000000000000000000000000000000000000000000000000000000000005").value!;
assert(float.asHex() === "0x0000000000000000000000000000000000000000000000000000000000000005");Sourcepub fn to_bigint(&self) -> BigInt
pub fn to_bigint(&self) -> BigInt
Convert the float to a JS/TS bigint equivalent of asHex() returned hex string.
§Throws
if conversion fails.
§Example
const float = Float.fromHex("0xfffffffe0000000000000000000000000000000000000000000000000000013a");
const value = float.toBigInt();
assert(value === 115792089183396302089269705419353877679230723318366275194376439045705909141818n);Sourcepub fn from_bigint(value: BigInt) -> Float
pub fn from_bigint(value: BigInt) -> Float
Constructs a Float from a bigint equivalent of the fromHex() returned Float.
§Throws
if conversion fails.
§Example
const float = Float.fromBigint(115792089183396302089269705419353877679230723318366275194376439045705909141818n);
assert(float.asHex() === "0xfffffffe0000000000000000000000000000000000000000000000000000013a");Sourcepub fn from_fixed_decimal_lossy_js(
value: BigInt,
decimals: u8,
) -> Result<FromFixedDecimalLossyResult, JsValue>
pub fn from_fixed_decimal_lossy_js( value: BigInt, decimals: u8, ) -> Result<FromFixedDecimalLossyResult, JsValue>
Converts a fixed-point decimal value to a Float using the specified number of decimals,
allowing lossy conversions and reporting whether precision was preserved.
This function attempts to convert a fixed-point decimal representation to a Float.
Unlike fromFixedDecimal, this method will not fail if precision is lost during conversion,
but instead reports the loss through the lossless flag in the result.
§Arguments
value- The fixed-point decimal value as a bigint (e.g., 12345n for 123.45 with 2 decimals).decimals- The number of decimal places in the fixed-point representation (0-255).
§Returns
Returns a FromFixedDecimalLossyResult containing:
float- The resultingFloatvalue.lossless- Boolean flag indicating whether the conversion preserved all precision (true) or was lossy (false).
§Errors
Throws a JsValue error if:
- The bigint value cannot be converted to a string.
- The value string cannot be parsed as a valid U256.
- The underlying EVM conversion fails.
§Example
// Lossless conversion
const result = Float.fromFixedDecimalLossy(12345n, 2);
const float = result.float;
const wasLossless = result.lossless;
assert(float.format()?.value === "123.45");
assert(wasLossless === true);
// Potentially lossy conversion
const result2 = Float.fromFixedDecimalLossy(123456789012345678901234567890n, 18);
if (!result2.lossless) {
console.warn("Precision was lost during conversion");
}Source§impl Float
impl Float
Sourcepub fn try_to_bigint(&self) -> Result<BigInt, FloatError>
pub fn try_to_bigint(&self) -> Result<BigInt, FloatError>
Tries to convert the float to a JS/TS bigint equivalent of asHex() returned hex string.
§Returns
Ok(bigint)- The resultingbigintvalue.Err(FloatError)- If the conversion fails.
§Example
const float = Float.fromHex("0xfffffffe0000000000000000000000000000000000000000000000000000013a");
const bigintResult = float.tryToBigInt();
if (bigintResult.error) {
console.error(bigintResult.error);
}
assert(bigintResult.value === 115792089183396302089269705419353877679230723318366275194376439045705909141818n);Sourcepub fn try_from_bigint(value: BigInt) -> Result<Float, FloatError>
pub fn try_from_bigint(value: BigInt) -> Result<Float, FloatError>
Constructs a Float from a bigint equivalent of the fromHex() returned Float.
§Returns
Ok(Float)- The resultingFloatvalue.Err(FloatError)- If the conversion fails.
§Example
const floatResult = Float.tryFromBigint(115792089183396302089269705419353877679230723318366275194376439045705909141818n);
if (floatResult.error) {
console.error(floatResult.error);
}
const value = float.value;
assert(value.asHex() === "0xfffffffe0000000000000000000000000000000000000000000000000000013a");Sourcepub fn from_fixed_decimal_js(
value: BigInt,
decimals: u8,
) -> Result<Float, FloatError>
pub fn from_fixed_decimal_js( value: BigInt, decimals: u8, ) -> Result<Float, FloatError>
Converts a fixed-point decimal value to a Float using the specified number of decimals.
§Arguments
value- The fixed-point decimal value as astring.decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(Float)- The resultingFloatvalue.Err(FloatError)- If the conversion fails.
§Example
const floatResult = Float.fromFixedDecimal("12345", 2);
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.format() === "123.45");Sourcepub fn to_fixed_decimal_js(&self, decimals: u8) -> Result<BigInt, FloatError>
pub fn to_fixed_decimal_js(&self, decimals: u8) -> Result<BigInt, FloatError>
Converts a Float to a fixed-point decimal value using the specified number of decimals.
§Arguments
decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(String)- The resulting fixed-point decimal value as a string.Err(FloatError)- If the conversion fails.
§Example
const float = Float.parse("123.45").value!;
const result = float.toFixedDecimal(2);
if (result.error) {
console.error(result.error);
}
assert(result.value === "12345");Sourcepub fn to_fixed_decimal_lossy_js(
&self,
decimals: u8,
) -> Result<ToFixedDecimalLossyResult, FloatError>
pub fn to_fixed_decimal_lossy_js( &self, decimals: u8, ) -> Result<ToFixedDecimalLossyResult, FloatError>
Converts a Float to a fixed-point decimal value using the specified number of decimals lossy.
§Returns
ToFixedDecimalLossyResult containing the value and lossless flag.
Sourcepub fn parse_js(str: String) -> Result<Float, FloatError>
pub fn parse_js(str: String) -> Result<Float, FloatError>
Parses a decimal string into a Float.
§Arguments
str- The string to parse.
§Returns
Ok(Float)- The parsed float.Err(FloatError)- If parsing fails.
§Example
const floatResult = Float.parse("3.1415");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.format() === "3.1415");Sourcepub fn from_hex_js(hex: &str) -> Result<Float, FloatError>
pub fn from_hex_js(hex: &str) -> Result<Float, FloatError>
Constructs a Float from a 32-byte hexadecimal string.
§Arguments
hex- The 32-byte hex string to parse.
§Returns
Ok(Float)- The float parsed from the hex string.Err(FloatError)- If the hex string is not valid or not 32 bytes.
§Example
const floatResult = Float.fromHex("0x0000000000000000000000000000000000000000000000000000000000000005");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.asHex() === "0x0000000000000000000000000000000000000000000000000000000000000005");Sourcepub fn max_positive_value_js() -> Result<Float, FloatError>
pub fn max_positive_value_js() -> Result<Float, FloatError>
Returns the maximum positive value that can be represented as a Float.
§Returns
Ok(Float)- The maximum positive value.Err(FloatError)- If the EVM call fails.
§Example
const maxPosResult = Float.maxPositiveValue();
if (maxPosResult.error) {
console.error(maxPosResult.error);
}
const maxPos = maxPosResult.value;
assert(!maxPos.format().error);Sourcepub fn min_positive_value_js() -> Result<Float, FloatError>
pub fn min_positive_value_js() -> Result<Float, FloatError>
Returns the minimum positive value that can be represented as a Float.
§Returns
Ok(Float)- The minimum positive value.Err(FloatError)- If the EVM call fails.
§Example
const minPosResult = Float.minPositiveValue();
if (minPosResult.error) {
console.error(minPosResult.error);
}
const minPos = minPosResult.value;
assert(!minPos.format().error);Sourcepub fn max_negative_value_js() -> Result<Float, FloatError>
pub fn max_negative_value_js() -> Result<Float, FloatError>
Returns the maximum negative value that can be represented as a Float.
§Returns
Ok(Float)- The maximum negative value (closest to zero).Err(FloatError)- If the EVM call fails.
§Example
const maxNegResult = Float.maxNegativeValue();
if (maxNegResult.error) {
console.error(maxNegResult.error);
}
const maxNeg = maxNegResult.value;
assert(!maxNeg.format().error);Sourcepub fn min_negative_value_js() -> Result<Float, FloatError>
pub fn min_negative_value_js() -> Result<Float, FloatError>
Returns the minimum negative value that can be represented as a Float.
§Returns
Ok(Float)- The minimum negative value (furthest from zero).Err(FloatError)- If the EVM call fails.
§Example
const minNegResult = Float.minNegativeValue();
if (minNegResult.error) {
console.error(minNegResult.error);
}
const minNeg = minNegResult.value;
assert(!minNeg.format().error);Sourcepub fn zero_js() -> Result<Float, FloatError>
pub fn zero_js() -> Result<Float, FloatError>
Returns the zero value of a Float in its maximized representation.
§Returns
Ok(Float)- The zero value.Err(FloatError)- If the EVM call fails.
§Example
const zeroResult = Float.zero();
if (zeroResult.error) {
console.error(zeroResult.error);
}
const zero = zeroResult.value;
assert(zero.isZero().value);
assert(zero.format().value === "0");Sourcepub fn format_default_scientific_min_js() -> Result<Float, FloatError>
pub fn format_default_scientific_min_js() -> Result<Float, FloatError>
Returns the default minimum value for scientific notation formatting (1e-4).
§Returns
Ok(Float)- The default minimum (1e-4).Err(FloatError)- If the EVM call fails.
§Example
const minResult = Float.formatDefaultScientificMin();
if (minResult.error) {
console.error(minResult.error);
}
const min = minResult.value;
assert(min.format().value === "0.0001");Sourcepub fn format_default_scientific_max_js() -> Result<Float, FloatError>
pub fn format_default_scientific_max_js() -> Result<Float, FloatError>
Returns the default maximum value for scientific notation formatting (1e9).
§Returns
Ok(Float)- The default maximum (1e9).Err(FloatError)- If the EVM call fails.
§Example
const maxResult = Float.formatDefaultScientificMax();
if (maxResult.error) {
console.error(maxResult.error);
}
const max = maxResult.value;
assert(max.format().value === "1000000000");Sourcepub fn format_js(&self) -> Result<String, FloatError>
pub fn format_js(&self) -> Result<String, FloatError>
Formats the float as a decimal string using default scientific notation range (1e-4 to 1e9).
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const floatResult = Float.parse("2.5");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
const formatResult = float.format();
assert(formatResult.value === "2.5");Sourcepub fn format_with_scientific_js(
&self,
scientific: bool,
) -> Result<String, FloatError>
pub fn format_with_scientific_js( &self, scientific: bool, ) -> Result<String, FloatError>
Formats the float as a decimal string with explicit scientific notation control.
§Arguments
scientific- If true, always use scientific notation. If false, use decimal notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const float = Float.parse("123.456").value!;
const decResult = float.formatWithScientific(false);
assert(decResult.value === "123.456");
const sciResult = float.formatWithScientific(true);
assert(sciResult.value === "1.23456e2");Sourcepub fn format_with_range_js(
&self,
scientific_min: &Self,
scientific_max: &Self,
) -> Result<String, FloatError>
pub fn format_with_range_js( &self, scientific_min: &Self, scientific_max: &Self, ) -> Result<String, FloatError>
Formats the float as a decimal string with a custom scientific notation range.
§Arguments
scientific_min- Values smaller than this (in absolute value) use scientific notation.scientific_max- Values larger than this (in absolute value) use scientific notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const float = Float.parse("0.5").value!;
const min = Float.parse("1").value!;
const max = Float.parse("100").value!;
const result = float.formatWithRange(min, max);
assert(result.value === "5e-1");Sourcepub fn lt_js(&self, b: &Self) -> Result<bool, FloatError>
pub fn lt_js(&self, b: &Self) -> Result<bool, FloatError>
Returns true if self is less than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less thanb.Ok(false)ifselfis not less thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.lt(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn eq_js(&self, b: &Self) -> Result<bool, FloatError>
pub fn eq_js(&self, b: &Self) -> Result<bool, FloatError>
Returns true if self is equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis equal tob.Ok(false)ifselfis not equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("2.0").value!;
const result = a.eq(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn lte_js(&self, b: &Self) -> Result<bool, FloatError>
pub fn lte_js(&self, b: &Self) -> Result<bool, FloatError>
Returns true if self is less than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less than or equal tob.Ok(false)ifselfis not less than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.lte(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn gte_js(&self, b: &Self) -> Result<bool, FloatError>
pub fn gte_js(&self, b: &Self) -> Result<bool, FloatError>
Returns true if self is greater than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater than or equal tob.Ok(false)ifselfis not greater than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("1.0").value!;
const result = a.gte(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn gt_js(&self, b: &Self) -> Result<bool, FloatError>
pub fn gt_js(&self, b: &Self) -> Result<bool, FloatError>
Returns true if self is greater than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater thanb.Ok(false)ifselfis not greater thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("1.0").value!;
const result = a.gt(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn inv_js(&self) -> Result<Float, FloatError>
pub fn inv_js(&self) -> Result<Float, FloatError>
Sourcepub fn abs_js(&self) -> Result<Float, FloatError>
pub fn abs_js(&self) -> Result<Float, FloatError>
Sourcepub fn add_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn add_js(&self, b: &Self) -> Result<Float, FloatError>
Sourcepub fn sub_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn sub_js(&self, b: &Self) -> Result<Float, FloatError>
Sourcepub fn mul_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn mul_js(&self, b: &Self) -> Result<Float, FloatError>
Sourcepub fn div_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn div_js(&self, b: &Self) -> Result<Float, FloatError>
Sourcepub fn frac_js(&self) -> Result<Float, FloatError>
pub fn frac_js(&self) -> Result<Float, FloatError>
Sourcepub fn floor_js(&self) -> Result<Float, FloatError>
pub fn floor_js(&self) -> Result<Float, FloatError>
Sourcepub fn min_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn min_js(&self, b: &Self) -> Result<Float, FloatError>
Returns the minimum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The minimum value.Err(FloatError)- If the operation fails.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.min(b);
if (result.error) {
console.error(result.error);
}
assert(result.value.format() === "1");Sourcepub fn max_js(&self, b: &Self) -> Result<Float, FloatError>
pub fn max_js(&self, b: &Self) -> Result<Float, FloatError>
Returns the maximum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The maximum value.Err(FloatError)- If the operation fails.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.max(b);
if (result.error) {
console.error(result.error);
}
assert(result.value.format() === "2");Sourcepub fn is_zero_js(&self) -> Result<bool, FloatError>
pub fn is_zero_js(&self) -> Result<bool, FloatError>
Sourcepub fn neg_js(&self) -> Result<Float, FloatError>
pub fn neg_js(&self) -> Result<Float, FloatError>
Source§impl Float
impl Float
Sourcepub fn try_to_bigint__wasm_export(&self) -> JsValue
pub fn try_to_bigint__wasm_export(&self) -> JsValue
Tries to convert the float to a JS/TS bigint equivalent of asHex() returned hex string.
§Returns
Ok(bigint)- The resultingbigintvalue.Err(FloatError)- If the conversion fails.
§Example
const float = Float.fromHex("0xfffffffe0000000000000000000000000000000000000000000000000000013a");
const bigintResult = float.tryToBigInt();
if (bigintResult.error) {
console.error(bigintResult.error);
}
assert(bigintResult.value === 115792089183396302089269705419353877679230723318366275194376439045705909141818n);Sourcepub fn try_from_bigint__wasm_export(value: BigInt) -> JsValue
pub fn try_from_bigint__wasm_export(value: BigInt) -> JsValue
Constructs a Float from a bigint equivalent of the fromHex() returned Float.
§Returns
Ok(Float)- The resultingFloatvalue.Err(FloatError)- If the conversion fails.
§Example
const floatResult = Float.tryFromBigint(115792089183396302089269705419353877679230723318366275194376439045705909141818n);
if (floatResult.error) {
console.error(floatResult.error);
}
const value = float.value;
assert(value.asHex() === "0xfffffffe0000000000000000000000000000000000000000000000000000013a");Sourcepub fn from_fixed_decimal_js__wasm_export(
value: BigInt,
decimals: u8,
) -> JsValue
pub fn from_fixed_decimal_js__wasm_export( value: BigInt, decimals: u8, ) -> JsValue
Converts a fixed-point decimal value to a Float using the specified number of decimals.
§Arguments
value- The fixed-point decimal value as astring.decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(Float)- The resultingFloatvalue.Err(FloatError)- If the conversion fails.
§Example
const floatResult = Float.fromFixedDecimal("12345", 2);
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.format() === "123.45");Sourcepub fn to_fixed_decimal_js__wasm_export(&self, decimals: u8) -> JsValue
pub fn to_fixed_decimal_js__wasm_export(&self, decimals: u8) -> JsValue
Converts a Float to a fixed-point decimal value using the specified number of decimals.
§Arguments
decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(String)- The resulting fixed-point decimal value as a string.Err(FloatError)- If the conversion fails.
§Example
const float = Float.parse("123.45").value!;
const result = float.toFixedDecimal(2);
if (result.error) {
console.error(result.error);
}
assert(result.value === "12345");Sourcepub fn to_fixed_decimal_lossy_js__wasm_export(&self, decimals: u8) -> JsValue
pub fn to_fixed_decimal_lossy_js__wasm_export(&self, decimals: u8) -> JsValue
Converts a Float to a fixed-point decimal value using the specified number of decimals lossy.
§Returns
ToFixedDecimalLossyResult containing the value and lossless flag.
Sourcepub fn parse_js__wasm_export(str: String) -> JsValue
pub fn parse_js__wasm_export(str: String) -> JsValue
Parses a decimal string into a Float.
§Arguments
str- The string to parse.
§Returns
Ok(Float)- The parsed float.Err(FloatError)- If parsing fails.
§Example
const floatResult = Float.parse("3.1415");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.format() === "3.1415");Sourcepub fn from_hex_js__wasm_export(hex: &str) -> JsValue
pub fn from_hex_js__wasm_export(hex: &str) -> JsValue
Constructs a Float from a 32-byte hexadecimal string.
§Arguments
hex- The 32-byte hex string to parse.
§Returns
Ok(Float)- The float parsed from the hex string.Err(FloatError)- If the hex string is not valid or not 32 bytes.
§Example
const floatResult = Float.fromHex("0x0000000000000000000000000000000000000000000000000000000000000005");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
assert(float.asHex() === "0x0000000000000000000000000000000000000000000000000000000000000005");Sourcepub fn max_positive_value_js__wasm_export() -> JsValue
pub fn max_positive_value_js__wasm_export() -> JsValue
Returns the maximum positive value that can be represented as a Float.
§Returns
Ok(Float)- The maximum positive value.Err(FloatError)- If the EVM call fails.
§Example
const maxPosResult = Float.maxPositiveValue();
if (maxPosResult.error) {
console.error(maxPosResult.error);
}
const maxPos = maxPosResult.value;
assert(!maxPos.format().error);Sourcepub fn min_positive_value_js__wasm_export() -> JsValue
pub fn min_positive_value_js__wasm_export() -> JsValue
Returns the minimum positive value that can be represented as a Float.
§Returns
Ok(Float)- The minimum positive value.Err(FloatError)- If the EVM call fails.
§Example
const minPosResult = Float.minPositiveValue();
if (minPosResult.error) {
console.error(minPosResult.error);
}
const minPos = minPosResult.value;
assert(!minPos.format().error);Sourcepub fn max_negative_value_js__wasm_export() -> JsValue
pub fn max_negative_value_js__wasm_export() -> JsValue
Returns the maximum negative value that can be represented as a Float.
§Returns
Ok(Float)- The maximum negative value (closest to zero).Err(FloatError)- If the EVM call fails.
§Example
const maxNegResult = Float.maxNegativeValue();
if (maxNegResult.error) {
console.error(maxNegResult.error);
}
const maxNeg = maxNegResult.value;
assert(!maxNeg.format().error);Sourcepub fn min_negative_value_js__wasm_export() -> JsValue
pub fn min_negative_value_js__wasm_export() -> JsValue
Returns the minimum negative value that can be represented as a Float.
§Returns
Ok(Float)- The minimum negative value (furthest from zero).Err(FloatError)- If the EVM call fails.
§Example
const minNegResult = Float.minNegativeValue();
if (minNegResult.error) {
console.error(minNegResult.error);
}
const minNeg = minNegResult.value;
assert(!minNeg.format().error);Sourcepub fn zero_js__wasm_export() -> JsValue
pub fn zero_js__wasm_export() -> JsValue
Returns the zero value of a Float in its maximized representation.
§Returns
Ok(Float)- The zero value.Err(FloatError)- If the EVM call fails.
§Example
const zeroResult = Float.zero();
if (zeroResult.error) {
console.error(zeroResult.error);
}
const zero = zeroResult.value;
assert(zero.isZero().value);
assert(zero.format().value === "0");Sourcepub fn format_default_scientific_min_js__wasm_export() -> JsValue
pub fn format_default_scientific_min_js__wasm_export() -> JsValue
Returns the default minimum value for scientific notation formatting (1e-4).
§Returns
Ok(Float)- The default minimum (1e-4).Err(FloatError)- If the EVM call fails.
§Example
const minResult = Float.formatDefaultScientificMin();
if (minResult.error) {
console.error(minResult.error);
}
const min = minResult.value;
assert(min.format().value === "0.0001");Sourcepub fn format_default_scientific_max_js__wasm_export() -> JsValue
pub fn format_default_scientific_max_js__wasm_export() -> JsValue
Returns the default maximum value for scientific notation formatting (1e9).
§Returns
Ok(Float)- The default maximum (1e9).Err(FloatError)- If the EVM call fails.
§Example
const maxResult = Float.formatDefaultScientificMax();
if (maxResult.error) {
console.error(maxResult.error);
}
const max = maxResult.value;
assert(max.format().value === "1000000000");Sourcepub fn format_js__wasm_export(&self) -> WasmEncodedResult<String>
pub fn format_js__wasm_export(&self) -> WasmEncodedResult<String>
Formats the float as a decimal string using default scientific notation range (1e-4 to 1e9).
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const floatResult = Float.parse("2.5");
if (floatResult.error) {
console.error(floatResult.error);
}
const float = floatResult.value;
const formatResult = float.format();
assert(formatResult.value === "2.5");Sourcepub fn format_with_scientific_js__wasm_export(
&self,
scientific: bool,
) -> WasmEncodedResult<String>
pub fn format_with_scientific_js__wasm_export( &self, scientific: bool, ) -> WasmEncodedResult<String>
Formats the float as a decimal string with explicit scientific notation control.
§Arguments
scientific- If true, always use scientific notation. If false, use decimal notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const float = Float.parse("123.456").value!;
const decResult = float.formatWithScientific(false);
assert(decResult.value === "123.456");
const sciResult = float.formatWithScientific(true);
assert(sciResult.value === "1.23456e2");Sourcepub fn format_with_range_js__wasm_export(
&self,
scientific_min: &Self,
scientific_max: &Self,
) -> WasmEncodedResult<String>
pub fn format_with_range_js__wasm_export( &self, scientific_min: &Self, scientific_max: &Self, ) -> WasmEncodedResult<String>
Formats the float as a decimal string with a custom scientific notation range.
§Arguments
scientific_min- Values smaller than this (in absolute value) use scientific notation.scientific_max- Values larger than this (in absolute value) use scientific notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
const float = Float.parse("0.5").value!;
const min = Float.parse("1").value!;
const max = Float.parse("100").value!;
const result = float.formatWithRange(min, max);
assert(result.value === "5e-1");Sourcepub fn lt_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
pub fn lt_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
Returns true if self is less than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less thanb.Ok(false)ifselfis not less thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.lt(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn eq_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
pub fn eq_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
Returns true if self is equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis equal tob.Ok(false)ifselfis not equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("2.0").value!;
const result = a.eq(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn lte_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
pub fn lte_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
Returns true if self is less than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less than or equal tob.Ok(false)ifselfis not less than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.lte(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn gte_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
pub fn gte_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
Returns true if self is greater than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater than or equal tob.Ok(false)ifselfis not greater than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("1.0").value!;
const result = a.gte(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn gt_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
pub fn gt_js__wasm_export(&self, b: &Self) -> WasmEncodedResult<bool>
Returns true if self is greater than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater thanb.Ok(false)ifselfis not greater thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
const a = Float.parse("2.0").value!;
const b = Float.parse("1.0").value!;
const result = a.gt(b);
if (result.error) {
console.error(result.error);
}
assert(result.value);Sourcepub fn inv_js__wasm_export(&self) -> JsValue
pub fn inv_js__wasm_export(&self) -> JsValue
Sourcepub fn abs_js__wasm_export(&self) -> JsValue
pub fn abs_js__wasm_export(&self) -> JsValue
Sourcepub fn add_js__wasm_export(&self, b: &Self) -> JsValue
pub fn add_js__wasm_export(&self, b: &Self) -> JsValue
Sourcepub fn sub_js__wasm_export(&self, b: &Self) -> JsValue
pub fn sub_js__wasm_export(&self, b: &Self) -> JsValue
Sourcepub fn mul_js__wasm_export(&self, b: &Self) -> JsValue
pub fn mul_js__wasm_export(&self, b: &Self) -> JsValue
Sourcepub fn div_js__wasm_export(&self, b: &Self) -> JsValue
pub fn div_js__wasm_export(&self, b: &Self) -> JsValue
Sourcepub fn frac_js__wasm_export(&self) -> JsValue
pub fn frac_js__wasm_export(&self) -> JsValue
Sourcepub fn floor_js__wasm_export(&self) -> JsValue
pub fn floor_js__wasm_export(&self) -> JsValue
Sourcepub fn min_js__wasm_export(&self, b: &Self) -> JsValue
pub fn min_js__wasm_export(&self, b: &Self) -> JsValue
Returns the minimum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The minimum value.Err(FloatError)- If the operation fails.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.min(b);
if (result.error) {
console.error(result.error);
}
assert(result.value.format() === "1");Sourcepub fn max_js__wasm_export(&self, b: &Self) -> JsValue
pub fn max_js__wasm_export(&self, b: &Self) -> JsValue
Returns the maximum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The maximum value.Err(FloatError)- If the operation fails.
§Example
const a = Float.parse("1.0").value!;
const b = Float.parse("2.0").value!;
const result = a.max(b);
if (result.error) {
console.error(result.error);
}
assert(result.value.format() === "2");Sourcepub fn is_zero_js__wasm_export(&self) -> WasmEncodedResult<bool>
pub fn is_zero_js__wasm_export(&self) -> WasmEncodedResult<bool>
Sourcepub fn neg_js__wasm_export(&self) -> JsValue
pub fn neg_js__wasm_export(&self) -> JsValue
Source§impl Float
impl Float
Sourcepub const fn from_raw(value: B256) -> Self
pub const fn from_raw(value: B256) -> Self
Creates a new Float from the given 32-byte value B256.
Sourcepub fn get_inner(&self) -> B256
pub fn get_inner(&self) -> B256
Getter for inner 32-bytes value of this Float instance as B256.
Sourcepub fn set_inner(&mut self, value: B256)
pub fn set_inner(&mut self, value: B256)
Sets the inner 32-byte value of this float from the given B256.
Sourcepub fn from_fixed_decimal(value: U256, decimals: u8) -> Result<Self, FloatError>
pub fn from_fixed_decimal(value: U256, decimals: u8) -> Result<Self, FloatError>
Converts a fixed-point decimal value to a Float using the specified number of decimals.
§Arguments
value- The fixed-point decimal value as aU256.decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(Float)- The resultingFloatvalue.Err(FloatError)- If the conversion fails.
§Example
use rain_math_float::Float;
use alloy::primitives::U256;
// 123.45 with 2 decimals is represented as 12345
let value = U256::from(12345u64);
let decimals = 2u8;
let float = Float::from_fixed_decimal(value, decimals)?;
assert_eq!(float.format()?, "123.45");
anyhow::Ok(())Sourcepub fn to_fixed_decimal(self, decimals: u8) -> Result<U256, FloatError>
pub fn to_fixed_decimal(self, decimals: u8) -> Result<U256, FloatError>
Converts a Float to a fixed-point decimal value using the specified number of decimals.
§Arguments
decimals- The number of decimals in the fixed-point representation.
§Returns
Ok(U256)- The resulting fixed-point decimal value.Err(FloatError)- If the conversion fails.
§Example
use rain_math_float::Float;
use alloy::primitives::U256;
// 123.45 with 2 decimals becomes 12345
let float = Float::parse("123.45".to_string())?;
let fixed = float.to_fixed_decimal(2)?;
assert_eq!(fixed, U256::from(12345u64));
anyhow::Ok(())Sourcepub fn from_fixed_decimal_lossy(
value: U256,
decimals: u8,
) -> Result<(Self, bool), FloatError>
pub fn from_fixed_decimal_lossy( value: U256, decimals: u8, ) -> Result<(Self, bool), FloatError>
Converts a fixed-point decimal value to a Float using the specified number of decimals lossy.
§Arguments
value- The fixed-point decimal value as aU256.decimals- The number of decimals in the fixed-point representation.
§Returns
Ok((Float, bool))- The resultingFloatvalue and a boolean indicating if the conversion was lossless.Err(FloatError)- If the conversion fails.
§Example
use rain_math_float::Float;
use alloy::primitives::U256;
// 123.45 with 2 decimals is represented as 12345
let value = U256::from(12345u64);
let decimals = 2u8;
let (float, lossless) = Float::from_fixed_decimal_lossy(value, decimals)?;
assert_eq!(float.format()?, "123.45");
assert!(lossless);
anyhow::Ok(())Sourcepub fn to_fixed_decimal_lossy(
self,
decimals: u8,
) -> Result<(U256, bool), FloatError>
pub fn to_fixed_decimal_lossy( self, decimals: u8, ) -> Result<(U256, bool), FloatError>
Converts a Float to a fixed-point decimal value using the specified number of decimals lossy.
§Arguments
decimals- The number of decimals in the fixed-point representation.
§Returns
Ok((U256, bool))- The resulting fixed-point decimal value and a boolean indicating if the conversion was lossless.Err(FloatError)- If the conversion fails.
§Example
use rain_math_float::Float;
use alloy::primitives::U256;
// 123.45 with 2 decimals becomes 12345
let float = Float::from_fixed_decimal(U256::from(12345), 3)?;
let (fixed, lossless) = float.to_fixed_decimal_lossy(2)?;
assert_eq!(fixed, U256::from(1234u64));
assert!(!lossless);
anyhow::Ok(())Sourcepub fn parse(str: String) -> Result<Self, FloatError>
pub fn parse(str: String) -> Result<Self, FloatError>
Sourcepub fn as_hex(self) -> String
pub fn as_hex(self) -> String
Returns the 32-byte hexadecimal string representation of the float.
§Returns
String- The 32-byte hex string.
§Example
use rain_math_float::Float;
let float = Float::from_hex("0x0000000000000000000000000000000000000000000000000000000000000005").unwrap();
assert_eq!(float.as_hex(), "0x0000000000000000000000000000000000000000000000000000000000000005");Sourcepub fn from_hex(hex: &str) -> Result<Self, FloatError>
pub fn from_hex(hex: &str) -> Result<Self, FloatError>
Constructs a Float from a 32-byte hexadecimal string.
§Arguments
hex- The 32-byte hex string to parse.
§Returns
Ok(Float)- The float parsed from the hex string.Err(FloatError)- If the hex string is not valid or not 32 bytes.
§Example
use rain_math_float::Float;
let float = Float::from_hex("0x0000000000000000000000000000000000000000000000000000000000000005")?;
assert_eq!(float.as_hex(), "0x0000000000000000000000000000000000000000000000000000000000000005");
anyhow::Ok(())Sourcepub fn max_positive_value() -> Result<Self, FloatError>
pub fn max_positive_value() -> Result<Self, FloatError>
Returns the maximum positive value that can be represented as a Float.
§Returns
Ok(Float)- The maximum positive value.Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let max_pos = Float::max_positive_value()?;
let zero = Float::parse("0".to_string())?;
// Max positive is greater than zero
assert!(max_pos.gt(zero)?);
// Max positive is greater than any normal large number
let big_number = Float::parse("999999999999999999999".to_string())?;
assert!(max_pos.gt(big_number)?);
anyhow::Ok(())Sourcepub fn min_positive_value() -> Result<Self, FloatError>
pub fn min_positive_value() -> Result<Self, FloatError>
Returns the minimum positive value that can be represented as a Float.
§Returns
Ok(Float)- The minimum positive value.Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let min_pos = Float::min_positive_value()?;
let zero = Float::parse("0".to_string())?;
// Min positive is greater than zero but smaller than any other positive number
assert!(min_pos.gt(zero)?);
let small_number = Float::parse("0.000000000000000001".to_string())?;
assert!(min_pos.lt(small_number)?);
anyhow::Ok(())Sourcepub fn max_negative_value() -> Result<Self, FloatError>
pub fn max_negative_value() -> Result<Self, FloatError>
Returns the maximum negative value that can be represented as a Float.
§Returns
Ok(Float)- The maximum negative value (closest to zero).Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let max_neg = Float::max_negative_value()?;
let zero = Float::parse("0".to_string())?;
// Max negative is less than zero but greater than any other negative number
assert!(max_neg.lt(zero)?);
let small_negative = Float::parse("-0.000000000000000001".to_string())?;
assert!(max_neg.gt(small_negative)?);
anyhow::Ok(())Sourcepub fn min_negative_value() -> Result<Self, FloatError>
pub fn min_negative_value() -> Result<Self, FloatError>
Returns the minimum negative value that can be represented as a Float.
§Returns
Ok(Float)- The minimum negative value (furthest from zero).Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let min_neg = Float::min_negative_value()?;
let zero = Float::parse("0".to_string())?;
// Min negative is less than zero
assert!(min_neg.lt(zero)?);
// Min negative is less than any normal negative number
let big_negative = Float::parse("-999999999999999999999".to_string())?;
assert!(min_neg.lt(big_negative)?);
anyhow::Ok(())Sourcepub fn zero() -> Result<Self, FloatError>
pub fn zero() -> Result<Self, FloatError>
Returns the zero value of a Float in its maximized representation.
§Returns
Ok(Float)- The zero value.Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let zero = Float::zero()?;
assert!(zero.is_zero()?);
assert_eq!(zero.format()?, "0");
// Should be equal to parsed zero
let parsed_zero = Float::parse("0".to_string())?;
assert!(zero.eq(parsed_zero)?);
anyhow::Ok(())Sourcepub fn format_default_scientific_min() -> Result<Self, FloatError>
pub fn format_default_scientific_min() -> Result<Self, FloatError>
Returns the default minimum value for scientific notation formatting (1e-4).
Values smaller than this (in absolute value) will be formatted in scientific notation.
§Returns
Ok(Float)- The default minimum (1e-4).Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let min = Float::format_default_scientific_min()?;
assert_eq!(min.format()?, "0.0001");
anyhow::Ok(())Sourcepub fn format_default_scientific_max() -> Result<Self, FloatError>
pub fn format_default_scientific_max() -> Result<Self, FloatError>
Returns the default maximum value for scientific notation formatting (1e9).
Values larger than this (in absolute value) will be formatted in scientific notation.
§Returns
Ok(Float)- The default maximum (1e9).Err(FloatError)- If the EVM call fails.
§Example
use rain_math_float::Float;
let max = Float::format_default_scientific_max()?;
assert_eq!(max.format()?, "1000000000");
anyhow::Ok(())Sourcepub fn format(self) -> Result<String, FloatError>
pub fn format(self) -> Result<String, FloatError>
Formats the float as a decimal string using default scientific notation range (1e-4 to 1e9).
Values within the range [1e-4, 1e9] will use decimal notation. Values outside this range will use scientific notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Examples
Values within the default range use decimal notation:
use rain_math_float::Float;
// At the boundaries (inclusive)
assert_eq!(Float::parse("0.0001".to_string())?.format()?, "0.0001"); // 1e-4
assert_eq!(Float::parse("1000000000".to_string())?.format()?, "1000000000"); // 1e9
// Within range
assert_eq!(Float::parse("2.5".to_string())?.format()?, "2.5");
assert_eq!(Float::parse("123.456".to_string())?.format()?, "123.456");
assert_eq!(Float::parse("0.001".to_string())?.format()?, "0.001");
assert_eq!(Float::parse("1000000".to_string())?.format()?, "1000000");
anyhow::Ok(())Values outside the default range use scientific notation:
use rain_math_float::Float;
// Smaller than 1e-4
assert_eq!(Float::parse("0.00001".to_string())?.format()?, "1e-5");
assert_eq!(Float::parse("0.000001".to_string())?.format()?, "1e-6");
// Larger than 1e9
assert_eq!(Float::parse("10000000000".to_string())?.format()?, "1e10");
assert_eq!(Float::parse("123000000000".to_string())?.format()?, "1.23e11");
anyhow::Ok(())Sourcepub fn format_with_scientific(
self,
scientific: bool,
) -> Result<String, FloatError>
pub fn format_with_scientific( self, scientific: bool, ) -> Result<String, FloatError>
Formats the float as a decimal string with explicit scientific notation control.
§Arguments
scientific- If true, always use scientific notation. If false, use decimal notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
use rain_math_float::Float;
let float = Float::parse("3.14".to_string())?;
assert_eq!(float.format_with_scientific(false)?, "3.14");
assert_eq!(float.format_with_scientific(true)?, "3.14");
anyhow::Ok(())Sourcepub fn format_with_range(
self,
scientific_min: Self,
scientific_max: Self,
) -> Result<String, FloatError>
pub fn format_with_range( self, scientific_min: Self, scientific_max: Self, ) -> Result<String, FloatError>
Formats the float as a decimal string with a custom scientific notation range.
§Arguments
scientific_min- Values smaller than this (in absolute value) use scientific notation.scientific_max- Values larger than this (in absolute value) use scientific notation.
§Returns
Ok(String)- The formatted string.Err(FloatError)- If formatting fails.
§Example
use rain_math_float::Float;
let float = Float::parse("0.001".to_string())?;
let min = Float::parse("0.01".to_string())?;
let max = Float::parse("100".to_string())?;
assert_eq!(float.format_with_range(min, max)?, "1e-3");
anyhow::Ok(())Sourcepub fn lt(self, b: Self) -> Result<bool, FloatError>
pub fn lt(self, b: Self) -> Result<bool, FloatError>
Returns true if self is less than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less thanb.Ok(false)ifselfis not less thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
use rain_math_float::Float;
let a = Float::parse("1.0".to_string())?;
let b = Float::parse("2.0".to_string())?;
assert!(a.lt(b)?);
anyhow::Ok(())Sourcepub fn eq(self, b: Self) -> Result<bool, FloatError>
pub fn eq(self, b: Self) -> Result<bool, FloatError>
Returns true if self is equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis equal tob.Ok(false)ifselfis not equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
use rain_math_float::Float;
let a = Float::parse("3.14".to_string())?;
let b = Float::parse("3.14".to_string())?;
assert!(a.eq(b)?);
anyhow::Ok(())Sourcepub fn gt(self, b: Self) -> Result<bool, FloatError>
pub fn gt(self, b: Self) -> Result<bool, FloatError>
Returns true if self is greater than b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater thanb.Ok(false)ifselfis not greater thanb.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
use rain_math_float::Float;
let a = Float::parse("5.0".to_string())?;
let b = Float::parse("2.0".to_string())?;
assert!(a.gt(b)?);
anyhow::Ok(())Sourcepub fn inv(self) -> Result<Self, FloatError>
pub fn inv(self) -> Result<Self, FloatError>
Sourcepub fn abs(self) -> Result<Float, FloatError>
pub fn abs(self) -> Result<Float, FloatError>
Sourcepub fn lte(self, b: Self) -> Result<bool, FloatError>
pub fn lte(self, b: Self) -> Result<bool, FloatError>
Returns true if self is less than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis less than or equal tob.Ok(false)ifselfis not less than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
use rain_math_float::Float;
let a = Float::parse("1.0".to_string())?;
let b = Float::parse("2.0".to_string())?;
assert!(a.lte(b)?);
anyhow::Ok(())Sourcepub fn gte(self, b: Self) -> Result<bool, FloatError>
pub fn gte(self, b: Self) -> Result<bool, FloatError>
Returns true if self is greater than or equal to b.
§Arguments
b- TheFloatvalue to compare withself.
§Returns
Ok(true)ifselfis greater than or equal tob.Ok(false)ifselfis not greater than or equal tob.Err(FloatError)if the comparison fails due to an error in the underlying EVM call or decoding.
§Example
use rain_math_float::Float;
let a = Float::parse("2.0".to_string())?;
let b = Float::parse("1.0".to_string())?;
assert!(a.gte(b)?);
anyhow::Ok(())Source§impl Float
impl Float
Sourcepub fn integer(self) -> Result<Float, FloatError>
pub fn integer(self) -> Result<Float, FloatError>
Returns the integer part of the float (truncation toward zero).
§Returns
Ok(Float)- The integer part.Err(FloatError)- If the operation fails.
§Example
use rain_math_float::Float;
let x = Float::parse("3.75".to_string())?;
let int = x.integer()?;
assert_eq!(int.format()?, "3");
let y = Float::parse("-3.75".to_string())?;
let int_y = y.integer()?;
assert_eq!(int_y.format()?, "-3");
anyhow::Ok(())Sourcepub fn frac(self) -> Result<Float, FloatError>
pub fn frac(self) -> Result<Float, FloatError>
Sourcepub fn floor(self) -> Result<Float, FloatError>
pub fn floor(self) -> Result<Float, FloatError>
Sourcepub fn min(self, b: Self) -> Result<Self, FloatError>
pub fn min(self, b: Self) -> Result<Self, FloatError>
Returns the minimum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The minimum value.Err(FloatError)- If the operation fails.
§Example
use rain_math_float::Float;
let a = Float::parse("1.0".to_string())?;
let b = Float::parse("2.0".to_string())?;
let min = a.min(b)?;
assert_eq!(min.format()?, "1");
anyhow::Ok(())Sourcepub fn max(self, b: Self) -> Result<Self, FloatError>
pub fn max(self, b: Self) -> Result<Self, FloatError>
Returns the maximum of self and b.
§Arguments
b- The otherFloatto compare with.
§Returns
Ok(Float)- The maximum value.Err(FloatError)- If the operation fails.
§Example
use rain_math_float::Float;
let a = Float::parse("1.0".to_string())?;
let b = Float::parse("2.0".to_string())?;
let max = a.max(b)?;
assert_eq!(max.format()?, "2");
anyhow::Ok(())Sourcepub fn is_zero(self) -> Result<bool, FloatError>
pub fn is_zero(self) -> Result<bool, FloatError>
Checks if the float is zero.
§Returns
Ok(true)if the float is zero.Ok(false)if the float is not zero.Err(FloatError)if the operation fails.
§Example
use rain_math_float::Float;
let zero = Float::parse("0".to_string())?;
assert!(zero.is_zero()?);
let nonzero = Float::parse("1.23".to_string())?;
assert!(!nonzero.is_zero()?);
anyhow::Ok(())Trait Implementations§
Source§impl<'de> Deserialize<'de> for Float
impl<'de> Deserialize<'de> for Float
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<FixedBytes<32>> for Float
impl From<FixedBytes<32>> for Float
Source§impl FromWasmAbi for Float
impl FromWasmAbi for Float
Source§impl IntoWasmAbi for Float
impl IntoWasmAbi for Float
Source§impl LongRefFromWasmAbi for Float
impl LongRefFromWasmAbi for Float
Source§impl OptionFromWasmAbi for Float
impl OptionFromWasmAbi for Float
Source§impl OptionIntoWasmAbi for Float
impl OptionIntoWasmAbi for Float
Source§impl RefFromWasmAbi for Float
impl RefFromWasmAbi for Float
Source§impl RefMutFromWasmAbi for Float
impl RefMutFromWasmAbi for Float
Source§impl TryFromJsValue for Float
impl TryFromJsValue for Float
Source§impl VectorFromWasmAbi for Float
impl VectorFromWasmAbi for Float
Source§impl VectorIntoWasmAbi for Float
impl VectorIntoWasmAbi for Float
impl Copy for Float
impl SupportsConstructor for Float
impl SupportsInstanceProperty for Float
impl SupportsStaticProperty for Float
Auto Trait Implementations§
impl Freeze for Float
impl RefUnwindSafe for Float
impl Send for Float
impl Sync for Float
impl Unpin for Float
impl UnsafeUnpin for Float
impl UnwindSafe for Float
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.