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

[Experimental] Replace FloatingPoint Formatter and add support Float80 #151

Closed
wants to merge 9 commits into from

Conversation

norio-nomura
Copy link
Collaborator

@norio-nomura norio-nomura commented Jan 7, 2019

  • Use SwiftDtoa.(h|cpp) for formatting FloatingPoint into String
  • Support Float80 as ScalarConstructible and ScalarRepresentable

On Linux, Supporting Float80 requires Swift 4.2+, since swift_decompose_float80() does not exists on Swift 4.1 or earlier.
Is this a good opportunity to drop supporting Swift 4.0/4.1?

@norio-nomura norio-nomura changed the title [WIP] Use SwiftDtoa from apple/swift [WIP] Support Float80 Jan 7, 2019
Since `swift_decompose_float80()` does not exists on Swift 4.1 or earlier.
@norio-nomura
Copy link
Collaborator Author

On Linux, Supporting Float80 requires Swift 4.2+, since swift_decompose_float80() does not exists on Swift 4.1 or earlier.

Not only on Linux, but also Apple Platforms…

@norio-nomura
Copy link
Collaborator Author

norio-nomura commented Jan 7, 2019

I am not sure if we should adopt this.

Pros:

  • Implementation is interesting
  • Stop using NumberFormatter
  • More accurate formatting result

Cons:

  • The large source file to keep updating
  • The licensing changes may be required
  • "Float80 is ultimately a really rarely used feature at the end of the day"

@norio-nomura norio-nomura changed the title [WIP] Support Float80 [Experimental] Replace FloatingPoint Formatter and add support Float80 Jan 7, 2019
@jpsim
Copy link
Owner

jpsim commented Jan 7, 2019

Agreed 😄

@jpsim
Copy link
Owner

jpsim commented Jan 7, 2019

This was really cool. I'm sad to see it go :/

@norio-nomura
Copy link
Collaborator Author

I will leave the branch for the time being. :)

@norio-nomura
Copy link
Collaborator Author

norio-nomura commented Jan 7, 2019

filed a request as SR-9610 to exporting swift_decompose_double(), swift_decompose_float(), swift_decompose_float80() and swift_format_exponential() from libswiftCore

@norio-nomura
Copy link
Collaborator Author

filed a request as SR-9610 to exporting swift_decompose_double(), swift_decompose_float(), swift_decompose_float80() and swift_format_exponential() from libswiftCore

It seems that "Swift Evolution Process" is necessary to realize that. But for me it feels that it requires too much effort. 🤔
How about creating SwiftDtoa as separated project and use them from Yams?

@jpsim
Copy link
Owner

jpsim commented Jan 9, 2019

Would it be an option to add Float80 support to NumberFormatter instead?

@norio-nomura
Copy link
Collaborator Author

I don't think NSNumber that is required by NumberFormatter.string(from:) is supporting Float80.

@jpsim
Copy link
Owner

jpsim commented Jan 9, 2019

I'm curious, other than being spec compliant with the YAML specification, is there a real world motivation for supporting Float80?

@norio-nomura
Copy link
Collaborator Author

is there a real world motivation for supporting Float80?

No.
But, sorry, I forgot that there is another motivation to introduce this.
While creating this PR, I found that formatting results of greatestFiniteMagnitude and leastNormalMagnitude on both of Double and Float are different from that using SwiftDtoa.
If we believe SwiftDtoa 's commit description, the current Yams implementation formatting Double and Float will be incorrect.

@norio-nomura
Copy link
Collaborator Author

I found that formatting results of greatestFiniteMagnitude and leastNormalMagnitude on both of Double and Float are different from that using SwiftDtoa.

opened #152 for indicating current formatting results.

@norio-nomura
Copy link
Collaborator Author

norio-nomura commented Jan 9, 2019

@norio-nomura
Copy link
Collaborator Author

Diffs of formatting results: https://github.com/jpsim/Yams/compare/use-swift-dtoa#diff-0c522086aa5f2635d87e4f06bbea524dR51

Oops!: Correct link is here.

@jpsim
Copy link
Owner

jpsim commented Jan 9, 2019

It's really just a difference of significant digits printed

-1.79769313486232e+308
-2.2250738585072e-308
+1.7976931348623157e+308
+2.2250738585072014e-308

I guess if you're doing Yams for scientific computing (which is also basically the only reason to use Float80), then SwiftDtoa's implementation would be slightly better. I just don't think it's worth the extra complexity personally.

@norio-nomura
Copy link
Collaborator Author

I just don't think it's worth the extra complexity personally.

👍 Let's forget this until Float80 becomes Codable: SR-9607

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.

None yet

2 participants