Improve documentation for float and int types (#4725)

This commit is contained in:
Malo 2024-08-12 10:12:06 +02:00 committed by GitHub
parent 54a1a7492f
commit 324c937dcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 20 deletions

View File

@ -27,10 +27,12 @@ impl f64 {
/// Converts a value to a float. /// Converts a value to a float.
/// ///
/// - Booleans are converted to `0.0` or `1.0`. /// - Booleans are converted to `0.0` or `1.0`.
/// - Integers are converted to the closest 64-bit float. /// - Integers are converted to the closest 64-bit float. For integers with
/// absolute value less than `{calc.pow(2, 53)}`, this conversion is
/// exact.
/// - Ratios are divided by 100%. /// - Ratios are divided by 100%.
/// - Strings are parsed in base 10 to the closest 64-bit float. /// - Strings are parsed in base 10 to the closest 64-bit float. Exponential
/// Exponential notation is supported. /// notation is supported.
/// ///
/// ```example /// ```example
/// #float(false) \ /// #float(false) \
@ -65,8 +67,8 @@ impl f64 {
/// Checks if a float is infinite. /// Checks if a float is infinite.
/// ///
/// For floats, there is positive and negative infinity. This function /// Floats can represent positive infinity and negative infinity. This
/// returns `true` if the float is either positive or negative infinity. /// function returns `{true}` if the float is an infinity.
/// ///
/// ```example /// ```example
/// #float.is-infinite(0) \ /// #float.is-infinite(0) \
@ -82,13 +84,13 @@ impl f64 {
/// ///
/// - If the number is positive (including `{+0.0}`), returns `{1.0}`. /// - If the number is positive (including `{+0.0}`), returns `{1.0}`.
/// - If the number is negative (including `{-0.0}`), returns `{-1.0}`. /// - If the number is negative (including `{-0.0}`), returns `{-1.0}`.
/// - If the number is [`{calc.nan}`]($calc.nan), returns /// - If the number is `{calc.nan}`, returns `{calc.nan}`.
/// [`{calc.nan}`]($calc.nan).
/// ///
/// ```example /// ```example
/// #(5.0).signum() \ /// #(5.0).signum() \
/// #(-5.0).signum() \ /// #(-5.0).signum() \
/// #(0.0).signum() \ /// #(0.0).signum() \
/// #calc.nan.signum()
/// ``` /// ```
#[func] #[func]
pub fn signum(self) -> f64 { pub fn signum(self) -> f64 {

View File

@ -62,7 +62,7 @@ impl i64 {
/// ```example /// ```example
/// #(5).signum() \ /// #(5).signum() \
/// #(-5).signum() \ /// #(-5).signum() \
/// #(0).signum() \ /// #(0).signum()
/// ``` /// ```
#[func] #[func]
pub fn signum(self) -> i64 { pub fn signum(self) -> i64 {
@ -75,7 +75,7 @@ impl i64 {
/// integer of 64 bits. /// integer of 64 bits.
/// ///
/// ```example /// ```example
/// #4.bit-not() /// #4.bit-not() \
/// #(-1).bit-not() /// #(-1).bit-not()
/// ``` /// ```
#[func(title = "Bitwise NOT")] #[func(title = "Bitwise NOT")]
@ -141,7 +141,7 @@ impl i64 {
/// fit in a 64-bit integer. /// fit in a 64-bit integer.
/// ///
/// ```example /// ```example
/// #33.bit-lshift(2) /// #33.bit-lshift(2) \
/// #(-1).bit-lshift(3) /// #(-1).bit-lshift(3)
/// ``` /// ```
#[func(title = "Bitwise Left Shift")] #[func(title = "Bitwise Left Shift")]
@ -162,8 +162,8 @@ impl i64 {
/// integer of 64 bits. /// integer of 64 bits.
/// ///
/// ```example /// ```example
/// #64.bit-rshift(2) /// #64.bit-rshift(2) \
/// #(-8).bit-rshift(2) /// #(-8).bit-rshift(2) \
/// #(-8).bit-rshift(2, logical: true) /// #(-8).bit-rshift(2, logical: true)
/// ``` /// ```
#[func(title = "Bitwise Right Shift")] #[func(title = "Bitwise Right Shift")]
@ -172,17 +172,17 @@ impl i64 {
/// The amount of bits to shift. Must not be negative. /// The amount of bits to shift. Must not be negative.
/// ///
/// Shifts larger than 63 are allowed and will cause the return value to /// Shifts larger than 63 are allowed and will cause the return value to
/// saturate. For non-negative numbers, the return value saturates at `0`, /// saturate. For non-negative numbers, the return value saturates at
/// while, for negative numbers, it saturates at `-1` if `logical` is set /// `{0}`, while, for negative numbers, it saturates at `{-1}` if
/// to `false`, or `0` if it is `true`. This behavior is consistent with /// `logical` is set to `{false}`, or `{0}` if it is `{true}`. This
/// just applying this operation multiple times. Therefore, the shift will /// behavior is consistent with just applying this operation multiple
/// always succeed. /// times. Therefore, the shift will always succeed.
shift: u32, shift: u32,
/// Toggles whether a logical (unsigned) right shift should be performed /// Toggles whether a logical (unsigned) right shift should be performed
/// instead of arithmetic right shift. /// instead of arithmetic right shift.
/// If this is `true`, negative operands will not preserve their sign bit, /// If this is `{true}`, negative operands will not preserve their sign
/// and bits which appear to the left after the shift will be `0`. /// bit, and bits which appear to the left after the shift will be
/// This parameter has no effect on non-negative operands. /// `{0}`. This parameter has no effect on non-negative operands.
#[named] #[named]
#[default(false)] #[default(false)]
logical: bool, logical: bool,