Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Fix Float mapping with downcasting #142

Merged
merged 1 commit into from
Jul 31, 2018
Merged

Fix Float mapping with downcasting #142

merged 1 commit into from
Jul 31, 2018

Conversation

keith
Copy link
Contributor

@keith keith commented Jul 31, 2018

The behavior of NSNumber as? Float in Swift is such that some values
that cannot "safely express the value stored" in NSNumber. This means
only using as? to cast to Float can fail, where doing .floatValue
or Float.init would succeed. To work around this oddity, this new
Convertible conformance calls .floatValue on NSNumber, leading to
a float, that is possibly less precise than you'd like.

The behavior of `NSNumber as? Float` in Swift is such that some values
that cannot "safely express the value stored" in NSNumber. This means
only using `as?` to cast to `Float` can fail, where doing `.floatValue`
or `Float.init` would succeed. To work around this oddity, this new
`Convertible` conformance calls `.floatValue` on `NSNumber`, leading to
a float, that is possibly less precise than you'd like.
@keith keith merged commit 4adc773 into master Jul 31, 2018
@keith keith deleted the ks/float-fix branch July 31, 2018 00:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants