ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:66814] [ruby-trunk - Bug #10594] [Open] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
@ 2014-12-12 21:45 ` findchris
  2014-12-12 22:25 ` [ruby-core:66817] [ruby-trunk - Bug #10594] Numeric#clamp findchris
                   ` (29 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: findchris @ 2014-12-12 21:45 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been reported by Chris Johnson.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:66817] [ruby-trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
  2014-12-12 21:45 ` [ruby-core:66814] [ruby-trunk - Bug #10594] [Open] Numeric#clamp findchris
@ 2014-12-12 22:25 ` findchris
  2015-06-27  9:55 ` [ruby-core:69754] [Ruby trunk " nerdinand
                   ` (28 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: findchris @ 2014-12-12 22:25 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Chris Johnson.


Example behavior:

~~~

234234234523.clamp(0..100)  # => 100
12.clamp(0..100)            # => 12  
-38817112.clamp(0..100)     # => 0

~~~

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-50386

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69754] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
  2014-12-12 21:45 ` [ruby-core:66814] [ruby-trunk - Bug #10594] [Open] Numeric#clamp findchris
  2014-12-12 22:25 ` [ruby-core:66817] [ruby-trunk - Bug #10594] Numeric#clamp findchris
@ 2015-06-27  9:55 ` nerdinand
  2015-06-29 10:38 ` [ruby-core:69771] " kosaki.motohiro
                   ` (27 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-06-27  9:55 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Here's a pull request for this: https://github.com/ruby/ruby/pull/947


----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53131

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69771] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-06-27  9:55 ` [ruby-core:69754] [Ruby trunk " nerdinand
@ 2015-06-29 10:38 ` kosaki.motohiro
  2015-06-29 19:01 ` [ruby-core:69776] " nerdinand
                   ` (26 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: kosaki.motohiro @ 2015-06-29 10:38 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Motohiro KOSAKI.


>+    double num_dbl = NUM2DBL(num);
>+    double beg_dbl = NUM2DBL(begp);
>+    double end_dbl = NUM2DBL(endp);

If num is Bignum, the above code could make data loss. I think.
Why can't we use "num"'s <, <= or <=> operator?

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53149

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69776] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-06-29 10:38 ` [ruby-core:69771] " kosaki.motohiro
@ 2015-06-29 19:01 ` nerdinand
  2015-06-30  2:18 ` [ruby-core:69783] " 0x0dea+redmine
                   ` (25 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-06-29 19:01 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Motohiro KOSAKI wrote:
> >+    double num_dbl = NUM2DBL(num);
> >+    double beg_dbl = NUM2DBL(begp);
> >+    double end_dbl = NUM2DBL(endp);
> 
> If num is Bignum, the above code could make data loss. I think.
> Why can't we use "num"'s <, <= or <=> operator?

I guess you're right. I just didn't really know how to do that. How would I use the operators?

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53154

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69783] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-06-29 19:01 ` [ruby-core:69776] " nerdinand
@ 2015-06-30  2:18 ` 0x0dea+redmine
  2015-06-30  8:43 ` [ruby-core:69814] " hanmac
                   ` (24 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-06-30  2:18 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.

File num_clamp.c added

Ferdinand Niedermann wrote:

> How would I use the operators?

I've attached an implementation of `num_clamp()` which uses `rb_funcall()` to invoke the receiver's `#<` and `#>` methods. It also checks the value of `exclp` in order to properly handle ranges with exclusive ends, such that `3.clamp(1...3) == 2`. 

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53161

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69814] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-06-30  2:18 ` [ruby-core:69783] " 0x0dea+redmine
@ 2015-06-30  8:43 ` hanmac
  2015-06-30 10:26 ` [ruby-core:69815] " 0x0dea+redmine
                   ` (23 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: hanmac @ 2015-06-30  8:43 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Hans Mackowiak.


hm might it be a good idea to have such a function directly in Comparable too?

like "x".chomp("a".."e") #=> "e"
hm maybe have it a second way to call it with using "x".chomp("a", "e") too similar to Comparable#between?

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53212

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69815] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-06-30  8:43 ` [ruby-core:69814] " hanmac
@ 2015-06-30 10:26 ` 0x0dea+redmine
  2015-07-03  7:15 ` [ruby-core:69848] " nerdinand
                   ` (22 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-06-30 10:26 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.


Hans Mackowiak wrote:
> hm might it be a good idea to have such a function directly in Comparable too?
> 
> like "x".chomp("a".."e") #=> "e"
> hm maybe have it a second way to call it with using "x".chomp("a", "e") too similar to Comparable#between?

I think your suggestions make a great deal of sense. That `#clamp` should be defined in terms of `#<=>` makes `Comparable` its natural home. Additionally, if the two-argument form were the only way to call it, the implementation would pretty much be the same as for `#between?` but with greater information density: 

```diff
 static VALUE
-cmp_between(VALUE x, VALUE min, VALUE max)
+cmp_clamp(VALUE x, VALUE min, VALUE max)
 {
-    if (RTEST(cmp_lt(x, min))) return Qfalse;
+    if (RTEST(cmp_lt(x, min))) return min;
-    if (RTEST(cmp_gt(x, max))) return Qfalse;
+    if (RTEST(cmp_gt(x, max))) return max;
-    return Qtrue;
+    return x;
 }
```

This approach does away with the potential for confusion introduced by exclusive ranges, made worse by the fact that "predecessor" is not well-defined for most `Comparable`s.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53213

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69848] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-06-30 10:26 ` [ruby-core:69815] " 0x0dea+redmine
@ 2015-07-03  7:15 ` nerdinand
  2015-07-06 15:27 ` [ruby-core:69882] " nerdinand
                   ` (21 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-03  7:15 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


That does make a lot of sense. I'll send another pull request.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53249

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69882] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2015-07-03  7:15 ` [ruby-core:69848] " nerdinand
@ 2015-07-06 15:27 ` nerdinand
  2015-07-07 16:22 ` [ruby-core:69888] " 0x0dea+redmine
                   ` (20 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-06 15:27 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


I tried the basic implementation (adaption of `#between?`). What should we do about cases like these?
```
irb(main):001:0> 1.clamp(2, 1)
=> 2
irb(main):002:0> 2.clamp(2, 1)
=> 1
```

With `#between?` these make more sense, because nothing is in the Range of 2 to 1:
```
irb(main):003:0> 1.between?(2, 1)
=> false
irb(main):004:0> 2.between?(2, 1)
=> false
```

Should we return `nil` in this case for `#clamp`?

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53298

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69888] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2015-07-06 15:27 ` [ruby-core:69882] " nerdinand
@ 2015-07-07 16:22 ` 0x0dea+redmine
  2015-07-08 13:00 ` [ruby-core:69901] " nerdinand
                   ` (19 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-07-07 16:22 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.


In the case of `min > max`, the options seem to be these:

* return `nil`
* return the receiver
* raise an `ArgumentError`

Given that the first two are likely to cause something else to explode down the line, it seems best to just stop at the source of the error.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53305

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69901] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2015-07-07 16:22 ` [ruby-core:69888] " 0x0dea+redmine
@ 2015-07-08 13:00 ` nerdinand
  2015-07-08 16:08 ` [ruby-core:69902] " 0x0dea+redmine
                   ` (18 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-08 13:00 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


I think there is even another option: Swapping the min and max values if they are passed in the wrong order.

This is obviously a question of the principle of least surprise. If you compare `#clamp` to `#between?`, it makes sense to actually return something instead of raising, because `#between?` does the same.
But as you say, one could argue that it's best to catch the error as early as possible, so raising would be a good option.

The only thing I definitely would not agree with is returning the receiver, as that is a valid behaviour if the receiver is between `min` and `max`. I think it would lead to confusion.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53319

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69902] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2015-07-08 13:00 ` [ruby-core:69901] " nerdinand
@ 2015-07-08 16:08 ` 0x0dea+redmine
  2015-07-09  7:33 ` [ruby-core:69917] " nerdinand
                   ` (17 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-07-08 16:08 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.


> I think there is even another option: Swapping the min and max values if they are passed in the wrong order.

I suspect there is little to no precedent for allowing "position-independent positional arguments". It's true that they could be tolerated and correctly handled in the case of `#clamp`, but doing so would likely hide some logic error elsewhere in the program.

`#between?` is a query method and thus observes the widespread convention of returning *only* either `true` or `false`. That nothing exists between 2 on the left and 1 on the right means `#between?` is correct not to raise given such input.

I confess that I only suggested returning the receiver to pad the list. It *would* potentially indicate to the caller that the requested operation couldn't be performed, but that's precisely what exceptions are for.

Silently swapping is antithetical to the very notion of positional arguments, returning `nil` is just going to make something else fail, and returning the receiver goes against the method's *raison d'être*.

The only potential alternative I see to raising an `ArgumentError` in the case of `min` > `max` would be to make them keyword arguments, but that would break symmetry with `#between?` and feels heavy-handed besides.

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53320

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69917] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2015-07-08 16:08 ` [ruby-core:69902] " 0x0dea+redmine
@ 2015-07-09  7:33 ` nerdinand
  2015-07-09 20:28 ` [ruby-core:69920] " nerdinand
                   ` (16 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-09  7:33 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


> That `min > max` should raise an `ArgumentError` seems the only logical conclusion.

I agree. I'll send another pull request including that.


----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53342

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69920] [Ruby trunk - Bug #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2015-07-09  7:33 ` [ruby-core:69917] " nerdinand
@ 2015-07-09 20:28 ` nerdinand
  2015-07-09 22:27 ` [ruby-core:69923] [Ruby trunk - Feature " nobu
                   ` (15 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-09 20:28 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Here you go: https://github.com/ruby/ruby/pull/962

----------------------------------------
Bug #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53344

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69923] [Ruby trunk - Feature #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2015-07-09 20:28 ` [ruby-core:69920] " nerdinand
@ 2015-07-09 22:27 ` nobu
  2015-07-09 23:12 ` [ruby-core:69924] " 0x0dea+redmine
                   ` (14 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nobu @ 2015-07-09 22:27 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Nobuyoshi Nakada.

Tracker changed from Bug to Feature

----------------------------------------
Feature #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53346

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69924] [Ruby trunk - Feature #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2015-07-09 22:27 ` [ruby-core:69923] [Ruby trunk - Feature " nobu
@ 2015-07-09 23:12 ` 0x0dea+redmine
  2015-07-10  5:32 ` [ruby-core:69929] " nerdinand
                   ` (13 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-07-09 23:12 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.


Ferdinand Niedermann wrote:
> Here you go: https://github.com/ruby/ruby/pull/962

The failure condition should be `min > max` rather than `max < min`. It's arguably rather silly to clamp to a single value, but the operation is nevertheless well-defined, and it would therefore be an error for `#clamp` to raise given equal `min` and `max`.

----------------------------------------
Feature #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53347

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69929] [Ruby trunk - Feature #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2015-07-09 23:12 ` [ruby-core:69924] " 0x0dea+redmine
@ 2015-07-10  5:32 ` nerdinand
  2015-07-10 15:39 ` [ruby-core:69941] " 0x0dea+redmine
                   ` (12 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-07-10  5:32 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


D.E. Akers wrote:
> Ferdinand Niedermann wrote:
> > Here you go: https://github.com/ruby/ruby/pull/962
> 
> The failure condition should be `min > max` rather than `max < min`. It's arguably rather silly to clamp to a single value, but the operation is nevertheless well-defined, and it would therefore be an error for `#clamp` to raise given equal `min` and `max`.

That doesn't really change anything, but I updated the pull request. I added some more tests to prove that it doesn't raise given equal `min` and `max`.

----------------------------------------
Feature #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53352

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:69941] [Ruby trunk - Feature #10594] Numeric#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2015-07-10  5:32 ` [ruby-core:69929] " nerdinand
@ 2015-07-10 15:39 ` 0x0dea+redmine
  2015-09-02 18:12 ` [ruby-core:70655] [Ruby trunk - Feature #10594] Comparable#clamp nerdinand
                   ` (11 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: 0x0dea+redmine @ 2015-07-10 15:39 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by D.E. Akers.


Ferdinand Niedermann wrote:
> That doesn't really change anything

You're right, of course. I'm not sure why I read it as "raise unless `max > min`". The error message is still slightly ill-worded, but everything else looks good. I hope `#clamp` makes it in. The `sort[1]` trick is nice, but it's a little too "clever".

----------------------------------------
Feature #10594: Numeric#clamp
https://bugs.ruby-lang.org/issues/10594#change-53368

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70655] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2015-07-10 15:39 ` [ruby-core:69941] " 0x0dea+redmine
@ 2015-09-02 18:12 ` nerdinand
  2015-09-14 20:13 ` [ruby-core:70804] " kosaki.motohiro
                   ` (10 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-09-02 18:12 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.

File comparable-clamp.diff added
Subject changed from Numeric#clamp to Comparable#clamp

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54053

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70804] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (19 preceding siblings ...)
  2015-09-02 18:12 ` [ruby-core:70655] [Ruby trunk - Feature #10594] Comparable#clamp nerdinand
@ 2015-09-14 20:13 ` kosaki.motohiro
  2015-09-15  5:24 ` [ruby-core:70810] " hanmac
                   ` (9 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: kosaki.motohiro @ 2015-09-14 20:13 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Motohiro KOSAKI.


I really dislike using Comparable for this method because clamp is NOT kind of compare. If it is Numeric's method, I'm OK.


----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54187

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70810] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (20 preceding siblings ...)
  2015-09-14 20:13 ` [ruby-core:70804] " kosaki.motohiro
@ 2015-09-15  5:24 ` hanmac
  2015-09-15  9:42 ` [ruby-core:70811] " eregontp
                   ` (8 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: hanmac @ 2015-09-15  5:24 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Hans Mackowiak.


Motohiro KOSAKI wrote:
> I really dislike using Comparable for this method because clamp is NOT kind of compare. If it is Numeric's method, I'm OK.

hm imo its better in Comparable than in Numeric because it does work for non Numeric objects too, like for String
thats why its better central in Comparable than in Numeric.

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54192

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70811] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (21 preceding siblings ...)
  2015-09-15  5:24 ` [ruby-core:70810] " hanmac
@ 2015-09-15  9:42 ` eregontp
  2015-09-15  9:48 ` [ruby-core:70812] " nerdinand
                   ` (7 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: eregontp @ 2015-09-15  9:42 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Benoit Daloze.


Hans Mackowiak wrote:
> Motohiro KOSAKI wrote:
> > I really dislike using Comparable for this method because clamp is NOT kind of compare. If it is Numeric's method, I'm OK.
> 
> hm imo its better in Comparable than in Numeric because it does work for non Numeric objects too, like for String
> thats why its better central in Comparable than in Numeric.

Good luck explaining the precise semantics of clamp on String though.

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54193

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70812] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (22 preceding siblings ...)
  2015-09-15  9:42 ` [ruby-core:70811] " eregontp
@ 2015-09-15  9:48 ` nerdinand
  2015-09-15 10:06 ` [ruby-core:70813] " eregontp
                   ` (6 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-09-15  9:48 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Benoit Daloze wrote:
> Good luck explaining the precise semantics of clamp on String though.

IMO it's not that hard to grasp:

     call-seq:
        obj.clamp(min, max) ->  obj

    Returns min if obj <=> min is less than zero, max if obj <=> max is
    greater than zero and obj otherwise.

        12.clamp(0, 100)         #=> 12
        523.clamp(0, 100)        #=> 100
        -3.123.clamp(0, 100)     #=> 0

        'd'.clamp('a', 'f')      #=> 'd'
        'z'.clamp('a', 'f')      #=> 'f'


----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54194

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70813] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (23 preceding siblings ...)
  2015-09-15  9:48 ` [ruby-core:70812] " nerdinand
@ 2015-09-15 10:06 ` eregontp
  2015-09-26 11:45 ` [ruby-core:70919] " nerdinand
                   ` (5 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: eregontp @ 2015-09-15 10:06 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Benoit Daloze.


It's just that String#<=> is not consistent with String#succ but indeed it's not so much of a problem here.

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54195

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:70919] [Ruby trunk - Feature #10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (24 preceding siblings ...)
  2015-09-15 10:06 ` [ruby-core:70813] " eregontp
@ 2015-09-26 11:45 ` nerdinand
  2016-07-21 13:10 ` [ruby-core:76503] [Ruby trunk Feature#10594] Comparable#clamp nerdinand
                   ` (4 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2015-09-26 11:45 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Where do we go from here? Is my patch acceptable? If no, what should I change? If yes, what's the process for getting it merged?

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-54282

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76503] [Ruby trunk Feature#10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (25 preceding siblings ...)
  2015-09-26 11:45 ` [ruby-core:70919] " nerdinand
@ 2016-07-21 13:10 ` nerdinand
  2016-07-22  9:33   ` [ruby-core:76521] " Martin J. Dürst
  2016-07-22  9:47 ` [ruby-core:76523] " shyouhei
                   ` (3 subsequent siblings)
  30 siblings, 1 reply; 32+ messages in thread
From: nerdinand @ 2016-07-21 13:10 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Anyone there? I'd love to see this in Ruby finally and I'm not the only one...

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-59746

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76521] Re: [Ruby trunk Feature#10594] Comparable#clamp
  2016-07-21 13:10 ` [ruby-core:76503] [Ruby trunk Feature#10594] Comparable#clamp nerdinand
@ 2016-07-22  9:33   ` Martin J. Dürst
  0 siblings, 0 replies; 32+ messages in thread
From: Martin J. Dürst @ 2016-07-22  9:33 UTC (permalink / raw)
  To: Ruby developers

On 2016/07/21 22:10, nerdinand@nerdinand.com wrote:
> Issue #10594 has been updated by Ferdinand Niedermann.

> Anyone there? I'd love to see this in Ruby finally and I'm not the only one...

One thing I can suggest for those who want to see a reply to this (and 
other) issues is to list it on the next Developers Meeting. The last one 
was this week (see 
https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20160719Japan 
and 
https://docs.google.com/document/d/1nu4pzK9nYNaKKNHQetP2xthvCVXexIsg6GUPoJR7CPQ/pub).

You should list the issues you care about under the "From non-attendees" 
section.

The next meeting is scheduled for August 9th, but the wiki page for it 
is not yet up.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76523] [Ruby trunk Feature#10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (26 preceding siblings ...)
  2016-07-21 13:10 ` [ruby-core:76503] [Ruby trunk Feature#10594] Comparable#clamp nerdinand
@ 2016-07-22  9:47 ` shyouhei
  2016-07-22  9:52 ` [ruby-core:76524] " nerdinand
                   ` (2 subsequent siblings)
  30 siblings, 0 replies; 32+ messages in thread
From: shyouhei @ 2016-07-22  9:47 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Shyouhei Urabe.


Martin Dürst wrote:
>  The next meeting is scheduled for August 9th, but the wiki page for it 
>  is not yet up.

Here you are: https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20160809Japan

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-59765

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76524] [Ruby trunk Feature#10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (27 preceding siblings ...)
  2016-07-22  9:47 ` [ruby-core:76523] " shyouhei
@ 2016-07-22  9:52 ` nerdinand
  2016-07-22 10:55 ` [ruby-core:76528] " shyouhei
  2016-08-09  5:55 ` [ruby-core:76773] " matz
  30 siblings, 0 replies; 32+ messages in thread
From: nerdinand @ 2016-07-22  9:52 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Ferdinand Niedermann.


Shyouhei Urabe wrote:
> Martin Dürst wrote:
> >  The next meeting is scheduled for August 9th, but the wiki page for it 
> >  is not yet up.
> 
> Here you are: https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20160809Japan

Thanks, but I don't think I have access to editing this page. Or at least I can't find the button for it...

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-59766

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76528] [Ruby trunk Feature#10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (28 preceding siblings ...)
  2016-07-22  9:52 ` [ruby-core:76524] " nerdinand
@ 2016-07-22 10:55 ` shyouhei
  2016-08-09  5:55 ` [ruby-core:76773] " matz
  30 siblings, 0 replies; 32+ messages in thread
From: shyouhei @ 2016-07-22 10:55 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Shyouhei Urabe.


Ferdinand Niedermann wrote:
> Thanks, but I don't think I have access to editing this page. Or at least I can't find the button for it...

Added a link to this issue.

----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-59771

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [ruby-core:76773] [Ruby trunk Feature#10594] Comparable#clamp
       [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
                   ` (29 preceding siblings ...)
  2016-07-22 10:55 ` [ruby-core:76528] " shyouhei
@ 2016-08-09  5:55 ` matz
  30 siblings, 0 replies; 32+ messages in thread
From: matz @ 2016-08-09  5:55 UTC (permalink / raw)
  To: ruby-core

Issue #10594 has been updated by Yukihiro Matsumoto.


I accept the idea of `#clamp` as `Comparable#clamp(min, max)`.
It would not accept ranges (for now).

Matz.


----------------------------------------
Feature #10594: Comparable#clamp
https://bugs.ruby-lang.org/issues/10594#change-59996

* Author: Chris Johnson
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
This is basically a re-opening of the feature request of issue#4573 (https://bugs.ruby-lang.org/issues/4574), which was closed due a naming debate.

It seems the standard naming for restricting a number to a specified range is indeed 'clamp'.  (1)(2)(3)

As such, can we use Yusuke Endoh's original patch with the naming adjustments?  If so, I can provide accordingly.

Cheers.

(1) http://www.rubydoc.info/github/epitron/epitools/Numeric:clamp
(2) http://stackoverflow.com/questions/12020787/is-there-a-limit-clamp-function-in-ruby
(3) https://developer.gnome.org/glib/stable/glib-Standard-Macros.html#CLAMP:CAPS


---Files--------------------------------
num_clamp.c (427 Bytes)
comparable-clamp.diff (2.52 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2016-08-09  5:21 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-10594.20141212214558@ruby-lang.org>
2014-12-12 21:45 ` [ruby-core:66814] [ruby-trunk - Bug #10594] [Open] Numeric#clamp findchris
2014-12-12 22:25 ` [ruby-core:66817] [ruby-trunk - Bug #10594] Numeric#clamp findchris
2015-06-27  9:55 ` [ruby-core:69754] [Ruby trunk " nerdinand
2015-06-29 10:38 ` [ruby-core:69771] " kosaki.motohiro
2015-06-29 19:01 ` [ruby-core:69776] " nerdinand
2015-06-30  2:18 ` [ruby-core:69783] " 0x0dea+redmine
2015-06-30  8:43 ` [ruby-core:69814] " hanmac
2015-06-30 10:26 ` [ruby-core:69815] " 0x0dea+redmine
2015-07-03  7:15 ` [ruby-core:69848] " nerdinand
2015-07-06 15:27 ` [ruby-core:69882] " nerdinand
2015-07-07 16:22 ` [ruby-core:69888] " 0x0dea+redmine
2015-07-08 13:00 ` [ruby-core:69901] " nerdinand
2015-07-08 16:08 ` [ruby-core:69902] " 0x0dea+redmine
2015-07-09  7:33 ` [ruby-core:69917] " nerdinand
2015-07-09 20:28 ` [ruby-core:69920] " nerdinand
2015-07-09 22:27 ` [ruby-core:69923] [Ruby trunk - Feature " nobu
2015-07-09 23:12 ` [ruby-core:69924] " 0x0dea+redmine
2015-07-10  5:32 ` [ruby-core:69929] " nerdinand
2015-07-10 15:39 ` [ruby-core:69941] " 0x0dea+redmine
2015-09-02 18:12 ` [ruby-core:70655] [Ruby trunk - Feature #10594] Comparable#clamp nerdinand
2015-09-14 20:13 ` [ruby-core:70804] " kosaki.motohiro
2015-09-15  5:24 ` [ruby-core:70810] " hanmac
2015-09-15  9:42 ` [ruby-core:70811] " eregontp
2015-09-15  9:48 ` [ruby-core:70812] " nerdinand
2015-09-15 10:06 ` [ruby-core:70813] " eregontp
2015-09-26 11:45 ` [ruby-core:70919] " nerdinand
2016-07-21 13:10 ` [ruby-core:76503] [Ruby trunk Feature#10594] Comparable#clamp nerdinand
2016-07-22  9:33   ` [ruby-core:76521] " Martin J. Dürst
2016-07-22  9:47 ` [ruby-core:76523] " shyouhei
2016-07-22  9:52 ` [ruby-core:76524] " nerdinand
2016-07-22 10:55 ` [ruby-core:76528] " shyouhei
2016-08-09  5:55 ` [ruby-core:76773] " matz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).