Movatterモバイル変換


[0]ホーム

URL:


f32

Primitive Typef32 

1.0.0
Expand description

A 32-bit floating-point type (specifically, the “binary32” type defined in IEEE 754-2008).

This type can represent a wide range of decimal numbers, like3.5,27,-113.75,0.0078125,34359738368,0,-1. So unlike integer types(such asi32), floating-point types can represent non-integer numbers,too.

However, being able to represent this wide range of numbers comes at thecost of precision: floats can only represent some of the real numbers andcalculation with floats round to a nearby representable number. For example,5.0 and1.0 can be exactly represented asf32, but1.0 / 5.0 resultsin0.20000000298023223876953125 since0.2 cannot be exactly representedasf32. Note, however, that printing floats withprintln and friends willoften discard insignificant digits:println!("{}", 1.0f32 / 5.0f32) willprint0.2.

Additionally,f32 can represent some special values:

  • −0.0: IEEE 754 floating-point numbers have a bit that indicates their sign, so −0.0 is apossible value. For comparison −0.0 = +0.0, but floating-point operations can carrythe sign bit through arithmetic operations. This means −0.0 × +0.0 produces −0.0 anda negative number rounded to a value smaller than a float can represent also produces −0.0.
  • and−∞: these result from calculationslike1.0 / 0.0.
  • NaN (not a number): this value results fromcalculations like(-1.0).sqrt(). NaN has some potentially unexpectedbehavior:
    • It is not equal to any float, including itself! This is the reasonf32doesn’t implement theEq trait.
    • It is also neither smaller nor greater than any float, making itimpossible to sort by the default comparison operation, which is thereasonf32 doesn’t implement theOrd trait.
    • It is also consideredinfectious as almost all calculations where oneof the operands is NaN will also result in NaN. The explanations on thispage only explicitly document behavior on NaN operands if this defaultis deviated from.
    • Lastly, there are multiple bit patterns that are considered NaN.Rust does not currently guarantee that the bit patterns of NaN arepreserved over arithmetic operations, and they are not guaranteed to beportable or even fully deterministic! This means that there may be somesurprising results upon inspecting the bit patterns,as the same calculations might produce NaNs with different bit patterns.This also affects the sign of the NaN: checkingis_sign_positive oris_sign_negative ona NaN is the most common way to run into these surprising results.(Checkingx >= 0.0 orx <= 0.0 avoids those surprises, but also how negative/positivezero are treated.)See the section below for what exactly is guaranteed about the bit pattern of a NaN.

When a primitive operation (addition, subtraction, multiplication, ordivision) is performed on this type, the result is rounded according to theroundTiesToEven direction defined in IEEE 754-2008. That means:

  • The result is the representable value closest to the true value, if thereis a unique closest representable value.
  • If the true value is exactly half-way between two representable values,the result is the one with an even least-significant binary digit.
  • If the true value’s magnitude is ≥f32::MAX + 2(f32::MAX_EXPf32::MANTISSA_DIGITS − 1), the result is ∞ or −∞ (preserving thetrue value’s sign).
  • If the result of a sum exactly equals zero, the outcome is +0.0 unlessboth arguments were negative, then it is -0.0. Subtractiona - b isregarded as a suma + (-b).

For more information on floating-point numbers, seeWikipedia.

See also thestd::f32::consts module.

§NaN bit patterns

This section defines the possible NaN bit patterns returned by floating-point operations.

The bit pattern of a floating-point NaN value is defined by:

  • a sign bit.
  • a quiet/signaling bit. Rust assumes that the quiet/signaling bit being set to1 indicates aquiet NaN (QNaN), and a value of0 indicates a signaling NaN (SNaN). In the following wewill hence just call it the “quiet bit”.
  • a payload, which makes up the rest of the significand (i.e., the mantissa) except for thequiet bit.

The rules for NaN values differ betweenarithmetic andnon-arithmetic (or “bitwise”)operations. The non-arithmetic operations are unary-,abs,copysign,signum,{to,from}_bits,{to,from}_{be,le,ne}_bytes andis_sign_{positive,negative}. Theseoperations are guaranteed to exactly preserve the bit pattern of their input except for possiblychanging the sign bit.

The following rules apply when a NaN value is returned from an arithmetic operation:

  • The result has a non-deterministic sign.

  • The quiet bit and payload are non-deterministically chosen fromthe following set of options:

    • Preferred NaN: The quiet bit is set and the payload is all-zero.
    • Quieting NaN propagation: The quiet bit is set and the payload is copied from any inputoperand that is a NaN. If the inputs and outputs do not have the same payload size (i.e., foras casts), then
      • If the output is smaller than the input, low-order bits of the payload get dropped.
      • If the output is larger than the input, the payload gets filled up with 0s in the low-orderbits.
    • Unchanged NaN propagation: The quiet bit and payload are copied from any input operandthat is a NaN. If the inputs and outputs do not have the same size (i.e., foras casts), thesame rules as for “quieting NaN propagation” apply, with one caveat: if the output is smallerthan the input, dropping the low-order bits may result in a payload of 0; a payload of 0 is notpossible with a signaling NaN (the all-0 significand encodes an infinity) so unchanged NaNpropagation cannot occur with some inputs.
    • Target-specific NaN: The quiet bit is set and the payload is picked from a target-specificset of “extra” possible NaN payloads. The set can depend on the input operand values.See the table below for the concrete NaNs this set contains on various targets.

In particular, if all input NaNs are quiet (or if there are no input NaNs), then the output NaNis definitely quiet. Signaling NaN outputs can only occur if they are provided as an inputvalue. Similarly, if all input NaNs are preferred (or if there are no input NaNs) and the targetdoes not have any “extra” NaN payloads, then the output NaN is guaranteed to be preferred.

The non-deterministic choice happens when the operation is executed; i.e., the result of aNaN-producing floating-point operation is a stable bit pattern (looking at these bits multipletimes will yield consistent results), but running the same operation twice with the same inputscan produce different results.

These guarantees are neither stronger nor weaker than those of IEEE 754: IEEE 754 guaranteesthat an operation never returns a signaling NaN, whereas it is possible for operations likeSNAN * 1.0 to return a signaling NaN in Rust. Conversely, IEEE 754 makes no statement at allabout which quiet NaN is returned, whereas Rust restricts the set of possible results to theones listed above.

Unless noted otherwise, the same rules also apply to NaNs returned by other library functions(e.g.min,minimum,max,maximum); other aspects of their semantics and which IEEE 754operation they correspond to are documented with the respective functions.

When an arithmetic floating-point operation is executed inconst context, the same rulesapply: no guarantee is made about which of the NaN bit patterns described above will bereturned. The result does not have to match what happens when executing the same code atruntime, and the result can vary depending on factors such as compiler version and flags.

§Target-specific “extra” NaN values

target_archExtra payloads possible on this platform
aarch64,arm,arm64ec,loongarch64,powerpc (except whentarget_abi = "spe"),powerpc64,riscv32,riscv64,s390x,x86,x86_64None
nvptx64All payloads
sparc,sparc64The all-one payload
wasm32,wasm64If all input NaNs are quiet with all-zero payload: None.
Otherwise: all payloads.

For targets not in this table, all payloads are possible.

§Algebraic operators

Algebraic operators of the forma.algebraic_*(b) allow the compiler to optimizefloating point operations using all the usual algebraic properties of real numbers –despite the fact that those properties donot hold on floating point numbers.This can give a great performance boost since it may unlock vectorization.

The exact set of optimizations is unspecified but typically allows combining operations,rearranging series of operations based on mathematical properties, converting between divisionand reciprocal multiplication, and disregarding the sign of zero. This means that the results ofelementary operations may have undefined precision, and “non-mathematical” valuessuch as NaN, +/-Inf, or -0.0 may behave in unexpected ways, but these operationswill never cause undefined behavior.

Because of the unpredictable nature of compiler optimizations, the same inputs may producedifferent results even within a single program run.Unsafe code must not rely on any propertyof the return value for soundness. However, implementations will generally do their best topick a reasonable tradeoff between performance and accuracy of the result.

For example:

x = a.algebraic_add(b).algebraic_add(c).algebraic_add(d);

May be rewritten as:

x = a + b + c + d;// As writtenx = (a + c) + (b + d);// Reordered to shorten critical path and enable vectorization

Implementations§

Source§

implf32

1.0.0 (const: 1.90.0) ·Source

pub const fnfloor(self) ->f32

