Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing docstring for round_with_overflow #115

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/FixedPointDecimals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
Loading