Skip to content

Commit

Permalink
Merge pull request #37 from milankl/mk/keepbitsmax
Browse files Browse the repository at this point in the history
No rounding for max keepbits
  • Loading branch information
milankl authored Apr 7, 2022
2 parents 3ce48e5 + 8555fa3 commit 5f3ebbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BitInformation"
uuid = "de688a37-743e-4ac2-a6f0-bd62414d1aa7"
authors = ["Milan <milankloewer@gmx.de> and contributors"]
version = "0.5.0"
version = "0.5.1"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
8 changes: 6 additions & 2 deletions src/round_nearest.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Shift integer to push the mantissa in the right position. Used to determine
round up or down in the tie case. `keepbits` is the number of mantissa bits to
be kept (i.e. not zero-ed) after rounding."""
be kept (i.e. not zero-ed) after rounding. Special case: shift is -1 for
keepbits == significand_bits(T) to avoid a round away from 0 where no rounding
should be applied."""
function get_shift(::Type{T},keepbits::Integer) where {T<:Base.IEEEFloat}
return Base.significand_bits(T) - keepbits
shift = Base.significand_bits(T) - keepbits # normal case
shift -= keepbits == Base.significand_bits(T) # to avoid round away from 0
return shift
end

"""Returns for a Float-type `T` and `keepbits`, the number of mantissa bits to be
Expand Down
2 changes: 1 addition & 1 deletion test/round_nearest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end

@testset "No rounding for keepbits=10,23,52" begin
for (T,k) in zip([Float16,Float32,Float64],
[11,24,53])
[10,23,52])
A = rand(T,200,300)
Ar = round(A,k)
@test A == Ar
Expand Down

2 comments on commit 5f3ebbd

@milankl
Copy link
Owner Author

@milankl milankl commented on 5f3ebbd Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/58104

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" 5f3ebbd135e427c68048988fdc24f6f2d5cb71e9
git push origin v0.5.1

Please sign in to comment.