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

make use of scientific notation for BigFloat consistent with other types #29211

Merged
merged 1 commit into from Dec 3, 2018

Conversation

3 participants
@rfourquet
Copy link
Contributor

commented Sep 16, 2018

This switches to non-scientific notation when the scientific exponent
would be in -4:5, as is the case for e.g. Float64.
For example, string(big(42.0)) is now "42.0".

This is a change I've wanted for quite a while, I don't know if I'm in the minority here. I didn't find a discussion on this topic (except for removing a useless "e+00"), so I'm not sure whether the current printing is just inherited from the choices made in MPFR, or if this was a conscious decision.
I mostly use BigFloat in a range where I find the scientific notation as an obstacle to my human parsing, e.g.

julia> big"42.0"                                                                                                         
4.2e+01

julia> rand(BigFloat, 2, 2)
2×2 Array{BigFloat,2}:
 5.59682e-01  9.24952e-01
 4.77888e-01  4.98624e-02

julia> 2 * rand(BigFloat, 3)
3-element Array{BigFloat,1}:
 1.119363387037806864843608696550048745013519509937459521981246563117370317221463
 1.557756144279027196473368290932951926003919517867431965355848779211876826219583e-01
 1.849904313908958285396788230625007253199545024377884487188520977470270959385811

In particular in the last example, it's easy for me to forget to look at the end to check if there is an exponent.
With this PR, this is turned into

julia> big"42.0"                                                                                                         
42.0

julia> rand(BigFloat, 2, 2)
2×2 Array{BigFloat,2}:
 0.559682  0.924952
 0.477888  0.0498624

julia> 2 * rand(BigFloat, 3)
3-element Array{BigFloat,1}:
 1.119363387037806864843608696550048745013519509937459521981246563117370317221463
 0.1557756144279027196473368290932951926003919517867431965355848779211876826219583
 1.849904313908958285396788230625007253199545024377884487188520977470270959385811

@rfourquet rfourquet force-pushed the rf/bigfloat-print branch 2 times, most recently from f3e0127 to 5543ac0 Sep 16, 2018

@StefanKarpinski StefanKarpinski added this to the 1.1 milestone Sep 16, 2018

@JeffBezanson

This comment has been minimized.

Copy link
Member

commented Oct 20, 2018

This seems pretty inefficient --- is there a way to do this via the mpfr_sprintf format string?

@rfourquet

This comment has been minimized.

Copy link
Contributor Author

commented Nov 30, 2018

This seems pretty inefficient

I just did basic benchmarks to check that, and it's (only) about 35% slower.

is there a way to do this via the mpfr_sprintf format string?

I tried that but didn't find how (IIRC), so ended up with the handmade version.

make use of scientific notation for BigFloat consistent with other types
This switches to non-scientific notation when the scientific exponent
would be in `-4:5`, as is the case for e.g. Float64.
For example, `string(big(42.0))` is now `"42.0"`.

@rfourquet rfourquet force-pushed the rf/bigfloat-print branch from 5543ac0 to 536a165 Nov 30, 2018

@rfourquet rfourquet removed the needs news label Nov 30, 2018

@JeffBezanson

This comment has been minimized.

Copy link
Member

commented Dec 3, 2018

Ok. This is a very good change, so I'll merge it.

@JeffBezanson JeffBezanson merged commit 7ea4542 into master Dec 3, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@JeffBezanson JeffBezanson deleted the rf/bigfloat-print branch Dec 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.