From 72a7e404ba59c3aabbf7f33ce182ccf9f0692f56 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 19 Feb 2025 16:58:23 -0700 Subject: [PATCH] Add missing docstring for round_with_overflow --- src/FixedPointDecimals.jl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/FixedPointDecimals.jl b/src/FixedPointDecimals.jl index 912093b..25c432e 100644 --- a/src/FixedPointDecimals.jl +++ b/src/FixedPointDecimals.jl @@ -523,10 +523,10 @@ function rdiv_with_overflow(x::FD{T, f}, y::Integer) where {T<:Integer, f} end # Does not exist in Base.Checked, so just exists in this package. -@doc """ +""" FixedPointDecimals.ceil_with_overflow(x::FD)::Tuple{FD,Bool} -Calculates the nearest integral value of the same type as x that is greater than or equal +Calculate the nearest integral value of the same type as x that is greater than or equal to x, returning it and a boolean indicating whether overflow has occurred. The overflow protection may impose a perceptible performance penalty. @@ -546,10 +546,10 @@ function ceil_with_overflow(x::FD{T,f}) where {T<:Integer,f} end # Does not exist in Base.Checked, so just exists in this package. -@doc """ +""" FixedPointDecimals.floor_with_overflow(x::FD)::Tuple{FD,Bool} -Calculates the nearest integral value of the same type as x that is less than or equal +Calculate the nearest integral value of the same type as x that is less than or equal to x, returning it and a boolean indicating whether overflow has occurred. The overflow protection may impose a perceptible performance penalty. @@ -564,6 +564,16 @@ function floor_with_overflow(x::FD{T, f}) where {T, f} return (reinterpret(FD{T, f}, backing), overflowed) end +# Does not exist in Base.Checked, so just exists in this package. +""" + FixedPointDecimals.round_with_overflow(x::FD, mode=RoundNearest)::Tuple{FD,Bool} + +Calculate the nearest integral value of the same type as x, breaking ties using the +specified RoundingModes, returning it and a boolean indicating whether overflow has +occurred. + +The overflow protection may impose a perceptible performance penalty. +""" round_with_overflow(fd::FD, ::RoundingMode{:Up}) = ceil_with_overflow(fd) round_with_overflow(fd::FD, ::RoundingMode{:Down}) = floor_with_overflow(fd) # trunc cannot overflow.