Skip to content

[stdlib] More verbose debugDescription for NaN #2786

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

Merged
merged 2 commits into from
Jun 7, 2016

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 31, 2016

What's in this pull request?

Follow-up on #1922

Now, the format of debugDescription for NaN is:
-[(0xhexadecimal-digits­)]

@stephentyrone
Could you confirm the format?

@gribozavr
Should we use more high level APIs?


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

#if !arch(i386)
expectDebugPrinted("snan", Float.signalingNaN)
expectDebugPrinted("snan(0xffff)", Float(nan: 65535, signaling: true))
expectDebugPrinted("-snan(0xffff)", -Float(nan: 65535, signaling: true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests with the largest possible payload, to make sure that high bits are not dropped in any of the conversions?

@rintaro rintaro force-pushed the float-debugdesc branch from 82d738f to 7a99dbf Compare June 3, 2016 13:16
expectDebugPrinted("nan(0xffff)", Float(nan: 65535, signaling: false))
expectDebugPrinted("-nan(0xffff)", -Float(nan: 65535, signaling: false))
expectDebugPrinted("nan(0x1fffff)", Float(bitPattern: 0x7fff_ffff))
expectDebugPrinted("nan(0x1fffff)", Float(bitPattern: 0x7fdf_ffff))
Copy link
Member Author

@rintaro rintaro Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, current implementation drops MSB of payload bits,
because that bit is reserved for placeholder payload of signaling NaN.
I'm not sure whether this behavior is reasonable or not. @stephentyrone ?

@rintaro
Copy link
Member Author

rintaro commented Jun 3, 2016

To clarify the largest NaN payload value.
Added some test cases for NaNs.

@rintaro
Copy link
Member Author

rintaro commented Jun 3, 2016

@swift-ci Please test

}
let isSignaling = (significand & Float${bits}._quietNaNMask) == 0
let payload = significand & ((Float${bits}._quietNaNMask >> 1) - 1)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a FIXME note here, as these string manipulations are inefficient enough to make someone want to optimize them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, we could move some of the string concatenation into the C function that we are calling below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use FIXME(performance) for these kinds of notes.

@moiseev
Copy link
Contributor

moiseev commented Jun 6, 2016

Minor note: there is enough repetition in FloatingPoint.swift.gyb that it could benefit from using GYB. Otherwise looks good. Happy to merge it once @stephentyrone confirms.

@moiseev
Copy link
Contributor

moiseev commented Jun 6, 2016

Oh, and yes, for the record, Linux build failure is unrelated.

@stephentyrone
Copy link
Contributor

@moiseev Format looks good.

rintaro added 2 commits June 7, 2016 10:52
The format of debugDescription for NaN is:
[ '-' ] ( 'snan' | 'nan' ) [ '(0x' hexadecimal-digits ')' ]
@rintaro rintaro force-pushed the float-debugdesc branch from 7a99dbf to 702a5ab Compare June 7, 2016 01:52
@rintaro
Copy link
Member Author

rintaro commented Jun 7, 2016

Added FIXME note.

@gribozavr
Copy link
Contributor

gribozavr commented Jun 7, 2016

@rintaro Thank you!

@swift-ci Please test and merge

@swift-ci swift-ci merged commit 7a736cc into swiftlang:master Jun 7, 2016
@rintaro rintaro deleted the float-debugdesc branch June 22, 2016 10:00
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.

5 participants