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

Refactor names of BigFloat precision functions #13232

Merged

Conversation

dpsanders
Copy link
Contributor

This reduces the number of exported names from Base by 3 and makes them more flexible to be used with other types with different precisions.
Fixes #13225.

Changes:

  • get_bigfloat_precision() -> precision(BigFloat)
  • set_bigfloat_precision(prec) -> setprecision(BigFloat, prec) and setprecision(prec)
  • with_bigfloat_precision(f, prec) -> setprecision(f, BigFloat, prec) and setprecision(f, prec)

The idea of reusing setprecision instead of with_bigfloat_precision is due to @simonbyrne

Also, for consistency,

  • with_rounding(f, T, rounding_mode) -> setrounding(f, T, rounding_mode)
  • set_rounding(T, rounding_mode) -> setrounding(T, rounding_mode)
  • get_rounding(T) -> rounding(T)

@simonbyrne
Copy link
Contributor

I'm not really sold on setprecision!: to me, ! denotes that it mutates one of the arguments, whereas this function mutates a global variable. I have no strong feelings on underscores.

One other thing I've been thinking about is that withprecision functionality could be served by setprecision (in analogy to open).

@StefanKarpinski
Copy link
Sponsor Member

+1 to no underscores
-1 to ! at end of setprecision

@tkelman
Copy link
Contributor

tkelman commented Sep 20, 2015

mutating a global fits with the "not safe to do from multiple threads" interpretation of the ! convention

@ScottPJones
Copy link
Contributor

That's the first time I've heard of that multiple thread convention, is it documented somewhere?
Also, would it even hold here?
Should state like precision, rounding, etc. be thread specific, or across all threads in the process?
It also seems like neither @StefanKarpinski or @simonbyrne knew about that convention.

@simonbyrne
Copy link
Contributor

I think getrounding is more descriptive than rounding.

@ScottPJones
Copy link
Contributor

then, for consistency, should precision be deprecated and replaced by getprecision?

@simonbyrne
Copy link
Contributor

Yes, that too.

@dpsanders
Copy link
Contributor Author

I'm happy with getprecision and getrounding. I'll change this when I have a moment (not for a while, I fear).

@StefanKarpinski
Copy link
Sponsor Member

I really dislike prefixing these with get. Any function that returns a value "gets" that value. Should we prefix all functions that return anything besides nothing with "get"?

@tbreloff
Copy link

Agree with Stefan. I cringed when I just read getprecision and getrounding.

On Tue, Oct 13, 2015 at 2:32 PM, Stefan Karpinski [email protected]
wrote:

I really dislike prefixing these with get. Any function that returns a
value "gets" that value. Should we prefix all functions that return
anything besides nothing with "get"?


Reply to this email directly or view it on GitHub
#13232 (comment).

@dpsanders
Copy link
Contributor Author

I also prefer without the get in fact.
I don't think that rounding(BigFloat) can be construed as much else than the current rounding mode of the BigFloat type. And 3 + precision(x) reads easily as "3 plus the precision of x", whereas 3 + getprecision(x) is difficult to parse.

@ScottPJones
Copy link
Contributor

Then rounding and precision will be fine - but what's not good would be for them to be inconsistent.

set_rounding,
with_rounding,
setprecision,
setprecision,
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is a duplicate

@dpsanders
Copy link
Contributor Author

Thanks for the detailed review, @ScottPJones

@simonbyrne
Copy link
Contributor

Okay, I'm on board with rounding/precision. @dpsanders If you can fix the duplicate issues, then rebase, I would be happy to merge this.

@dpsanders
Copy link
Contributor Author

Sure, should be able to this weekend.

@dpsanders dpsanders force-pushed the dps/refactor_bigfloat_precision_names branch 5 times, most recently from 0d3e1b0 to 688deb4 Compare November 5, 2015 05:16
@dpsanders
Copy link
Contributor Author

After some git frustration, I have fixed @tkelman's comments (thanks!), squashed and rebased to current master.
I believe this is now ready to be merged.


.. Docstring generated from Julia source

Set the rounding mode of floating point type ``T``, controlling the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs one last run of genstdlib? Otherwise lgtm

@dpsanders
Copy link
Contributor Author

I'm trying to get the docs fixed, but after several rounds of to-ing and fro-ing, I get

ERROR: LoadError: duplicate setrounding(T, mode) .. function:: setrounding(T, mode)

even though I don't see where there's a duplicate.

Reduces the number of exported names from Base by 3 and makes them more flexible to me used with other types with different precisions.
@dpsanders dpsanders force-pushed the dps/refactor_bigfloat_precision_names branch from d633afa to bc54a76 Compare November 8, 2015 05:04
@dpsanders
Copy link
Contributor Author

I believe that this is now, finally, ready to be merged.

tkelman added a commit that referenced this pull request Nov 8, 2015
…ion_names

Refactor names of BigFloat precision functions
@tkelman tkelman merged commit 7077931 into JuliaLang:master Nov 8, 2015
@tkelman
Copy link
Contributor

tkelman commented Nov 8, 2015

Yep 👍 thanks for bearing with a few more rounds than usual.

@dpsanders
Copy link
Contributor Author

Thanks to all for the comments and help.

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.

None yet

6 participants