-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SE-0080 (2/5) - Failable initializers for Float->Float #2977
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
SE-0080 (2/5) - Failable initializers for Float->Float #2977
Conversation
e16ffba
to
e2b9c14
Compare
@swift-ci Please test |
#if !os(Windows) && (arch(i386) || arch(x86_64)) | ||
% end | ||
% end | ||
|
||
/// Construct an instance that approximates `other`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restore the old comment for the case when Self
is That
(Create an instance initialized to ...
).
@stephentyrone Could you review, please? I'm not 100% sure what is the desired behavior for NaN. I can see it argued both ways:
|
#if arch(i386) || arch(x86_64) | ||
% end | ||
|
||
% for OtherFloat, otherSignificandBits in floatNameToSignificandBits.iteritems(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation of the second-level %if
and %for
is inconsistent, would you mind fixing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think I got this right. You're right, it was all over the place from moving things around over time.
e2b9c14
to
9345d65
Compare
Yeah, so @gribozavr / @stephentyrone on the NaN deal: I went back and forth on it and meant to leave a note asking for guidance. It seemed like not propagating the NaN is the right move, but I got stuck going back and forth on it. Maybe it should propagate, like the -Inf/+Inf special cases? It's at the very least not the same case as truncation, where we're advertising that we'll return nil. |
(Also I guess the change I just made to |
There are two competing considerations WRT how
General practice in floating-point is that it's OK to "lose" NaNs if the exceptional condition is tracked by some other means (here, returning
I come down weakly in favor of returning |
if ${That}(self) != other { | ||
return nil | ||
} | ||
% endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endif
vs end
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've got that fixed locally. I was waiting on ideas on NaN handling before I pushed changes again.
9345d65
to
548911f
Compare
/// Create an ${That} initialized to `value`, if `value` can be represented without rounding. | ||
/// - note: This is effectively checking that `inputValue == outputValue`, meaning `NaN` inputs will always return `nil`. | ||
@_transparent | ||
public init?(exactly other: ${That}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look ok as a revision?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the function to be @inline(__always)
instead of @_transparent
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To elaborate, @_transparent
affects compile-time diagnostics, and I don't think we have any special diagnostics support in the compiler for this new initializer.
@ultramiraculous Thank you! LGTM modulo comments. Let's run it in CI: @swift-ci Please test |
548911f
to
c0f7a4e
Compare
@swift-ci Please test |
} | ||
|
||
/// Create an ${That} initialized to `value`, if `value` can be represented without rounding. | ||
/// - note: This is effectively checking that `inputValue == outputValue`, meaning `NaN` inputs will always return `nil`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should "an ${That}" be "a ${That}"? The substitutions are Float
, Double
, and Float80
.
Also, could you wrap to 80 columns and add an empty line before "- note"?
@ultramiraculous Thank you very much for working on this PR! |
d5ed380
to
e7a5e67
Compare
e7a5e67
to
025a699
Compare
@swift-ci Please test and merge |
What's in this pull request?
Breaking out from #2742. Adds
init?(exactly:)
initializers for float types from other float types.Resolved bug number: (SR-1491)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.