-
Notifications
You must be signed in to change notification settings - Fork 23
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
Make FD÷FD return an FD. #40
Conversation
Before this, `FD{T,f} ÷ FD{T,f}` returned `T`, now it returns `FD{T,f}`. Same for `div`, `fld`, and `fld`.
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
==========================================
+ Coverage 98.82% 98.83% +<.01%
==========================================
Files 1 1
Lines 170 171 +1
==========================================
+ Hits 168 169 +1
Misses 2 2
Continue to review full report at Codecov.
|
There weren't any tests of `div` before, so this adds some simple ones.
Also, I noticed that there weren't any unit tests for |
One advantage of returning |
Since |
Yeah, this is a good point, @TotalVerb. By returning a julia> FixedPointDecimals.FixedDecimal{Int16, 4}(1) ÷ FixedPointDecimals.FixedDecimal{Int16, 4}(0.0005)
>> 2000
julia> FixedPointDecimals.FixedDecimal{Int16, 4}(2000)
ERROR: InexactError: trunc(Int16, 20000000) That said, I agree with
Actually, I don't think we do, although it would probably be worth adding a comment explaining why we don't.
|
Maybe the comment could be something like: # Note that div(x.i, y.i) eliminates the scaling coefficient, so we need to reconstruct the FD. |
Added a comment here to explain why we don't need the widening logic. Does this look okay?: FixedPointDecimals.jl/src/FixedPointDecimals.jl Lines 307 to 311 in becc3df
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests need a little work otherwise I'm happy to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take another look; should be good to merge now, i think! :)
fb8fd7a
to
1819dd6
Compare
Before this,
FD{T,f} ÷ FD{T,f}
returnedT
, now it returnsFD{T,f}
.Same for
div
,fld
, andfld
.Here's an example of the old behavior. Addition and division for two
FixedDecimals
returns aFixedDecimal
, but integer division (div
) was returning the raw storage typeT
instead of wrapping it in a FixedDecimal.