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 maxintfloat(::Type{BFloat16}) #60

Merged
merged 2 commits into from
Nov 7, 2023
Merged

add maxintfloat(::Type{BFloat16}) #60

merged 2 commits into from
Nov 7, 2023

Conversation

milankl
Copy link
Member

@milankl milankl commented Nov 7, 2023

maxintfloat(T) is the largest integer n so that n+1 is not representable anymore with a given format T. For BFloat16 this is $256 = 2^{n_m+1}$ with $n_m = 7$ the number of mantissa bits.

julia> BFloat16(256)
BFloat16(256.0)

julia> BFloat16(257)
BFloat16(256.0)

julia> BFloat16(258)
BFloat16(258.0)

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1278fa9) 66.66% compared to head (e9117ea) 66.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   66.66%   66.85%   +0.18%     
==========================================
  Files           3        3              
  Lines         180      181       +1     
==========================================
+ Hits          120      121       +1     
  Misses         60       60              
Files Coverage Δ
src/bfloat16.jl 71.85% <100.00%> (+0.16%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JeffreySarnoff JeffreySarnoff left a comment

Choose a reason for hiding this comment

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

lgtm

julia> function maxint(T, maxint=2^(1+precision(T)))
ints = 1:maxint
findfirst(iszero, ints .== Int.(BFloat16.(ints))) - 1
end;

julia> maxint(BFloat16)
256

@milankl milankl merged commit 18e21d6 into master Nov 7, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants