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/