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

[SR-8681] lldb should use the better algorithm for float printing (like Swift) #4362

Open
jepers opened this issue Sep 1, 2018 · 5 comments

Comments

@jepers
Copy link

jepers commented Sep 1, 2018

Previous ID SR-8681
Radar None
Original Reporter @jepers
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Improvement
Assignee None
Priority Medium

md5: 8dd91e31acdf34ed560b155632235ce2

Issue Description:

Filing this as suggested by @jckarter in this forum post.

Swift 4.2 uses a new algorithm that should always print a minimal-length decimal value that parses back into the original floating-point value, so Double(String( x )) always produces x.

I noticed that the REPL still uses the old algorithm:

$ swift
Welcome to Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.0.4). Type :help for assistance.
  1> 0.3
$R0: Double = 0.29999999999999999
  2> 0.3.debugDescription
$R1: String = "0.3"

Just for completion, here is the same session with Swift 4.1, where the old algorithm was used not only for the REPL's feedback but also for eg the result of 0.3.debugDescription:

$ swift
Welcome to Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2). Type :help for assistance.
  1> 0.3
$R0: Double = 0.29999999999999999
  2> 0.3.debugDescription
$R1: String = "0.29999999999999999"
@belkadan
Copy link

belkadan commented Sep 4, 2018

Arguably useful for LLDB in non-Swift modes too. cc jingham@apple.com (JIRA User)

@swift-ci
Copy link

swift-ci commented Sep 4, 2018

Comment by Jim Ingham (JIRA)

lldb uses APFloat API's to print doubles and floats. Does the swift printing use that or something layered on top of that? If the former it should be pretty easy to include whatever flags you use to get this behavior out of APFloat. If the latter, we should move this code somewhere in llvm so lldb doesn't have to reimplement it.

@belkadan
Copy link

belkadan commented Sep 4, 2018

@stephentyrone, is the Swift logic implemented in Swift or C++?

@stephentyrone
Copy link
Member

It's actually in C, compiled as C++, with some very lightweight Swift wrappers. We should move APFloat to use it for better performance anyway.

Semi-tangential, what would need to happen for LLDB to use debugDescription? Isn't this what it's for?

@belkadan
Copy link

belkadan commented Sep 4, 2018

debugDescription is used for 'print-object', but normal LLDB printing must not run any code in-process.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
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