Returns the largest integer less than or equal toself.

This function always returns the precise result.

§Examples
letf =3.7_f32;letg =3.0_f32;leth = -3.7_f32;assert_eq!(f.floor(),3.0);assert_eq!(g.floor(),3.0);assert_eq!(h.floor(), -4.0);
1.0.0 (const: 1.90.0) ·Source

pub const fnceil(self) ->f32

Returns the smallest integer greater than or equal toself.

This function always returns the precise result.

§Examples
letf =3.01_f32;letg =4.0_f32;assert_eq!(f.ceil(),4.0);assert_eq!(g.ceil(),4.0);
1.0.0 (const: 1.90.0) ·Source

pub const fnround(self) ->f32

Returns the nearest integer toself. If a value is half-way between twointegers, round away from0.0.

This function always returns the precise result.

§Examples
letf =3.3_f32;letg = -3.3_f32;leth = -3.7_f32;leti =3.5_f32;letj =4.5_f32;assert_eq!(f.round(),3.0);assert_eq!(g.round(), -3.0);assert_eq!(h.round(), -4.0);assert_eq!(i.round(),4.0);assert_eq!(j.round(),5.0);
1.77.0 (const: 1.90.0) ·Source

pub const fnround_ties_even(self) ->f32

Returns the nearest integer to a number. Rounds half-way cases to the numberwith an even least significant digit.

This function always returns the precise result.

§Examples
letf =3.3_f32;letg = -3.3_f32;leth =3.5_f32;leti =4.5_f32;assert_eq!(f.round_ties_even(),3.0);assert_eq!(g.round_ties_even(), -3.0);assert_eq!(h.round_ties_even(),4.0);assert_eq!(i.round_ties_even(),4.0);
1.0.0 (const: 1.90.0) ·Source

pub const fntrunc(self) ->f32

Returns the integer part ofself.This means that non-integer numbers are always truncated towards zero.

This function always returns the precise result.

§Examples
letf =3.7_f32;letg =3.0_f32;leth = -3.7_f32;assert_eq!(f.trunc(),3.0);assert_eq!(g.trunc(),3.0);assert_eq!(h.trunc(), -3.0);
1.0.0 (const: 1.90.0) ·Source

pub const fnfract(self) ->f32

Returns the fractional part ofself.

This function always returns the precise result.

§Examples
letx =3.6_f32;lety = -3.6_f32;letabs_difference_x = (x.fract() -0.6).abs();letabs_difference_y = (y.fract() - (-0.6)).abs();assert!(abs_difference_x <= f32::EPSILON);assert!(abs_difference_y <= f32::EPSILON);
1.0.0 ·Source

pub fnmul_add(self, a:f32, b:f32) ->f32

Fused multiply-add. Computes(self * a) + b with only one roundingerror, yielding a more accurate result than an unfused multiply-add.

Usingmul_addmay be more performant than an unfused multiply-add ifthe target architecture has a dedicatedfma CPU instruction. However,this is not always true, and will be heavily dependant on designingalgorithms with specific target hardware in mind.

§Precision

The result of this operation is guaranteed to be the roundedinfinite-precision result. It is specified by IEEE 754 asfusedMultiplyAdd and guaranteed not to change.

§Examples
letm =10.0_f32;letx =4.0_f32;letb =60.0_f32;assert_eq!(m.mul_add(x, b),100.0);assert_eq!(m * x + b,100.0);letone_plus_eps =1.0_f32+ f32::EPSILON;letone_minus_eps =1.0_f32- f32::EPSILON;letminus_one = -1.0_f32;// The exact result (1 + eps) * (1 - eps) = 1 - eps * eps.assert_eq!(one_plus_eps.mul_add(one_minus_eps, minus_one), -f32::EPSILON * f32::EPSILON);// Different rounding with the non-fused multiply and add.assert_eq!(one_plus_eps * one_minus_eps + minus_one,0.0);
1.38.0 ·Source

pub fndiv_euclid(self, rhs:f32) ->f32

Calculates Euclidean division, the matching method forrem_euclid.

This computes the integern such thatself = n * rhs + self.rem_euclid(rhs).In other words, the result isself / rhs rounded to the integernsuch thatself >= n * rhs.

§Precision

The result of this operation is guaranteed to be the roundedinfinite-precision result.

§Examples
leta: f32 =7.0;letb =4.0;assert_eq!(a.div_euclid(b),1.0);// 7.0 > 4.0 * 1.0assert_eq!((-a).div_euclid(b), -2.0);// -7.0 >= 4.0 * -2.0assert_eq!(a.div_euclid(-b), -1.0);// 7.0 >= -4.0 * -1.0assert_eq!((-a).div_euclid(-b),2.0);// -7.0 >= -4.0 * 2.0
1.38.0 ·Source

pub fnrem_euclid(self, rhs:f32) ->f32

Calculates the least nonnegative remainder ofself (mod rhs).

In particular, the return valuer satisfies0.0 <= r < rhs.abs() inmost cases. However, due to a floating point round-off error it canresult inr == rhs.abs(), violating the mathematical definition, ifself is much smaller thanrhs.abs() in magnitude andself < 0.0.This result is not an element of the function’s codomain, but it is theclosest floating point number in the real numbers and thus fulfills thepropertyself == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)approximately.

§Precision

The result of this operation is guaranteed to be the roundedinfinite-precision result.

§Examples
leta: f32 =7.0;letb =4.0;assert_eq!(a.rem_euclid(b),3.0);assert_eq!((-a).rem_euclid(b),1.0);assert_eq!(a.rem_euclid(-b),3.0);assert_eq!((-a).rem_euclid(-b),1.0);// limitation due to round-off errorassert!((-f32::EPSILON).rem_euclid(3.0) !=0.0);
1.0.0 ·Source

pub fnpowi(self, n:i32) ->f32

Raises a number to an integer power.

Using this function is generally faster than usingpowf.It might have a different sequence of rounding operations thanpowf,so the results are not guaranteed to agree.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx =2.0_f32;letabs_difference = (x.powi(2) - (x * x)).abs();assert!(abs_difference <=1e-5);assert_eq!(f32::powi(f32::NAN,0),1.0);
1.0.0 ·Source

pub fnpowf(self, n:f32) ->f32

Raises a number to a floating point power.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx =2.0_f32;letabs_difference = (x.powf(2.0) - (x * x)).abs();assert!(abs_difference <=1e-5);assert_eq!(f32::powf(1.0, f32::NAN),1.0);assert_eq!(f32::powf(f32::NAN,0.0),1.0);
1.0.0 ·Source

pub fnsqrt(self) ->f32

Returns the square root of a number.

Returns NaN ifself is a negative number other than-0.0.

§Precision

The result of this operation is guaranteed to be the roundedinfinite-precision result. It is specified by IEEE 754 assquareRootand guaranteed not to change.

§Examples
letpositive =4.0_f32;letnegative = -4.0_f32;letnegative_zero = -0.0_f32;assert_eq!(positive.sqrt(),2.0);assert!(negative.sqrt().is_nan());assert!(negative_zero.sqrt() == negative_zero);
1.0.0 ·Source

pub fnexp(self) ->f32

Returnse^(self), (the exponential function).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letone =1.0f32;// e^1lete = one.exp();// ln(e) - 1 == 0letabs_difference = (e.ln() -1.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnexp2(self) ->f32

Returns2^(self).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letf =2.0f32;// 2^2 - 4 == 0letabs_difference = (f.exp2() -4.0).abs();assert!(abs_difference <=1e-5);
1.0.0 ·Source

pub fnln(self) ->f32

Returns the natural logarithm of the number.

This returns NaN when the number is negative, and negative infinity when number is zero.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letone =1.0f32;// e^1lete = one.exp();// ln(e) - 1 == 0letabs_difference = (e.ln() -1.0).abs();assert!(abs_difference <=1e-6);

Non-positive values:

assert_eq!(0_f32.ln(), f32::NEG_INFINITY);assert!((-42_f32).ln().is_nan());
1.0.0 ·Source

pub fnlog(self, base:f32) ->f32

Returns the logarithm of the number with respect to an arbitrary base.

This returns NaN when the number is negative, and negative infinity when number is zero.

The result might not be correctly rounded owing to implementation details;self.log2() can produce more accurate results for base 2, andself.log10() can produce more accurate results for base 10.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letfive =5.0f32;// log5(5) - 1 == 0letabs_difference = (five.log(5.0) -1.0).abs();assert!(abs_difference <=1e-6);

Non-positive values:

assert_eq!(0_f32.log(10.0), f32::NEG_INFINITY);assert!((-42_f32).log(10.0).is_nan());
1.0.0 ·Source

pub fnlog2(self) ->f32

Returns the base 2 logarithm of the number.

This returns NaN when the number is negative, and negative infinity when number is zero.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
lettwo =2.0f32;// log2(2) - 1 == 0letabs_difference = (two.log2() -1.0).abs();assert!(abs_difference <=1e-6);

Non-positive values:

assert_eq!(0_f32.log2(), f32::NEG_INFINITY);assert!((-42_f32).log2().is_nan());
1.0.0 ·Source

pub fnlog10(self) ->f32

Returns the base 10 logarithm of the number.

This returns NaN when the number is negative, and negative infinity when number is zero.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letten =10.0f32;// log10(10) - 1 == 0letabs_difference = (ten.log10() -1.0).abs();assert!(abs_difference <=1e-6);

Non-positive values:

assert_eq!(0_f32.log10(), f32::NEG_INFINITY);assert!((-42_f32).log10().is_nan());
1.0.0 ·Source

pub fnabs_sub(self, other:f32) ->f32

👎Deprecated since 1.10.0: you probably meant(self - other).abs(): this operation is(self - other).max(0.0) except thatabs_sub also propagates NaNs (also known asfdimf in C). If you truly need the positive difference, consider using that expression or the C functionfdimf, depending on how you wish to handle NaN (please consider filing an issue describing your use-case too).

The positive difference of two numbers.

  • Ifself <= other:0.0
  • Else:self - other
§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thefdimf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letx =3.0f32;lety = -3.0f32;letabs_difference_x = (x.abs_sub(1.0) -2.0).abs();letabs_difference_y = (y.abs_sub(1.0) -0.0).abs();assert!(abs_difference_x <=1e-6);assert!(abs_difference_y <=1e-6);
1.0.0 ·Source

pub fncbrt(self) ->f32

Returns the cube root of a number.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thecbrtf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letx =8.0f32;// x^(1/3) - 2 == 0letabs_difference = (x.cbrt() -2.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnhypot(self, other:f32) ->f32

Compute the distance between the origin and a point (x,y) on theEuclidean plane. Equivalently, compute the length of the hypotenuse of aright-angle triangle with other sides having lengthx.abs() andy.abs().

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thehypotf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letx =2.0f32;lety =3.0f32;// sqrt(x^2 + y^2)letabs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();assert!(abs_difference <=1e-5);
1.0.0 ·Source

pub fnsin(self) ->f32

