summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/foundations
diff options
context:
space:
mode:
author+merlan #flirora <flirora@flirora.xyz>2025-02-12 07:35:03 -0500
committerGitHub <noreply@github.com>2025-02-12 12:35:03 +0000
commit83ad407d3ccff4a8de1e7ffe198bfed874f5c0c7 (patch)
tree032d00e52d6e87480efe40bc69f8a54005813da7 /crates/typst-library/src/foundations
parenta0cd89b478437e53ece754a901ccfc035b4f2acf (diff)
Update documentation for `float.{to-bits, from-bits}` (#5836)
Diffstat (limited to 'crates/typst-library/src/foundations')
-rw-r--r--crates/typst-library/src/foundations/float.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/crates/typst-library/src/foundations/float.rs b/crates/typst-library/src/foundations/float.rs
index fcc46b03..21d0a8d8 100644
--- a/crates/typst-library/src/foundations/float.rs
+++ b/crates/typst-library/src/foundations/float.rs
@@ -110,7 +110,7 @@ impl f64 {
f64::signum(self)
}
- /// Converts bytes to a float.
+ /// Interprets bytes as a float.
///
/// ```example
/// #float.from-bytes(bytes((0, 0, 0, 0, 0, 0, 240, 63))) \
@@ -120,8 +120,10 @@ impl f64 {
pub fn from_bytes(
/// The bytes that should be converted to a float.
///
- /// Must be of length exactly 8 so that the result fits into a 64-bit
- /// float.
+ /// Must have a length of either 4 or 8. The bytes are then
+ /// interpreted in [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)'s
+ /// binary32 (single-precision) or binary64 (double-precision) format
+ /// depending on the length of the bytes.
bytes: Bytes,
/// The endianness of the conversion.
#[named]
@@ -158,6 +160,13 @@ impl f64 {
#[named]
#[default(Endianness::Little)]
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
+ /// [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754)'s binary32
+ /// (single-precision) or binary64 (double-precision) format
+ /// depending on the provided size.
#[named]
#[default(8)]
size: u32,