[swift-evolution] [Proposal] Add floor() and ceiling() functions to FloatingPoint

David Hart david at hartbit.com
Mon Jun 27 15:35:15 CDT 2016


Hadn't thought of roundUp/Down. Makes it so obvious. +10

> On 27 Jun 2016, at 18:32, Erica Sadun <erica at ericasadun.com> wrote:
> 
> I'm with those recommending round, rounded, roundUp, roundedUp, roundDown, 
> roundedDown, with Remy's precision factored in as needed.
> 
> This is usually the point where Dave A wanders in and explains how this can all be 
> implemented by a single FloatingPoint protocol, with built-in properties
> and methods across all FP types in order to limit the API surface area that would be
> otherwise affected by creating a whole bunch of native stdlib freestanding functions,
> even generic ones.
> 
> -- E, starting the "Tailor Swift Simply" party
> 
> 
>> On Jun 27, 2016, at 12:53 AM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I disagree: in English, the nouns are floor and ceiling. That's what they should be called.
>> On Mon, Jun 27, 2016 at 02:41 David Hart <david at hartbit.com> wrote:
>>> Whatever the naming scheme, I would be hesitant to have the non-mutating versions of floor and ceil have different endings, seeing how connected they are. So:
>>> 
>>> floor, ceil 
>>> floored, ceiled 
>>> flooring, ceiling
>>> 
>>> But not a mix.
>>> 
>>>> On 27 Jun 2016, at 07:13, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>>>> 
>>>>> On Mon, Jun 27, 2016 at 12:45 AM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
>>>>> Given the API guidelines, it should be
>>>>> 
>>>>> rounded, ceiled, floored 
>>>>> 
>>>>> for returning the rounded/ceiled/floored value and
>>>>> 
>>>>> round(), ceil(), floor()
>>>>> 
>>>>> would be the mutating variants. Question is where it's not too confusing for anyone knowing these from another language.
>>>> 
>>>> Although colloquially they can be "verbed," ceil[ing] and floor are formally nouns, just like sine, union, etc. So the API guidelines would recommend: `rounded`, `ceiling`, `floor` for the non-mutating version and `round`, `formCeiling`, and `formFloor` for the mutating version.
>>>> 
>>>>> 
>>>>>> On Jun 25, 2016, at 9:02 PM, Remy Demarest via swift-evolution <swift-evolution at swift.org> wrote:
>>>>>> 
>>>>>> We don't seem to have a rounded() function either as part of FloatingPoint, we should probably have these methods in the end:
>>>>>> 
>>>>>> func rounded() -> Self
>>>>>> func rounded(withPrecision: Int) -> Self
>>>>>> 
>>>>>> Along with the 4 other methods proposed below.
>>>>>> 
>>>>>>>> Le 25 juin 2016 à 11:55, Haravikk via swift-evolution <swift-evolution at swift.org> a écrit :
>>>>>>>> 
>>>>>>>> 
>>>>>>> 
>>>>>>>> On 25 Jun 2016, at 11:06, Karl via swift-evolution <swift-evolution at swift.org> wrote:
>>>>>>>> 
>>>>>>>> floor() and ceil(), exactly like C. ceiling() is more descriptive and is a mathematical term of art.
>>>>>>>> nextIntegralUp() and nextIntegralDown() are more descriptive still, but possibly misleading as (4.0).nextIntegralUp() == 4.0
>>>>>>> I'm in favour of these capabilities being there, but in terms of naming I've often wondered why it can't just be part of a rounding group of methods like so:
>>>>>>> 
>>>>>>> 	func roundedUp() -> Self { … }
>>>>>>> 	func roundedUp(withPrecision:Int) -> Self { … }
>>>>>>> 	func roundedDown() -> Self { … }
>>>>>>> 	func roundedDown(withPrecision:Int) -> Self { … }
>>>>>>> 
>>>>>>> Since the methods with implied precision of zero are equivalent to floor and ceiling surely? I know floor and ceiling are pretty common terms, but they're just a form rounding when it comes down to it.
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160627/54502d7c/attachment.html>


More information about the swift-evolution mailing list