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

print(::Float32) should use e instead of Julia specific f #18053

Closed
wants to merge 1 commit into from

Conversation

kshramt
Copy link

@kshramt kshramt commented Aug 16, 2016

Note:

Currently, showcompact(::Float32) prints typed representation for Float32 (e.g. 1.0f10).
Although this behaviour is inconsistent with the documentation of showcompact,
I kept the behaviour as is, following the discussions of #17720.

Note:

Currently, `showcompact(::Float32)` prints typed representation for `Float32` (e.g. `1.0f10`).
Although this behaviour is inconsistent with [the documentation of `showcompact`](http://docs.julialang.org/en/latest/stdlib/io-network/?highlight=showcompact),
I kept the behaviour as is, following the discussions of <JuliaLang#17720>.
@tkelman
Copy link
Contributor

tkelman commented Aug 16, 2016

This is getting pretty confusing to keep track of when a Float32 should be printed with e and when it should be printed with f. I think it would be better to be consistent about always printing with f by default, and consumers like JSON.jl that want to convert to other formats can specifically request a format that uses e.

@tkelman tkelman added the domain:io Involving the I/O subsystem: libuv, read, write, etc. label Aug 16, 2016
@JeffBezanson
Copy link
Sponsor Member

The second change here uses f in even more places than before, and introduces a further inconsistency:

julia> [1.0f0]
1-element Array{Float32,1}:
 1.0f0

julia> [1.0e0]
1-element Array{Float64,1}:
 1.0

The typed flag means to always print the type-identifying f, as opposed to only printing it in place of e.

@kshramt
Copy link
Author

kshramt commented Aug 17, 2016

@tkelman
I am -1.0f0 for always printing f.
As documented, show should be used if a value should be printed with Julia-specific details.
print should not print Julia-specific details.

http://docs.julialang.org/en/latest/stdlib/io-network/?highlight=showcompact#Base.show

The representation used by show generally includes Julia-specific formatting and type information.

http://docs.julialang.org/en/latest/stdlib/io-network/?highlight=showcompact#Base.print

The representation used by print includes minimal formatting and tries to avoid Julia-specific details.

@JeffBezanson
#17720 requires show to print the redundant type information f for elements of a Float32 array.
I am -1 for the behavior of #17720, but tried to follow the behavior.
If I understand correctly, #17720 requires show([1f0]) to be printed as

1-element Array{Float32,1}:
 1.0f0

instead of

1-element Array{Float32,1}:                                                                                           │
 1.0

to make it clear that the element in the array is Float32.

(Travis CI failure is due to a time-limitation for OSX build.)

@slundberg
Copy link
Contributor

Any update here? The current status is that JSON fails with small Float32 values...

@JeffBezanson
Copy link
Sponsor Member

Working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants