Skip to content

Conversation

kimikage
Copy link
Collaborator

This displays the fixed point type of the input in the message, not the rawtype. (cf. #190 (comment))

julia> checked_add(0.5N0f8, 0.5N0f8) # this PR
ERROR: OverflowError: 0.502N0f8 + 0.502N0f8 overflowed for type N0f8

Of course, more information could be added to the error message, but I think the error message in the constructor is sufficient to supplement it.

julia> 1.004N0f8
ERROR: ArgumentError: N0f8 is an 8-bit type representing 256 values from 0.0 to 1.0; cannot represent 1.004

This also avoids the stall with checked_{add/sub} on Windows. (cf. #190 (comment)) TBH, this is the real purpose of this PR. 😅

julia> @btime checked_add.($x, $y);
  898.900 μs (2 allocations: 976.70 KiB) # before (on Windows)
  577.699 μs (2 allocations: 976.70 KiB) # after (on Windows)
  678.800 μs (2 allocations: 976.70 KiB) # before (on Linux)
  679.500 μs (2 allocations: 976.70 KiB) # after (on Linux)

This displays the fixed point type of the input in the message, not the rawtype.
This also avoids the stall with `checked_{add/sub}` on Windows.
@test all(x -> saturating_neg(x) == clamp(fneg(x), F), xs)
@test all(x -> !(typemin(F) < fneg(x) < typemax(F)) ||
@test all(x -> saturating_neg(x) === clamp(fneg(x), F), xs)
@test all(x -> !(typemin(F) <= fneg(x) <= typemax(F)) ||
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had excluded typemin and typemax with the intention of writing generic code for 100% testing. They have a risk of causing inconsistencies due to the rounding errors in floating point operations.
However, I decided against supporting non-8-bit types in 100% tests for multiplication. So we can safely include typemin and typemax for 8-bit types.

@codecov
Copy link

codecov bot commented Aug 15, 2020

Codecov Report

Merging #214 into master will increase coverage by 0.23%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #214      +/-   ##
==========================================
+ Coverage   88.24%   88.48%   +0.23%     
==========================================
  Files           6        6              
  Lines         485      495      +10     
==========================================
+ Hits          428      438      +10     
  Misses         57       57              
Impacted Files Coverage Δ
src/FixedPointNumbers.jl 85.14% <100.00%> (+0.90%) ⬆️

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 b7e2ae1...369cba5. Read the comment docs.

@kimikage kimikage merged commit fab4079 into JuliaMath:master Aug 15, 2020
@kimikage kimikage deleted the overflow_message branch August 15, 2020 15:21
@kimikage kimikage mentioned this pull request Apr 30, 2024
38 tasks
kimikage added a commit to kimikage/FixedPointNumbers.jl that referenced this pull request May 1, 2024
This displays the fixed point type of the input in the message, not the rawtype.
kimikage added a commit to kimikage/FixedPointNumbers.jl that referenced this pull request May 1, 2024
This displays the fixed point type of the input in the message, not the rawtype.
kimikage added a commit to kimikage/FixedPointNumbers.jl that referenced this pull request May 1, 2024
This displays the fixed point type of the input in the message, not the rawtype.
kimikage added a commit to kimikage/FixedPointNumbers.jl that referenced this pull request May 1, 2024
This displays the fixed point type of the input in the message, not the rawtype.
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.

1 participant