Skip to content

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

Open
@jepers

Description

@jepers
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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions