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

Extend custom numeric types to support floating point literals #445

Open
baronfel opened this issue Oct 20, 2016 · 3 comments
Open

Extend custom numeric types to support floating point literals #445

baronfel opened this issue Oct 20, 2016 · 3 comments

Comments

@baronfel
Copy link
Contributor

baronfel commented Oct 20, 2016

Currently you can define custom numeric types for integer values.
It would be nice to be able to handle floating point values too, e.g.

type complex = 
    | Complex of double * double

type imaginery = 
    | Imaginery of double
    static member (+) (lhs:double,Imaginery(rhs)) = Complex(lhs,rhs)

module NumericLiteralI =
    let FromZero () = Imaginery 0.0
    let FromOne () = Imaginery 1.0
    let FromInt32 (x) = Imaginery (double x)
    let FromInt64 (x:int64) = Imaginery (double x)
    let FromDouble (x:float) = Imaginery x // extension
    let polar = 1.5 + 2.5I

Original UserVoice Submission

@dsyme
Copy link
Collaborator

dsyme commented Oct 29, 2016

Now marking as planned, which means we can move to an RFC https://github.com/fsharp/FSharpLangDesign/tree/master/RFCs. Please submit one if we don't get to it first. The details remain to be worked out however

Don Syme
F# Language Evolution

@jbeeko
Copy link

jbeeko commented Feb 5, 2017

Is there any reason to not support Decimal as well?

@Happypig375
Copy link
Contributor

To match F# terminology, the new function should be called FromFloat.
That function should only be used when the literal has <=15 significant figures and its exponent is within -300 to 300.
For values outside of this range, a FromFloatString should be added.

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

4 participants