Skip to content

avoids integer overflow on left shift#106

Merged
timholy merged 2 commits intoJuliaMath:masterfrom
ssfrr:int32-fix
Feb 5, 2018
Merged

avoids integer overflow on left shift#106
timholy merged 2 commits intoJuliaMath:masterfrom
ssfrr:int32-fix

Conversation

@ssfrr
Copy link
Copy Markdown
Contributor

@ssfrr ssfrr commented Feb 4, 2018

in several places the conversion machinery uses 1<<f, which is a
problem for Fixed{Int64, 63}, and Fixed{Int32, 31} on 32-bit machines.

This changes those to one(widen1(T))<<f.

Fixes #104.

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 4, 2018

whoops, accidentally built this on an old master branch. ignore until I can check out the updates and rebase...

in several places the conversion machinery uses `1<<f`, which is a
problem for `Fixed{Int64, 63}`, and `Fixed{Int32, 31}` on 32-bit machines.

This changes those to `one(widen1(T))<<f`.

Fixes JuliaMath#104.
@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 4, 2018

ok, rebased on latest master

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #106 into master will decrease coverage by 2.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #106      +/-   ##
==========================================
- Coverage    91.7%   89.52%   -2.19%     
==========================================
  Files           4        4              
  Lines         193      191       -2     
==========================================
- Hits          177      171       -6     
- Misses         16       20       +4
Impacted Files Coverage Δ
src/fixed.jl 100% <100%> (ø) ⬆️
src/FixedPointNumbers.jl 84.28% <0%> (-6%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 861b036...249d114. Read the comment docs.

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 5, 2018

It looks like the test coverage reduction has something to do with whether the tests get run in 0.6 or 0.7, not the changes in this PR.

@timholy
Copy link
Copy Markdown
Member

timholy commented Feb 5, 2018

The code seems fine, but those tests you added pass on current master, which means they're not actually testing this fix.

These days I try to remember to write the tests first, and then fix the code, just so I can be sure I'm testing what I think I am.

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 5, 2018

The tests fail in master on 32-bit. You can test with the 32-bit Linux builds.

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 5, 2018

Though it does seem a little strange that the Fixed{Int64, 63} tests pass on 64-bit master now that I think about it. I would expect those to overflow as well...

@timholy
Copy link
Copy Markdown
Member

timholy commented Feb 5, 2018

Ah, of course, thanks for reminding me. On master I got this:

julia> typemax(Fixed{Int64, 63})
-1.0Q0f63

and with this PR

julia> typemax(Fixed{Int64, 63})
1.0Q0f63                                                                                                                                                                                                                                     

Perhaps add that to the test suite?

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 5, 2018

OK, fixed up the tests so they explicitly test for typemax, and also now use BigInt and BigFloat to make sure we're not running into precision issues with the numbers we're testing against (particularly with Fixed{Int64, 63}.

The new tests now fail on 64-bit master, as well.

@timholy timholy merged commit cf9ebc4 into JuliaMath:master Feb 5, 2018
@timholy
Copy link
Copy Markdown
Member

timholy commented Feb 5, 2018

Thanks so much!

@ssfrr
Copy link
Copy Markdown
Contributor Author

ssfrr commented Feb 5, 2018

no prob! FixedPointNumbers is one of my favorite Julia packages, glad I could help out.

I'm hoping this can get tagged relatively soon because it's blocking me merging a PR on one of my packages whose tests were failing on 32-bit. :)

@ssfrr ssfrr deleted the int32-fix branch February 5, 2018 22:11
@timholy
Copy link
Copy Markdown
Member

timholy commented Feb 5, 2018

0.4.6 has been submitted, thanks for the reminder.

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.

3 participants