mirror of
https://github.com/typst/typst
synced 2025-08-11 21:57:55 +08:00
Update documentation for float.{to-bits, from-bits}
This commit is contained in:
parent
e4f8e57c53
commit
a00aea82c5
@ -110,7 +110,8 @@ impl f64 {
|
|||||||
f64::signum(self)
|
f64::signum(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts bytes to a float.
|
/// Interprets bytes as a float in [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)
|
||||||
|
/// format.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #float.from-bytes(bytes((0, 0, 0, 0, 0, 0, 240, 63))) \
|
/// #float.from-bytes(bytes((0, 0, 0, 0, 0, 0, 240, 63))) \
|
||||||
@ -120,8 +121,10 @@ impl f64 {
|
|||||||
pub fn from_bytes(
|
pub fn from_bytes(
|
||||||
/// The bytes that should be converted to a float.
|
/// The bytes that should be converted to a float.
|
||||||
///
|
///
|
||||||
/// Must be of length exactly 8 so that the result fits into a 64-bit
|
/// Must have a length of either 4 or 8. The bytes are then
|
||||||
/// float.
|
/// interpreted in the binary32 (single-precision) or
|
||||||
|
/// binary64 (double-precision) format depending on the
|
||||||
|
/// length of the bytes.
|
||||||
bytes: Bytes,
|
bytes: Bytes,
|
||||||
/// The endianness of the conversion.
|
/// The endianness of the conversion.
|
||||||
#[named]
|
#[named]
|
||||||
@ -145,7 +148,8 @@ impl f64 {
|
|||||||
bail!("bytes must have a length of 4 or 8");
|
bail!("bytes must have a length of 4 or 8");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a float to bytes.
|
/// Converts a float to bytes in [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)
|
||||||
|
/// format.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #array(1.0.to-bytes(endian: "big")) \
|
/// #array(1.0.to-bytes(endian: "big")) \
|
||||||
@ -158,6 +162,12 @@ impl f64 {
|
|||||||
#[named]
|
#[named]
|
||||||
#[default(Endianness::Little)]
|
#[default(Endianness::Little)]
|
||||||
endian: Endianness,
|
endian: Endianness,
|
||||||
|
/// The size of the resulting bytes.
|
||||||
|
///
|
||||||
|
/// This must be either 4 or 8. The call will return the
|
||||||
|
/// representation of this float in either the binary32
|
||||||
|
/// (single-precision) or binary64 (double-precision) format
|
||||||
|
/// depending on the provided size.
|
||||||
#[named]
|
#[named]
|
||||||
#[default(8)]
|
#[default(8)]
|
||||||
size: u32,
|
size: u32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user