Skip to content

Commit

Permalink
Merge pull request #76 from milankl/mk/precompile
Browse files Browse the repository at this point in the history
BFloat16s v0.5 compat
  • Loading branch information
milankl authored Jan 17, 2024
2 parents 6667c23 + 779d10f commit 55a74db
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StochasticRounding"
uuid = "3843c9a1-1f18-49ff-9d99-1b4c8a8e97ed"
authors = ["Milan Kloewer and StochasticRounding.jl contributors"]
version = "0.8.1"
version = "0.8.2"

[deps]
BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
Expand All @@ -10,7 +10,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RandomNumbers = "e6cf234a-135c-5ec9-84dd-332b85af5143"

[compat]
BFloat16s = "0.1, 0.2, 0.3, 0.4"
BFloat16s = "0.1, 0.2, 0.3, 0.4, 0.5"
DoubleFloats = "1"
Random = "1"
RandomNumbers = "^1.4"
Expand Down
57 changes: 1 addition & 56 deletions src/bfloat16.jl
Original file line number Diff line number Diff line change
@@ -1,57 +1,2 @@
# from BFloat16s.jl#main (22/12/23) to be removed with next release of BFloat16s.jl
function Base.nextfloat(f::BFloat16, d::Integer)

F = typeof(f)
fumax = reinterpret(Base.uinttype(F), F(Inf))
U = typeof(fumax)

isnan(f) && return f
fi = reinterpret(Int16, f)
fneg = fi < 0
fu = unsigned(fi & typemax(fi))

dneg = d < 0
da = Base.uabs(d)
if da > typemax(U)
fneg = dneg
fu = fumax
else
du = da % U
if fneg dneg
if du > fu
fu = min(fumax, du - fu)
fneg = !fneg
else
fu = fu - du
end
else
if fumax - fu < du
fu = fumax
else
fu = fu + du
end
end
end
if fneg
fu |= Base.sign_mask(F)
end
reinterpret(F, fu)
end

function Base.decompose(x::BFloat16)::NTuple{3,Int}
isnan(x) && return 0, 0, 0
isinf(x) && return ifelse(x < 0, -1, 1), 0, 0
n = reinterpret(UInt16, x)
s = (n & 0x007f) % Int16
e = ((n & 0x7f80) >> 7) % Int
s |= Int16(e != 0) << 7
d = ifelse(signbit(x), -1, 1)
s, e - 134 + (e == 0), d
end

BFloat16s.BFloat16(x::BigFloat) = BFloat16(Float32(x))
Base.BigFloat(x::BFloat16) = BigFloat(Float32(x))

Base.maxintfloat(::Type{BFloat16}) = reinterpret(BFloat16,0x4380)

Base.round(x::BFloat16, r::RoundingMode{:ToZero}) = BFloat16(trunc(Float32(x)))
Base.BigFloat(x::BFloat16) = BigFloat(Float32(x))

2 comments on commit 55a74db

@milankl
Copy link
Owner Author

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/99044

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.8.2 -m "<description of version>" 55a74db797d2d58c44224b9d5ceb7eec97663f73
git push origin v0.8.2

Please sign in to comment.