Computes the sine of a number (in radians).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx = std::f32::consts::FRAC_PI_2;letabs_difference = (x.sin() -1.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fncos(self) ->f32

Computes the cosine of a number (in radians).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx =2.0* std::f32::consts::PI;letabs_difference = (x.cos() -1.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fntan(self) ->f32

Computes the tangent of a number (in radians).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thetanf from libc on Unix andWindows. Note that this might change in the future.

§Examples
letx = std::f32::consts::FRAC_PI_4;letabs_difference = (x.tan() -1.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnasin(self) ->f32

Computes the arcsine of a number. Return value is in radians inthe range [-pi/2, pi/2] or NaN if the number is outside the range[-1, 1].

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to theasinf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letf = std::f32::consts::FRAC_PI_4;// asin(sin(pi/2))letabs_difference = (f.sin().asin() - f).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnacos(self) ->f32

Computes the arccosine of a number. Return value is in radians inthe range [0, pi] or NaN if the number is outside the range[-1, 1].

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to theacosf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letf = std::f32::consts::FRAC_PI_4;// acos(cos(pi/4))letabs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnatan(self) ->f32

Computes the arctangent of a number. Return value is in radians in therange [-pi/2, pi/2];

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to theatanf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letf =1.0f32;// atan(tan(1))letabs_difference = (f.tan().atan() -1.0).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnatan2(self, other:f32) ->f32

Computes the four quadrant arctangent ofself (y) andother (x) in radians.

  • x = 0,y = 0:0
  • x >= 0:arctan(y/x) ->[-pi/2, pi/2]
  • y >= 0:arctan(y/x) + pi ->(pi/2, pi]
  • y < 0:arctan(y/x) - pi ->(-pi, -pi/2)
§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to theatan2f from libc on Unixand Windows. Note that this might change in the future.

§Examples
// Positive angles measured counter-clockwise// from positive x axis// -pi/4 radians (45 deg clockwise)letx1 =3.0f32;lety1 = -3.0f32;// 3pi/4 radians (135 deg counter-clockwise)letx2 = -3.0f32;lety2 =3.0f32;letabs_difference_1 = (y1.atan2(x1) - (-std::f32::consts::FRAC_PI_4)).abs();letabs_difference_2 = (y2.atan2(x2) - (3.0* std::f32::consts::FRAC_PI_4)).abs();assert!(abs_difference_1 <=1e-5);assert!(abs_difference_2 <=1e-5);
1.0.0 ·Source

pub fnsin_cos(self) -> (f32,f32)

Simultaneously computes the sine and cosine of the number,x. Returns(sin(x), cos(x)).

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to the(f32::sin(x), f32::cos(x)). Note that this might change in the future.

§Examples
letx = std::f32::consts::FRAC_PI_4;letf = x.sin_cos();letabs_difference_0 = (f.0- x.sin()).abs();letabs_difference_1 = (f.1- x.cos()).abs();assert!(abs_difference_0 <=1e-4);assert!(abs_difference_1 <=1e-4);
1.0.0 ·Source

pub fnexp_m1(self) ->f32

Returnse^(self) - 1 in a way that is accurate even if thenumber is close to zero.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to theexpm1f from libc on Unixand Windows. Note that this might change in the future.

§Examples
letx =1e-8_f32;// for very small x, e^x is approximately 1 + x + x^2 / 2letapprox = x + x * x /2.0;letabs_difference = (x.exp_m1() - approx).abs();assert!(abs_difference <1e-10);
1.0.0 ·Source

pub fnln_1p(self) ->f32

Returnsln(1+n) (natural logarithm) more accurately than ifthe operations were performed separately.

This returns NaN whenn < -1.0, and negative infinity whenn == -1.0.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thelog1pf from libc on Unixand Windows. Note that this might change in the future.

§Examples
letx =1e-8_f32;// for very small x, ln(1 + x) is approximately x - x^2 / 2letapprox = x - x * x /2.0;letabs_difference = (x.ln_1p() - approx).abs();assert!(abs_difference <1e-10);

Out-of-range values:

assert_eq!((-1.0_f32).ln_1p(), f32::NEG_INFINITY);assert!((-2.0_f32).ln_1p().is_nan());
1.0.0 ·Source

pub fnsinh(self) ->f32

Hyperbolic sine function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thesinhf from libc on Unixand Windows. Note that this might change in the future.

§Examples
lete = std::f32::consts::E;letx =1.0f32;letf = x.sinh();// Solving sinh() at 1 gives `(e^2-1)/(2e)`letg = ((e * e) -1.0) / (2.0* e);letabs_difference = (f - g).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fncosh(self) ->f32

Hyperbolic cosine function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thecoshf from libc on Unixand Windows. Note that this might change in the future.

§Examples
lete = std::f32::consts::E;letx =1.0f32;letf = x.cosh();// Solving cosh() at 1 gives this resultletg = ((e * e) +1.0) / (2.0* e);letabs_difference = (f - g).abs();// Same resultassert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fntanh(self) ->f32

Hyperbolic tangent function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thetanhf from libc on Unixand Windows. Note that this might change in the future.

§Examples
lete = std::f32::consts::E;letx =1.0f32;letf = x.tanh();// Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`letg = (1.0- e.powi(-2)) / (1.0+ e.powi(-2));letabs_difference = (f - g).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnasinh(self) ->f32

Inverse hyperbolic sine function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx =1.0f32;letf = x.sinh().asinh();letabs_difference = (f - x).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnacosh(self) ->f32

Inverse hyperbolic cosine function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx =1.0f32;letf = x.cosh().acosh();letabs_difference = (f - x).abs();assert!(abs_difference <=1e-6);
1.0.0 ·Source

pub fnatanh(self) ->f32

Inverse hyperbolic tangent function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.

§Examples
letx = std::f32::consts::FRAC_PI_6;letf = x.tanh().atanh();letabs_difference = (f - x).abs();assert!(abs_difference <=1e-5);
Source

pub fngamma(self) ->f32

🔬This is a nightly-only experimental API. (float_gamma #99842)

Gamma function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thetgammaf from libc on Unixand Windows. Note that this might change in the future.

§Examples
#![feature(float_gamma)]letx =5.0f32;letabs_difference = (x.gamma() -24.0).abs();assert!(abs_difference <=1e-5);
Source

pub fnln_gamma(self) -> (f32,i32)

🔬This is a nightly-only experimental API. (float_gamma #99842)

Natural logarithm of the absolute value of the gamma function

The integer part of the tuple indicates the sign of the gamma function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform, Rust version, andcan even differ within the same execution from one invocation to the next.This function currently corresponds to thelgamma_r from libc on Unixand Windows. Note that this might change in the future.

§Examples
#![feature(float_gamma)]letx =2.0f32;letabs_difference = (x.ln_gamma().0-0.0).abs();assert!(abs_difference <= f32::EPSILON);
Source

pub fnerf(self) ->f32

🔬This is a nightly-only experimental API. (float_erf #136321)

Error function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform,Rust version, and can even differ within the same execution from one invocation to the next.

This function currently corresponds to theerff from libc on Unixand Windows. Note that this might change in the future.

§Examples
#![feature(float_erf)]/// The error function relates what percent of a normal distribution lies/// within `x` standard deviations (scaled by `1/sqrt(2)`).fnwithin_standard_deviations(x: f32) -> f32 {    (x * std::f32::consts::FRAC_1_SQRT_2).erf() *100.0}// 68% of a normal distribution is within one standard deviationassert!((within_standard_deviations(1.0) -68.269).abs() <0.01);// 95% of a normal distribution is within two standard deviationsassert!((within_standard_deviations(2.0) -95.450).abs() <0.01);// 99.7% of a normal distribution is within three standard deviationsassert!((within_standard_deviations(3.0) -99.730).abs() <0.01);
Source

pub fnerfc(self) ->f32

🔬This is a nightly-only experimental API. (float_erf #136321)

Complementary error function.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform,Rust version, and can even differ within the same execution from one invocation to the next.

This function currently corresponds to theerfcf from libc on Unixand Windows. Note that this might change in the future.

§Examples
#![feature(float_erf)]letx: f32 =0.123;letone = x.erf() + x.erfc();letabs_difference = (one -1.0).abs();assert!(abs_difference <=1e-6);
Source§

implf32

1.43.0 ·Source

pub constRADIX:u32 = 2u32

The radix or base of the internal representation off32.

1.43.0 ·Source

pub constMANTISSA_DIGITS:u32 = 24u32

Number of significant digits in base 2.

Note that the size of the mantissa in the bitwise representation is onesmaller than this since the leading 1 is not stored explicitly.

1.43.0 ·Source

pub constDIGITS:u32 = 6u32

Approximate number of significant digits in base 10.

This is the maximumx such that any decimal number withxsignificant digits can be converted tof32 and back without loss.

Equal to floor(log10 2MANTISSA_DIGITS − 1).

1.43.0 ·Source

pub constEPSILON:f32 = 1.1920929E-7f32

Machine epsilon value forf32.

This is the difference between1.0 and the next larger representable number.

Equal to 21 − MANTISSA_DIGITS.

1.43.0 ·Source

pub constMIN:f32 = -3.40282347E+38f32

Smallest finitef32 value.

Equal to −MAX.

1.43.0 ·Source

pub constMIN_POSITIVE:f32 = 1.17549435E-38f32

Smallest positive normalf32 value.

Equal to 2MIN_EXP − 1.

1.43.0 ·Source

pub constMAX:f32 = 3.40282347E+38f32

Largest finitef32 value.

Equal to(1 − 2MANTISSA_DIGITS) 2MAX_EXP.

1.43.0 ·Source

pub constMIN_EXP:i32 = -125i32

One greater than the minimum possiblenormal power of 2 exponentfor a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).

This corresponds to the exact minimum possiblenormal power of 2 exponentfor a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).In other words, all normal numbers representable by this type aregreater than or equal to 0.5 × 2MIN_EXP.

1.43.0 ·Source

pub constMAX_EXP:i32 = 128i32

One greater than the maximum possible power of 2 exponentfor a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition).

This corresponds to the exact maximum possible power of 2 exponentfor a significand bounded by 0.5 ≤ x < 1 (i.e. the C definition).In other words, all numbers representable by this type arestrictly less than 2MAX_EXP.

1.43.0 ·Source

pub constMIN_10_EXP:i32 = -37i32

Minimumx for which 10x is normal.

Equal to ceil(log10 MIN_POSITIVE).

1.43.0 ·Source

pub constMAX_10_EXP:i32 = 38i32

Maximumx for which 10x is normal.

Equal to floor(log10 MAX).

1.43.0 ·Source

pub constNAN:f32 = NaN_f32

Not a Number (NaN).

Note that IEEE 754 doesn’t define just a single NaN value; a plethora of bit patterns areconsidered to be NaN. Furthermore, the standard makes a difference between a “signaling” anda “quiet” NaN, and allows inspecting its “payload” (the unspecified bits in the bit pattern)and its sign. See thespecification of NaN bit patterns for moreinfo.

This constant is guaranteed to be a quiet NaN (on targets that follow the Rust assumptionsthat the quiet/signaling bit being set to 1 indicates a quiet NaN). Beyond that, nothing isguaranteed about the specific bit pattern chosen here: both payload and sign are arbitrary.The concrete bit pattern may change across Rust versions and target platforms.

1.43.0 ·Source

pub constINFINITY:f32 = +Inf_f32

Infinity (∞).

1.43.0 ·Source

pub constNEG_INFINITY:f32 = -Inf_f32

Negative infinity (−∞).

1.0.0 (const: 1.83.0) ·Source

pub const fnis_nan(self) ->bool

Returnstrue if this value is NaN.

letnan = f32::NAN;letf =7.0_f32;assert!(nan.is_nan());assert!(!f.is_nan());
1.0.0 (const: 1.83.0) ·Source

pub const fnis_infinite(self) ->bool

Returnstrue if this value is positive infinity or negative infinity, andfalse otherwise.

letf =7.0f32;letinf = f32::INFINITY;letneg_inf = f32::NEG_INFINITY;letnan = f32::NAN;assert!(!f.is_infinite());assert!(!nan.is_infinite());assert!(inf.is_infinite());assert!(neg_inf.is_infinite());
1.0.0 (const: 1.83.0) ·Source

pub const fnis_finite(self) ->bool

Returnstrue if this number is neither infinite nor NaN.

letf =7.0f32;letinf = f32::INFINITY;letneg_inf = f32::NEG_INFINITY;letnan = f32::NAN;assert!(f.is_finite());assert!(!nan.is_finite());assert!(!inf.is_finite());assert!(!neg_inf.is_finite());
1.53.0 (const: 1.83.0) ·Source

pub const fnis_subnormal(self) ->bool

Returnstrue if the number issubnormal.

letmin = f32::MIN_POSITIVE;// 1.17549435e-38f32letmax = f32::MAX;letlower_than_min =1.0e-40_f32;letzero =0.0_f32;assert!(!min.is_subnormal());assert!(!max.is_subnormal());assert!(!zero.is_subnormal());assert!(!f32::NAN.is_subnormal());assert!(!f32::INFINITY.is_subnormal());// Values between `0` and `min` are Subnormal.assert!(lower_than_min.is_subnormal());
1.0.0 (const: 1.83.0) ·Source

pub const fnis_normal(self) ->bool

Returnstrue if the number is neither zero, infinite,subnormal, or NaN.

letmin = f32::MIN_POSITIVE;// 1.17549435e-38f32letmax = f32::MAX;letlower_than_min =1.0e-40_f32;letzero =0.0_f32;assert!(min.is_normal());assert!(max.is_normal());assert!(!zero.is_normal());assert!(!f32::NAN.is_normal());assert!(!f32::INFINITY.is_normal());// Values between `0` and `min` are Subnormal.assert!(!lower_than_min.is_normal());
1.0.0 (const: 1.83.0) ·Source

pub const fnclassify(self) ->FpCategory

Returns the floating point category of the number. If only one propertyis going to be tested, it is generally faster to use the specificpredicate instead.

usestd::num::FpCategory;letnum =12.4_f32;letinf = f32::INFINITY;assert_eq!(num.classify(), FpCategory::Normal);assert_eq!(inf.classify(), FpCategory::Infinite);
1.0.0 (const: 1.83.0) ·Source

pub const fnis_sign_positive(self) ->bool

Returnstrue ifself has a positive sign, including+0.0, NaNs withpositive sign bit and positive infinity.

Note that IEEE 754 doesn’t assign any meaning to the sign bit in case ofa NaN, and as Rust doesn’t guarantee that the bit pattern of NaNs areconserved over arithmetic operations, the result ofis_sign_positive ona NaN might produce an unexpected or non-portable result. See thespecificationof NaN bit patterns for more info. Useself.signum() == 1.0if you need fully portable behavior (will returnfalse for all NaNs).

letf =7.0_f32;letg = -7.0_f32;assert!(f.is_sign_positive());assert!(!g.is_sign_positive());
1.0.0 (const: 1.83.0) ·Source

pub const fnis_sign_negative(self) ->bool

Returnstrue ifself has a negative sign, including-0.0, NaNs withnegative sign bit and negative infinity.

Note that IEEE 754 doesn’t assign any meaning to the sign bit in case ofa NaN, and as Rust doesn’t guarantee that the bit pattern of NaNs areconserved over arithmetic operations, the result ofis_sign_negative ona NaN might produce an unexpected or non-portable result. See thespecificationof NaN bit patterns for more info. Useself.signum() == -1.0if you need fully portable behavior (will returnfalse for all NaNs).

letf =7.0f32;letg = -7.0f32;assert!(!f.is_sign_negative());assert!(g.is_sign_negative());
1.86.0 (const: 1.86.0) ·Source

pub const fnnext_up(self) ->f32

Returns the least number greater thanself.

LetTINY be the smallest representable positivef32. Then,

  • ifself.is_nan(), this returnsself;
  • ifself isNEG_INFINITY, this returnsMIN;
  • ifself is-TINY, this returns -0.0;
  • ifself is -0.0 or +0.0, this returnsTINY;
  • ifself isMAX orINFINITY, this returnsINFINITY;
  • otherwise the unique least value greater thanself is returned.

The identityx.next_up() == -(-x).next_down() holds for all non-NaNx. Whenxis finitex == x.next_up().next_down() also holds.

// f32::EPSILON is the difference between 1.0 and the next number up.assert_eq!(1.0f32.next_up(),1.0+ f32::EPSILON);// But not for most numbers.assert!(0.1f32.next_up() <0.1+ f32::EPSILON);assert_eq!(16777216f32.next_up(),16777218.0);

This operation corresponds to IEEE-754nextUp.

1.86.0 (const: 1.86.0) ·Source

pub const fnnext_down(self) ->f32

Returns the greatest number less thanself.

LetTINY be the smallest representable positivef32. Then,

  • ifself.is_nan(), this returnsself;
  • ifself isINFINITY, this returnsMAX;
  • ifself isTINY, this returns 0.0;
  • ifself is -0.0 or +0.0, this returns-TINY;
  • ifself isMIN orNEG_INFINITY, this returnsNEG_INFINITY;
  • otherwise the unique greatest value less thanself is returned.

The identityx.next_down() == -(-x).next_up() holds for all non-NaNx. Whenxis finitex == x.next_down().next_up() also holds.

letx =1.0f32;// Clamp value into range [0, 1).letclamped = x.clamp(0.0,1.0f32.next_down());assert!(clamped <1.0);assert_eq!(clamped.next_up(),1.0);

This operation corresponds to IEEE-754nextDown.

1.0.0 (const: 1.85.0) ·Source

pub const fnrecip(self) ->f32

Takes the reciprocal (inverse) of a number,1/x.

letx =2.0_f32;letabs_difference = (x.recip() - (1.0/ x)).abs();assert!(abs_difference <= f32::EPSILON);
1.7.0 (const: 1.85.0) ·Source

pub const fnto_degrees(self) ->f32

Converts radians to degrees.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform,Rust version, and can even differ within the same execution from one invocation to the next.

§Examples
letangle = std::f32::consts::PI;letabs_difference = (angle.to_degrees() -180.0).abs();assert!(abs_difference <= f32::EPSILON);
1.7.0 (const: 1.85.0) ·Source

pub const fnto_radians(self) ->f32

Converts degrees to radians.

§Unspecified precision

The precision of this function is non-deterministic. This means it varies by platform,Rust version, and can even differ within the same execution from one invocation to the next.

§Examples
letangle =180.0f32;letabs_difference = (angle.to_radians() - std::f32::consts::PI).abs();assert!(abs_difference <= f32::EPSILON);
1.0.0 (const: 1.85.0) ·Source

pub const fnmax(self, other:f32) ->f32

Returns the maximum of the two numbers, ignoring NaN.

If one of the arguments is NaN, then the other argument is returned.This follows the IEEE 754-2008 semantics for maxNum, except for handling of signaling NaNs;this function handles all NaNs the same way and avoids maxNum’s problems with associativity.This also matches the behavior of libm’s fmax. In particular, if the inputs compare equal(such as for the case of+0.0 and-0.0), either input may be returned non-deterministically.

letx =1.0f32;lety =2.0f32;assert_eq!(x.max(y), y);
1.0.0 (const: 1.85.0) ·Source

pub const fnmin(self, other:f32) ->f32

Returns the minimum of the two numbers, ignoring NaN.

If one of the arguments is NaN, then the other argument is returned.This follows the IEEE 754-2008 semantics for minNum, except for handling of signaling NaNs;this function handles all NaNs the same way and avoids minNum’s problems with associativity.This also matches the behavior of libm’s fmin. In particular, if the inputs compare equal(such as for the case of+0.0 and-0.0), either input may be returned non-deterministically.

letx =1.0f32;lety =2.0f32;assert_eq!(x.min(y), x);
Source

pub const fnmaximum(self, other:f32) ->f32

🔬This is a nightly-only experimental API. (float_minimum_maximum #91079)

Returns the maximum of the two numbers, propagating NaN.

This returns NaN wheneither argument is NaN, as opposed tof32::max which only returns NaN whenboth arguments are NaN.

#![feature(float_minimum_maximum)]letx =1.0f32;lety =2.0f32;assert_eq!(x.maximum(y), y);assert!(x.maximum(f32::NAN).is_nan());

If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greaterof the two numbers. For this operation, -0.0 is considered to be less than +0.0.Note that this follows the semantics specified in IEEE 754-2019.

Also note that “propagation” of NaNs here doesn’t necessarily mean that the bitpattern of a NaNoperand is conserved; see thespecification of NaN bit patterns for more info.

Source

pub const fnminimum(self, other:f32) ->f32

🔬This is a nightly-only experimental API. (float_minimum_maximum #91079)

Returns the minimum of the two numbers, propagating NaN.

This returns NaN wheneither argument is NaN, as opposed tof32::min which only returns NaN whenboth arguments are NaN.

#![feature(float_minimum_maximum)]letx =1.0f32;lety =2.0f32;assert_eq!(x.minimum(y), x);assert!(x.minimum(f32::NAN).is_nan());

If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesserof the two numbers. For this operation, -0.0 is considered to be less than +0.0.Note that this follows the semantics specified in IEEE 754-2019.

Also note that “propagation” of NaNs here doesn’t necessarily mean that the bitpattern of a NaNoperand is conserved; see thespecification of NaN bit patterns for more info.

1.85.0 (const: 1.85.0) ·Source

pub const fnmidpoint(self, other:f32) ->f32

Calculates the midpoint (average) betweenself andrhs.

This returns NaN wheneither argument is NaN or if a combination of+inf and -inf is provided as arguments.

§Examples
assert_eq!(1f32.midpoint(4.0),2.5);assert_eq!((-5.5f32).midpoint(8.0),1.25);
1.44.0 ·Source

pub unsafe fnto_int_unchecked<Int>(self) -> Int
wheref32:FloatToInt<Int>,

Rounds toward zero and converts to any primitive integer type,assuming that the value is finite and fits in that type.

letvalue =4.6_f32;letrounded =unsafe{ value.to_int_unchecked::<u16>() };assert_eq!(rounded,4);letvalue = -128.9_f32;letrounded =unsafe{ value.to_int_unchecked::<i8>() };assert_eq!(rounded, i8::MIN);
§Safety

The value must:

  • Not beNaN
  • Not be infinite
  • Be representable in the return typeInt, after truncating off its fractional part
1.20.0 (const: 1.83.0) ·Source

pub const fnto_bits(self) ->u32

Raw transmutation tou32.

This is currently identical totransmute::<f32, u32>(self) on all platforms.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

Note that this function is distinct fromas casting, which attempts topreserve thenumeric value, and not the bitwise value.

§Examples
assert_ne!((1f32).to_bits(),1f32asu32);// to_bits() is not casting!assert_eq!((12.5f32).to_bits(),0x41480000);
1.20.0 (const: 1.83.0) ·Source

pub const fnfrom_bits(v:u32) ->f32

Raw transmutation fromu32.

This is currently identical totransmute::<u32, f32>(v) on all platforms.It turns out this is incredibly portable, for two reasons:

  • Floats and Ints have the same endianness on all supported platforms.
  • IEEE 754 very precisely specifies the bit layout of floats.

However there is one caveat: prior to the 2008 version of IEEE 754, howto interpret the NaN signaling bit wasn’t actually specified. Most platforms(notably x86 and ARM) picked the interpretation that was ultimatelystandardized in 2008, but some didn’t (notably MIPS). As a result, allsignaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.

Rather than trying to preserve signaling-ness cross-platform, thisimplementation favors preserving the exact bits. This means thatany payloads encoded in NaNs will be preserved even if the result ofthis method is sent over the network from an x86 machine to a MIPS one.

If the results of this method are only manipulated by the samearchitecture that produced them, then there is no portability concern.

If the input isn’t NaN, then there is no portability concern.

If you don’t care about signalingness (very likely), then there is noportability concern.

Note that this function is distinct fromas casting, which attempts topreserve thenumeric value, and not the bitwise value.

§Examples
letv = f32::from_bits(0x41480000);assert_eq!(v,12.5);
1.40.0 (const: 1.83.0) ·Source

pub const fnto_be_bytes(self) -> [u8;4]

Returns the memory representation of this floating point number as a byte array inbig-endian (network) byte order.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letbytes =12.5f32.to_be_bytes();assert_eq!(bytes, [0x41,0x48,0x00,0x00]);
1.40.0 (const: 1.83.0) ·Source

pub const fnto_le_bytes(self) -> [u8;4]

Returns the memory representation of this floating point number as a byte array inlittle-endian byte order.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letbytes =12.5f32.to_le_bytes();assert_eq!(bytes, [0x00,0x00,0x48,0x41]);
1.40.0 (const: 1.83.0) ·Source

pub const fnto_ne_bytes(self) -> [u8;4]

Returns the memory representation of this floating point number as a byte array innative byte order.

As the target platform’s native endianness is used, portable codeshould useto_be_bytes orto_le_bytes, as appropriate, instead.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letbytes =12.5f32.to_ne_bytes();assert_eq!(    bytes,ifcfg!(target_endian ="big") {        [0x41,0x48,0x00,0x00]    }else{        [0x00,0x00,0x48,0x41]    });
1.40.0 (const: 1.83.0) ·Source

pub const fnfrom_be_bytes(bytes: [u8;4]) ->f32

Creates a floating point value from its representation as a byte array in big endian.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letvalue = f32::from_be_bytes([0x41,0x48,0x00,0x00]);assert_eq!(value,12.5);
1.40.0 (const: 1.83.0) ·Source

pub const fnfrom_le_bytes(bytes: [u8;4]) ->f32

Creates a floating point value from its representation as a byte array in little endian.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letvalue = f32::from_le_bytes([0x00,0x00,0x48,0x41]);assert_eq!(value,12.5);
1.40.0 (const: 1.83.0) ·Source

pub const fnfrom_ne_bytes(bytes: [u8;4]) ->f32

Creates a floating point value from its representation as a byte array in native endian.

As the target platform’s native endianness is used, portable codelikely wants to usefrom_be_bytes orfrom_le_bytes, asappropriate instead.

Seefrom_bits for some discussion of theportability of this operation (there are almost no issues).

§Examples
letvalue = f32::from_ne_bytes(ifcfg!(target_endian ="big") {    [0x41,0x48,0x00,0x00]}else{    [0x00,0x00,0x48,0x41]});assert_eq!(value,12.5);
1.62.0 ·Source

pub fntotal_cmp(&self, other: &f32) ->Ordering

Returns the ordering betweenself andother.

Unlike the standard partial comparison between floating point numbers,this comparison always produces an ordering in accordance tothetotalOrder predicate as defined in the IEEE 754 (2008 revision)floating point standard. The values are ordered in the following sequence:

  • negative quiet NaN
  • negative signaling NaN
  • negative infinity
  • negative numbers
  • negative subnormal numbers
  • negative zero
  • positive zero
  • positive subnormal numbers
  • positive numbers
  • positive infinity
  • positive signaling NaN
  • positive quiet NaN.

The ordering established by this function does not always agree with thePartialOrd andPartialEq implementations off32. For example,they consider negative and positive zero equal, whiletotal_cmpdoesn’t.

The interpretation of the signaling NaN bit follows the definition inthe IEEE 754 standard, which may not match the interpretation by some ofthe older, non-conformant (e.g. MIPS) hardware implementations.

§Example
structGoodBoy {    name: String,    weight: f32,}letmutbois =vec![    GoodBoy { name:"Pucci".to_owned(), weight:0.1},    GoodBoy { name:"Woofer".to_owned(), weight:99.0},    GoodBoy { name:"Yapper".to_owned(), weight:10.0},    GoodBoy { name:"Chonk".to_owned(), weight: f32::INFINITY },    GoodBoy { name:"Abs. Unit".to_owned(), weight: f32::NAN },    GoodBoy { name:"Floaty".to_owned(), weight: -5.0},];bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));// `f32::NAN` could be positive or negative, which will affect the sort order.iff32::NAN.is_sign_negative() {assert!(bois.into_iter().map(|b| b.weight)        .zip([f32::NAN, -5.0,0.1,10.0,99.0, f32::INFINITY].iter())        .all(|(a, b)| a.to_bits() == b.to_bits()))}else{assert!(bois.into_iter().map(|b| b.weight)        .zip([-5.0,0.1,10.0,99.0, f32::INFINITY, f32::NAN].iter())        .all(|(a, b)| a.to_bits() == b.to_bits()))}
1.50.0 (const: 1.85.0) ·Source

pub const fnclamp(self, min:f32, max:f32) ->f32

Restrict a value to a certain interval unless it is NaN.

Returnsmax ifself is greater thanmax, andmin ifself isless thanmin. Otherwise this returnsself.

Note that this function returns NaN if the initial value was NaN aswell.

§Panics

Panics ifmin > max,min is NaN, ormax is NaN.

§Examples
assert!((-3.0f32).clamp(-2.0,1.0) == -2.0);assert!((0.0f32).clamp(-2.0,1.0) ==0.0);assert!((2.0f32).clamp(-2.0,1.0) ==1.0);assert!((f32::NAN).clamp(-2.0,1.0).is_nan());
1.0.0 (const: 1.85.0) ·Source

pub const fnabs(self) ->f32

Computes the absolute value ofself.

This function always returns the precise result.

§Examples
letx =3.5_f32;lety = -3.5_f32;assert_eq!(x.abs(), x);assert_eq!(y.abs(), -y);assert!(f32::NAN.abs().is_nan());
1.0.0 (const: 1.85.0) ·Source

pub const fnsignum(self) ->f32

Returns a number that represents the sign ofself.

  • 1.0 if the number is positive,+0.0 orINFINITY
  • -1.0 if the number is negative,-0.0 orNEG_INFINITY
  • NaN if the number is NaN
§Examples
letf =3.5_f32;assert_eq!(f.signum(),1.0);assert_eq!(f32::NEG_INFINITY.signum(), -1.0);assert!(f32::NAN.signum().is_nan());
1.35.0 (const: 1.85.0) ·Source

pub const fncopysign(self, sign:f32) ->f32

Returns a number composed of the magnitude ofself and the sign ofsign.

Equal toself if the sign ofself andsign are the same, otherwise equal to-self.Ifself is a NaN, then a NaN with the same payload asself and the sign bit ofsign isreturned.

Ifsign is a NaN, then this operation will still carry over its sign into the result. Notethat IEEE 754 doesn’t assign any meaning to the sign bit in case of a NaN, and as Rustdoesn’t guarantee that the bit pattern of NaNs are conserved over arithmetic operations, theresult ofcopysign withsign being a NaN might produce an unexpected or non-portableresult. See thespecification of NaN bit patterns for moreinfo.

§Examples
letf =3.5_f32;assert_eq!(f.copysign(0.42),3.5_f32);assert_eq!(f.copysign(-0.42), -3.5_f32);assert_eq!((-f).copysign(0.42),3.5_f32);assert_eq!((-f).copysign(-0.42), -3.5_f32);assert!(f32::NAN.copysign(1.0).is_nan());
Source

pub const fnalgebraic_add(self, rhs:f32) ->f32

🔬This is a nightly-only experimental API. (float_algebraic #136469)

Float addition that allows optimizations based on algebraic rules.

Seealgebraic operators for more info.

Source

pub const fnalgebraic_sub(self, rhs:f32) ->f32

🔬This is a nightly-only experimental API. (float_algebraic #136469)

Float subtraction that allows optimizations based on algebraic rules.

Seealgebraic operators for more info.

Source

pub const fnalgebraic_mul(self, rhs:f32) ->f32

🔬This is a nightly-only experimental API. (float_algebraic #136469)

Float multiplication that allows optimizations based on algebraic rules.

Seealgebraic operators for more info.

Source

pub const fnalgebraic_div(self, rhs:f32) ->f32

🔬This is a nightly-only experimental API. (float_algebraic #136469)

Float division that allows optimizations based on algebraic rules.

Seealgebraic operators for more info.

Source

pub const fnalgebraic_rem(self, rhs:f32) ->f32

🔬This is a nightly-only experimental API. (float_algebraic #136469)

Float remainder that allows optimizations based on algebraic rules.

Seealgebraic operators for more info.

Trait Implementations§

1.0.0 (const:unstable) ·Source§

implAdd<&f32> for &f32

Source§

typeOutput = <f32 asAdd>::Output

The resulting type after applying the+ operator.
Source§

fnadd(self, other: &f32) -> <f32 asAdd>::Output

Performs the+ operation.Read more
1.0.0 (const:unstable) ·Source§

implAdd<&f32> forf32

Source§

typeOutput = <f32 asAdd>::Output

The resulting type after applying the+ operator.
Source§

fnadd(self, other: &f32) -> <f32 asAdd>::Output

Performs the+ operation.Read more
1.0.0 (const:unstable) ·Source§

implAdd<f32> for &f32

Source§

typeOutput = <f32 asAdd>::Output

The resulting type after applying the+ operator.
Source§

fnadd(self, other:f32) -> <f32 asAdd>::Output

Performs the+ operation.Read more
1.0.0 (const:unstable) ·Source§

implAdd forf32

Source§

typeOutput =f32

The resulting type after applying the+ operator.
Source§

fnadd(self, other:f32) ->f32

Performs the+ operation.Read more
1.22.0 (const:unstable) ·Source§

implAddAssign<&f32> forf32

Source§

fnadd_assign(&mut self, other: &f32)

Performs the+= operation.Read more
1.8.0 (const:unstable) ·Source§

implAddAssign forf32

Source§

fnadd_assign(&mut self, other:f32)

Performs the+= operation.Read more
1.0.0 ·Source§

implClone forf32

Source§

fnclone(&self) ->f32

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
1.0.0 ·Source§

implDebug forf32

Source§

fnfmt(&self, fmt: &mutFormatter<'_>) ->Result<(),Error>

Formats the value using the given formatter.Read more
1.0.0 (const:unstable) ·Source§

implDefault forf32

Source§

fndefault() ->f32

Returns the default value of0.0

1.0.0 ·Source§

implDisplay forf32

Source§

fnfmt(&self, fmt: &mutFormatter<'_>) ->Result<(),Error>

Formats the value using the given formatter.Read more
1.0.0 (const:unstable) ·Source§

implDiv<&f32> for &f32

Source§

typeOutput = <f32 asDiv>::Output

The resulting type after applying the/ operator.
Source§

fndiv(self, other: &f32) -> <f32 asDiv>::Output

Performs the/ operation.Read more
1.0.0 (const:unstable) ·Source§

implDiv<&f32> forf32

Source§

typeOutput = <f32 asDiv>::Output

The resulting type after applying the/ operator.
Source§

fndiv(self, other: &f32) -> <f32 asDiv>::Output

Performs the/ operation.Read more
1.0.0 (const:unstable) ·Source§

implDiv<f32> for &f32

Source§

typeOutput = <f32 asDiv>::Output

The resulting type after applying the/ operator.
Source§

fndiv(self, other:f32) -> <f32 asDiv>::Output

Performs the/ operation.Read more
1.0.0 (const:unstable) ·Source§

implDiv forf32

Source§

typeOutput =f32

The resulting type after applying the/ operator.
Source§

fndiv(self, other:f32) ->f32

Performs the/ operation.Read more
1.22.0 (const:unstable) ·Source§

implDivAssign<&f32> forf32

Source§

fndiv_assign(&mut self, other: &f32)

Performs the/= operation.Read more
1.8.0 (const:unstable) ·Source§

implDivAssign forf32

Source§

fndiv_assign(&mut self, other:f32)

Performs the/= operation.Read more
1.68.0 (const:unstable) ·Source§

implFrom<bool> forf32

Source§

fnfrom(small:bool) ->f32

Converts abool tof32 losslessly.The resulting value is positive0.0 forfalse and1.0 fortrue values.

§Examples
letx: f32 =false.into();assert_eq!(x,0.0);assert!(x.is_sign_positive());lety: f32 =true.into();assert_eq!(y,1.0);
1.6.0 (const:unstable) ·Source§

implFrom<f32> forf128

Source§

fnfrom(small:f32) ->f128

Convertsf32 tof128 losslessly.

1.6.0 (const:unstable) ·Source§

implFrom<f32> forf64

Source§

fnfrom(small:f32) ->f64

Convertsf32 tof64 losslessly.

1.6.0 (const:unstable) ·Source§

implFrom<i16> forf32

Source§

fnfrom(small:i16) ->f32

Convertsi16 tof32 losslessly.

1.6.0 (const:unstable) ·Source§

implFrom<i8> forf32

Source§

fnfrom(small:i8) ->f32

Convertsi8 tof32 losslessly.

1.6.0 (const:unstable) ·Source§

implFrom<u16> forf32

Source§

fnfrom(small:u16) ->f32

Convertsu16 tof32 losslessly.

1.6.0 (const:unstable) ·Source§

implFrom<u8> forf32

Source§

fnfrom(small:u8) ->f32

Convertsu8 tof32 losslessly.

1.0.0 ·Source§

implFromStr forf32

Source§

fnfrom_str(src: &str) ->Result<f32,ParseFloatError>

Converts a string in base 10 to a float.Accepts an optional decimal exponent.

This function accepts strings such as

  • ‘3.14’
  • ‘-3.14’
  • ‘2.5E10’, or equivalently, ‘2.5e10’
  • ‘2.5E-10’
  • ‘5.’
  • ‘.5’, or, equivalently, ‘0.5’
  • ‘7’
  • ‘007’
  • ‘inf’, ‘-inf’, ‘+infinity’, ‘NaN’

Note that alphabetical characters are not case-sensitive.

Leading and trailing whitespace represent an error.

§Grammar

All strings that adhere to the followingEBNF grammar whenlowercased will result in anOk being returned:

Float  ::= Sign? ( 'inf' | 'infinity' | 'nan' | Number )Number ::= ( Digit+ |             Digit+ '.' Digit* |             Digit* '.' Digit+ ) Exp?Exp    ::= 'e' Sign? Digit+Sign   ::= [+-]Digit  ::= [0-9]
§Arguments
  • src - A string
§Return value

Err(ParseFloatError) if the string did not represent a validnumber. Otherwise,Ok(n) wheren is the closestrepresentable floating-point number to the number representedbysrc (following the same rules for rounding as for theresults of primitive operations).

Source§

typeErr =ParseFloatError

The associated error which can be returned from parsing.
1.0.0 ·Source§

implLowerExp forf32

Source§

fnfmt(&self, fmt: &mutFormatter<'_>) ->Result<(),Error>

Formats the value using the given formatter.Read more
1.0.0 (const:unstable) ·Source§

implMul<&f32> for &f32

Source§

typeOutput = <f32 asMul>::Output

The resulting type after applying the* operator.
Source§

fnmul(self, other: &f32) -> <f32 asMul>::Output

Performs the* operation.Read more
1.0.0 (const:unstable) ·Source§

implMul<&f32> forf32

Source§

typeOutput = <f32 asMul>::Output

The resulting type after applying the* operator.
Source§

fnmul(self, other: &f32) -> <f32 asMul>::Output

Performs the* operation.Read more
1.0.0 (const:unstable) ·Source§

implMul<f32> for &f32

Source§

typeOutput = <f32 asMul>::Output

The resulting type after applying the* operator.
Source§

fnmul(self, other:f32) -> <f32 asMul>::Output

Performs the* operation.Read more
1.0.0 (const:unstable) ·Source§

implMul forf32

Source§

typeOutput =f32

The resulting type after applying the* operator.
Source§

fnmul(self, other:f32) ->f32

Performs the* operation.Read more
1.22.0 (const:unstable) ·Source§

implMulAssign<&f32> forf32

Source§

fnmul_assign(&mut self, other: &f32)

Performs the*= operation.Read more
1.8.0 (const:unstable) ·Source§

implMulAssign forf32

Source§

fnmul_assign(&mut self, other:f32)

Performs the*= operation.Read more
1.0.0 (const:unstable) ·Source§

implNeg for &f32

Source§

typeOutput = <f32 asNeg>::Output

The resulting type after applying the- operator.
Source§

fnneg(self) -> <f32 asNeg>::Output

Performs the unary- operation.Read more
1.0.0 (const:unstable) ·Source§

implNeg forf32

Source§

typeOutput =f32

The resulting type after applying the- operator.
Source§

fnneg(self) ->f32

Performs the unary- operation.Read more
1.0.0 (const:unstable) ·Source§

implPartialEq forf32

Source§

fneq(&self, other: &f32) ->bool

Tests forself andother values to be equal, and is used by==.
Source§

fnne(&self, other: &f32) ->bool

Tests for!=. The default implementation is almost always sufficient,and should not be overridden without very good reason.
1.0.0 (const:unstable) ·Source§

implPartialOrd forf32

Source§

fnpartial_cmp(&self, other: &f32) ->Option<Ordering>

This method returns an ordering betweenself andother values if one exists.Read more
Source§

fnlt(&self, other: &f32) ->bool

Tests less than (forself andother) and is used by the< operator.Read more
Source§

fnle(&self, other: &f32) ->bool

Tests less than or equal to (forself andother) and is used by the<= operator.Read more
Source§

fngt(&self, other: &f32) ->bool

Tests greater than (forself andother) and is used by the>operator.Read more
Source§

fnge(&self, other: &f32) ->bool

Tests greater than or equal to (forself andother) and is used bythe>= operator.Read more
1.12.0 ·Source§

impl<'a>Product<&'af32> forf32

Source§

fnproduct<I>(iter: I) ->f32
where I:Iterator<Item = &'af32>,

Takes an iterator and generatesSelf from the elements by multiplyingthe items.
1.12.0 ·Source§

implProduct forf32

Source§

fnproduct<I>(iter: I) ->f32
where I:Iterator<Item =f32>,

Takes an iterator and generatesSelf from the elements by multiplyingthe items.
1.0.0 (const:unstable) ·Source§

implRem<&f32> for &f32

Source§

typeOutput = <f32 asRem>::Output

The resulting type after applying the% operator.
Source§

fnrem(self, other: &f32) -> <f32 asRem>::Output

Performs the% operation.Read more
1.0.0 (const:unstable) ·Source§

implRem<&f32> forf32

Source§

typeOutput = <f32 asRem>::Output

The resulting type after applying the% operator.
Source§

fnrem(self, other: &f32) -> <f32 asRem>::Output

Performs the% operation.Read more
1.0.0 (const:unstable) ·Source§

implRem<f32> for &f32

Source§

typeOutput = <f32 asRem>::Output

The resulting type after applying the% operator.
Source§

fnrem(self, other:f32) -> <f32 asRem>::Output

Performs the% operation.Read more
1.0.0 (const:unstable) ·Source§

implRem forf32

The remainder from the division of two floats.

The remainder has the same sign as the dividend and is computed as:x - (x / y).trunc() * y.

§Examples

letx: f32 =50.50;lety: f32 =8.125;letremainder = x - (x / y).trunc() * y;// The answer to both operations is 1.75assert_eq!(x % y, remainder);
Source§

typeOutput =f32

The resulting type after applying the% operator.
Source§

fnrem(self, other:f32) ->f32

Performs the% operation.Read more
1.22.0 (const:unstable) ·Source§

implRemAssign<&f32> forf32

Source§

fnrem_assign(&mut self, other: &f32)

Performs the%= operation.Read more
1.8.0 (const:unstable) ·Source§

implRemAssign forf32

Source§

fnrem_assign(&mut self, other:f32)

Performs the%= operation.Read more
Source§

implSimdElement forf32

Source§

typeMask =i32

🔬This is a nightly-only experimental API. (portable_simd #86656)
The mask element type corresponding to this element type.
1.0.0 (const:unstable) ·Source§

implSub<&f32> for &f32

Source§

typeOutput = <f32 asSub>::Output

The resulting type after applying the- operator.
Source§

fnsub(self, other: &f32) -> <f32 asSub>::Output

Performs the- operation.Read more
1.0.0 (const:unstable) ·Source§

implSub<&f32> forf32

Source§

typeOutput = <f32 asSub>::Output

The resulting type after applying the- operator.
Source§

fnsub(self, other: &f32) -> <f32 asSub>::Output

Performs the- operation.Read more
1.0.0 (const:unstable) ·Source§

implSub<f32> for &f32

Source§

typeOutput = <f32 asSub>::Output

The resulting type after applying the- operator.
Source§

fnsub(self, other:f32) -> <f32 asSub>::Output

Performs the- operation.Read more
1.0.0 (const:unstable) ·Source§

implSub forf32

Source§

typeOutput =f32

The resulting type after applying the- operator.
Source§

fnsub(self, other:f32) ->f32

Performs the- operation.Read more
1.22.0 (const:unstable) ·Source§

implSubAssign<&f32> forf32

Source§

fnsub_assign(&mut self, other: &f32)

Performs the-= operation.Read more
1.8.0 (const:unstable) ·Source§

implSubAssign forf32

Source§

fnsub_assign(&mut self, other:f32)

Performs the-= operation.Read more
1.12.0 ·Source§

impl<'a>Sum<&'af32> forf32

Source§

fnsum<I>(iter: I) ->f32
where I:Iterator<Item = &'af32>,

Takes an iterator and generatesSelf from the elements by “summing up”the items.
1.12.0 ·Source§

implSum forf32

Source§

fnsum<I>(iter: I) ->f32
where I:Iterator<Item =f32>,

Takes an iterator and generatesSelf from the elements by “summing up”the items.
1.0.0 ·Source§

implUpperExp forf32

Source§

fnfmt(&self, fmt: &mutFormatter<'_>) ->Result<(),Error>

Formats the value using the given formatter.Read more
1.0.0 ·Source§

implCopy forf32

Source§

implFloatToInt<i128> forf32

Source§

implFloatToInt<i16> forf32

Source§

implFloatToInt<i32> forf32

Source§

implFloatToInt<i64> forf32

Source§

implFloatToInt<i8> forf32

Source§

implFloatToInt<isize> forf32

Source§

implFloatToInt<u128> forf32

Source§

implFloatToInt<u16> forf32

Source§

implFloatToInt<u32> forf32

Source§

implFloatToInt<u64> forf32

Source§

implFloatToInt<u8> forf32

Source§

implFloatToInt<usize> forf32

Source§

implSimdCast forf32

Source§

implUseCloned forf32

Auto Trait Implementations§

§

implFreeze forf32

§

implRefUnwindSafe forf32

§

implSend forf32

§

implSync forf32

§

implUnpin forf32

§

implUnwindSafe forf32

Blanket Implementations§

Source§

impl<T>Any for T
where T: 'static + ?Sized,

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

impl<T>Borrow<T> for T
where T: ?Sized,

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

impl<T>BorrowMut<T> for T
where T: ?Sized,

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U>Into<U> for T
where U:From<T>,

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

impl<T>ToOwned for T
where T:Clone,

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning.Read more
Source§

fnclone_into(&self, target:&mut T)

Uses borrowed data to replace owned data, usually by cloning.Read more
Source§

impl<T>ToString for T
where T:Display + ?Sized,

Source§

fnto_string(&self) ->String

Converts the given value to aString.Read more
Source§

impl<T, U>TryFrom<U> for T
where U:Into<T>,

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U>TryInto<U> for T
where U:TryFrom<T>,

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2025 Movatter.jp