Skip to content

Fix printf formatting #48

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

Merged
merged 2 commits into from
Oct 11, 2017
Merged

Conversation

jmkuhn
Copy link
Collaborator

@jmkuhn jmkuhn commented Oct 10, 2017

Fixes Issue #26. Implements %f %F %e %E %g %G. Doesn't implement %a/%A.

I also added the Dec*(x::AbstractString) constructor to simplify writing the tests.

src/DecFP.jl Outdated
@@ -102,11 +103,80 @@ for w in (32,64,128)
return xchk(x, InexactError, :parse, $BID, s)
end

$BID(x::AbstractString) = parse($BID, x)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this. Base doesn't define Int("3"), after all.

If this is just defined for the tests, we could define this method in runtests.jl.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Base does define BigFloat("1").

Copy link
Member

Choose a reason for hiding this comment

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

Oh, ok.

@stevengj
Copy link
Member

This is great, thanks for working on this. Can we change the default show method to be prettier (more like Float64 output) too?

@jmkuhn
Copy link
Collaborator Author

jmkuhn commented Oct 10, 2017

I'll work on show and update the PR.

@jmkuhn
Copy link
Collaborator Author

jmkuhn commented Oct 11, 2017

The output from show is not identical to the Float64 version, but it is much prettier than the old show.

@@ -79,6 +79,14 @@ function isnanstr(s::AbstractString)
return true
end

function Base.show(io::IO, x::DecimalFloatingPoint)
s = @sprintf("%g", x)
if ismatch(r"^-?\d+$", s)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't '.' ∉ s be sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using my current implementation,

julia> show(d64"1e10")
1e+10

Replacing ismatch with ∉ would produce 1e+10.0

Copy link
Member

Choose a reason for hiding this comment

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

Okay.

@stevengj
Copy link
Member

LGTM. The CI failures on 0.7 (nightly) are unrelated.

@stevengj stevengj merged commit 3b28783 into JuliaMath:master Oct 11, 2017
@stevengj stevengj mentioned this pull request Oct 11, 2017
@jmkuhn jmkuhn deleted the pull-request/5c3a555c branch October 11, 2017 20:53
@stevengj stevengj mentioned this pull request Feb 6, 2018
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.

2 participants