-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add BitsFloat abstract type, leverage dispatch for rounding modes
- Loading branch information
1 parent
43d9445
commit e77e7eb
Showing
9 changed files
with
48 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e77e7eb
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.
This is a very nice API.
e77e7eb
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.
So why is it deprecated to call
with_rounding
without a type? That should set the rounding modes for all floating-point types. Of course it should fail when the rounding mode isn't supported by all types – i.e.RoundFromZero
– but for rounding modes that are universally supported (the rest of them), it should just work.e77e7eb
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.
That's a fair point, but the reason for the deprecation is probably that "all floating-point types" is not well-defined. New types can add methods to
with_rounding
, but it seems we'd need some other mechanism to extend the behavior ofwith_rounding
without a type.e77e7eb
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.
This would require floating-point types registering themselves to support rounding mode changes. This is unavoidable with an API like this that involves global state.
e77e7eb
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.
Yep, that's exactly the reason why I deprecated it, as I couldn't figure out a neat way to do hooks (I haven't come across them anywhere else in Base). In the end, I couldn't really think of a good use case for when you would want to change both modes, since you can always call
set_rounding(typeof(x),RoundDown)
, or exploit parametric types at dispatch. Also it forces people to think about the types they're using, which is probably a good thing if you're mucking about with rounding modes.e77e7eb
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.
I can think of a situation: when I'm demoing stuff ;-). But seriously, I feel like this really undermines the genericness of this feature. The idea is that I can switch this and know that all the intervening computations have the rounding mode I just set, regardless of type. That is exactly what you need for the best use case for this, which is Kahan's approach to testing numerical stability: run your program in each rounding mode and see if you get similar results. If you have to go around and nitpick with the rounding mode of each type, then this isn't very helpful.