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

Float32 literals without the numeric dot #750

Closed
5 tasks done
Happypig375 opened this issue Jun 13, 2019 · 11 comments
Closed
5 tasks done

Float32 literals without the numeric dot #750

Happypig375 opened this issue Jun 13, 2019 · 11 comments

Comments

@Happypig375
Copy link
Contributor

Float32 literals without the numeric dot

I propose we allow float32 literals without the numeric dot.

The existing way of approaching this problem in F# is having that extra dot when typing float32 literals with that extra, ugly dot. Consider the beautiful decimal literals:

Microsoft (R) F# Interactive version 10.4.0 for F# 4.6
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> 750m;;
val it : decimal = 750M

> 750M;;
val it : decimal = 750M

> 750f;;

  750f;;
  ^^^^

stdin(3,1): error FS1156: This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0b0001 (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger).

> 750.f;;
val it : float32 = 750.0f

Pros and Cons

The advantages of making this adjustment to F# are consistency between literals: 750. is float, 750m is decimal, and 750f is float32.

The disadvantage of making this adjustment to F# is implementation complexity.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): XS

Related suggestions: dotnet/fsharp#6992

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@7sharp9
Copy link
Member

7sharp9 commented Jun 13, 2019

Having to put the dot is rather annoying. Even with this a float still would have to have a dot which is another inconsistency.

@Happypig375
Copy link
Contributor Author

I proposed ff and FF for floats at #737 (comment) but single-character suffixes would be more appropriate.

@cartermp
Copy link
Member

Generally I'd be supportive of this, since the decimal case is already supported.

@realvictorprm
Copy link
Member

If this is approved I can take care of the implementation. It's rather simple to implement, just a change in the parse&lexer I guess.

@dsyme
Copy link
Collaborator

dsyme commented Jul 1, 2019

Yes, this is reasonable. Marking as approved

@abelbraaksma
Copy link
Member

@gdziadkiewicz, nice to see you working on this. Are you also doing the RFC? I know it's a small language change, but I believe we should always have an RFC in place to cover language feature changes.

I can make one, I'm just holding off in case we would both be working on it ;).

@gdziadkiewicz
Copy link

If you are willing to create the RFC then please do so - I didn't start working on it yet :)

@abelbraaksma
Copy link
Member

abelbraaksma commented Nov 10, 2019

@Happypig375, could you give this suggestion a more meaningful title please? Something like 'Allow literal integers to be float when they have a suffix "f" '? (I only see '750f' now, which seems to be the number of the issue)

@gdziadkiewicz, I'll give it a try :)

@abelbraaksma
Copy link
Member

abelbraaksma commented Nov 22, 2019

@gdziadkiewicz, I totally forgot, thanks for doing the work! 💯

For ease of cross reference:

RFC: https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1080-float32-without-dot.md
RFC discussion: fsharp/fslang-design#414
Implementation: dotnet/fsharp#7839

@Happypig375 Happypig375 changed the title 750f Float32 literals without the numeric dot Dec 15, 2019
@dsyme
Copy link
Collaborator

dsyme commented May 28, 2020

closing as this has been completed, see the RFC

@abelbraaksma
Copy link
Member

@dsyme, yes it is, but there's small gotcha though, I reported it here: dotnet/fsharp#9338 (though I think it's too minor to warrant a fix before F# 5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants