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

1.0E0 allowed but not 1.0F0 #22273

Closed
stevengj opened this issue Jun 7, 2017 · 13 comments
Closed

1.0E0 allowed but not 1.0F0 #22273

stevengj opened this issue Jun 7, 2017 · 13 comments
Labels
parser Language parsing and surface syntax
Milestone

Comments

@stevengj
Copy link
Member

stevengj commented Jun 7, 2017

Seems like a slight parser inconsistency:

julia> 1.0e0
1.0

julia> 1.0E0
1.0

julia> 1.0f0
1.0f0

julia> 1.0F0
ERROR: UndefVarError: F0 not defined

(Introduced in #1535.)

@stevengj stevengj added the parser Language parsing and surface syntax label Jun 7, 2017
@stevengj
Copy link
Member Author

stevengj commented Jun 7, 2017

For reference, C/C++ allows either case, but in that language f is strictly a suffix (e.g. you would write 1.0e0f). Fortran uses 1.0e0 and 1.0d0 (any case) for single and double precision. Perhaps unsurprisingly, Julia's syntax is more similar to Lisp and Scheme, which allows either case (and adds s for half precision and l for extended precision), although Lisp uses d instead of e for double precision, with e denoting whatever is "default".

@ararslan
Copy link
Member

ararslan commented Jun 7, 2017

Allowing this would technically be a breaking change, since it means float literal juxtaposition with a variable called F0 will mean something different. So before we would be able to introduce that syntax, wouldn't we need to deprecate <literal>F0?

@stevengj
Copy link
Member Author

stevengj commented Jun 7, 2017

Yeah, we'd have to deprecate <literal>F[+-0123456789]. PITA.

@ararslan
Copy link
Member

ararslan commented Jun 7, 2017

An easier alternative that would also provide consistency is to go in the other direction: deprecate E in favor of e. Then everything is lowercase and the deprecation is both easier and less annoying to deal with.

@stevengj
Copy link
Member Author

stevengj commented Jun 8, 2017

parse(Float64, x) should probably continue to be case insensitive, for reading data produced in other languages. In fact, we could make float parsing more permissive, while making Julia parsing less permissive.

@stevengj
Copy link
Member Author

stevengj commented Jun 9, 2017

Currently, parse(Float32, s) is less permissive than Julia:

julia> parse(Float32, "1.0f0")
ERROR: ArgumentError: cannot parse "1.0f0" as Float32
Stacktrace:
 [1] parse(::Type{Float32}, ::String) at ./parse.jl:201

@ararslan
Copy link
Member

ararslan commented Jun 10, 2017

It looks like that's because we do number parsing in C, and the Float32 parsing function, jl_strtof_c, just casts the result of jl_strtod_c to a float. Unsurprisingly, jl_strtod_c isn't set up to accept f/F, just e/E, which is why that fails.

Edit: That's on Windows. On other systems, we use the built-in strtof_l, which calls strtod_l, which also does not parse f.

@vtjnash
Copy link
Member

vtjnash commented Jun 11, 2017

ref #5690

@Keno Keno added this to the 1.0 milestone Jul 20, 2017
@Keno
Copy link
Member

Keno commented Jul 20, 2017

Bump on this. @JeffBezanson feels strongly that E needs to be supported, but doesn't care about F or consistency for consistency's sake. @StefanKarpinski and I were fine with removing support for E. Other people may feel different. Please discuss.

@ararslan
Copy link
Member

+1 for removing E but I don't care that much. -1 for adding F.

@StefanKarpinski
Copy link
Member

See also #11212

@bramtayl
Copy link
Contributor

I wonder if it would be possible to solve it in a more general way similar to string literals, such that 10e6 parses as @e_num 10 6 and 0xFF001122 parses as @x_num 0 FF001122. Or something.

@JeffBezanson
Copy link
Member

I think it's more trouble than it's worth to do anything here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

7 participants