https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-04-13T21:42:30ZRuby Issue Tracking SystemRuby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164862011-04-13T21:42:30Zmrkn (Kenta Murata)muraken@gmail.com
<ul></ul><p>=begin<br>
I like Numeric#limit and/or Numeric#clip. I think "limit" is more mathematical, and "clip" is more easy to understand its functionality from its name. So I believe it is acceptable that the both names are provided.</p>
<p>In contrast, I feel that Numeric#within returns boolean so I don't want to accept it.</p>
<p>=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164872011-04-13T21:49:54Zsakuro (Sakuro OZAWA)
<ul></ul><p>=begin<br>
I prefer this sort of method be an instance method of Range.</p>
<p>You propse Range#bound, but 'bound' as a verb is similar to jump/leap (and its intransitive), isn't it? Do you mean past particle form of 'bind' ?</p>
<p>Anyway I propose Range#clamp as its name.</p>
<p>Examples:</p>
<ul>
<li>((<Java 3D|URL:<a href="http://download.oracle.com/docs/cd/E17802_01/j2se/javase/technologies/desktop/java3d/forDevelopers/J3D_1_3_API/j3dapi/javax/vecmath/Tuple3d.html#clamp(double" class="external">http://download.oracle.com/docs/cd/E17802_01/j2se/javase/technologies/desktop/java3d/forDevelopers/J3D_1_3_API/j3dapi/javax/vecmath/Tuple3d.html#clamp(double</a>, double)>))</li>
<li>((<DirectX|URL:<a href="http://msdn.microsoft.com/en-us/library/bb204824(VS.85).aspx%3E" class="external">http://msdn.microsoft.com/en-us/library/bb204824(VS.85).aspx></a>))</li>
</ul>
<p>=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164882011-04-13T21:52:41Zsakuro (Sakuro OZAWA)
<ul></ul><p>=begin<br>
For Japanese: clamp は漫画家じゃなくて万力/締め具のことです:)</p>
<p>=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164902011-04-13T22:23:06Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hello,</p>
<p>2011/4/13 <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>I prefer this sort of method be an instance method of Range.</p>
</blockquote>
<p>I can accept Range method, but why?<br>
I think that the subject of this feature is the limited Numeric.</p>
<blockquote>
<p>You propse Range#bound, Â but 'bound' as a verb is similar to jump/leap (and its intransitive), isn't it? Do you mean past particle form of 'bind' ?</p>
</blockquote>
<p>It resembles:</p>
<p><a href="http://en.wikipedia.org/wiki/Upper_and_lower_bounds" class="external">http://en.wikipedia.org/wiki/Upper_and_lower_bounds</a></p>
<p>But I did not think the name so deeply.<br>
Another name is welcome.</p>
<blockquote>
<p>Anyway I propose Range#clamp as its name.</p>
<p>Examples:</p>
<ul>
<li>((<Java 3D|URL:<a href="http://download.oracle.com/docs/cd/E17802_01/j2se/javase/technologies/desktop/java3d/forDevelopers/J3D_1_3_API/j3dapi/javax/vecmath/Tuple3d.html#clamp(double" class="external">http://download.oracle.com/docs/cd/E17802_01/j2se/javase/technologies/desktop/java3d/forDevelopers/J3D_1_3_API/j3dapi/javax/vecmath/Tuple3d.html#clamp(double</a>, double)>))</li>
<li>((<DirectX|URL:<a href="http://msdn.microsoft.com/en-us/library/bb204824(VS.85).aspx%3E" class="external">http://msdn.microsoft.com/en-us/library/bb204824(VS.85).aspx></a>))</li>
</ul>
</blockquote>
<p>Thanks for the information.<br>
The name would be good if it is really conventional.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164912011-04-13T23:31:42ZEregon (Benoit Daloze)
<ul></ul><p>=begin<br>
Hello,<br>
Kenta Murata wrote:</p>
<blockquote>
<p>I like Numeric#limit and/or Numeric#clip. I think "limit" is more mathematical, and "clip" is more easy to understand its functionality from its name. So I believe it is acceptable that the both names are provided.</p>
</blockquote>
<p>I agree, I find #limit and #clip more explicit than the others of the list (and #clamp) ...</p>
<blockquote>
<p>In contrast, I feel that Numeric#within returns boolean so I don't want to accept it.</p>
</blockquote>
<p>... but I prefer #within, the fact it does not have a final '?' is enough for me to not expect a boolean.</p>
<p>And that is the only name which do not make me think twice to know what it does.</p>
<p>Yusuke Endoh wrote:</p>
<blockquote>
<p>Some Japanese committers agree with this idea</p>
</blockquote>
<p>It's nice to also see this discussion on ruby-core.</p>
<blockquote>
<p>I can accept Range method, but why?<br>
I think that the subject of this feature is the limited Numeric.</p>
</blockquote>
<p>A Range method does not make much sense to me either (and it creates a likely useless Range).</p>
<p>So I prefer Numeric#within(lower_bound, upper_bound).<br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164922011-04-14T00:23:06Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hello,</p>
<p>2011/4/13 <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<blockquote>
<p>I like Numeric#limit and/or Numeric#clip. Â I think "limit" is more mathematical, and "clip" is more easy to understand its functionality from its name. Â So I believe it is acceptable that the both names are provided.</p>
</blockquote>
<p>I agree, I find #limit and #clip more explicit than the others of the list (and #clamp) ...</p>
</blockquote>
<p>Thank you, but I'm going to like clamp :-)<br>
"clamp" seems not only the term of computer graphics, but also<br>
the term of mathematics. Kenta found the following article:</p>
<p><a href="http://en.wikipedia.org/wiki/Saturation_arithmetic" class="external">http://en.wikipedia.org/wiki/Saturation_arithmetic</a></p>
<blockquote>
<p>If the result of an operation is greater than the maximum it is set ("clamped") to the maximum, while if it is below the minimum it is clamped to the minimum.</p>
</blockquote>
<blockquote>
<p>Yusuke Endoh wrote:</p>
<blockquote>
<p>Some Japanese committers agree with this idea</p>
</blockquote>
<p>It's nice to also see this discussion on ruby-core.</p>
</blockquote>
<p>Note that I have not gotten matz's approval yet :-)</p>
<blockquote>
<blockquote>
<p>I can accept Range method, but why?<br>
I think that the subject of this feature is the limited Numeric.</p>
</blockquote>
</blockquote>
<p>I forgot to tell another issue of Range method.<br>
It is difficult to define the behavior of "(2...5).bound(6)".<br>
My previous patch lets the code raise an ArgumentError, but<br>
I'm not sure if it is right.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164942011-04-14T12:19:40Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul></ul><p>=begin<br>
Gack!<br>
simple paste made RD format error. ;-)<br>
Let's retry.</p>
<hr>
<p>Btw, Linux kernel has following macro.</p>
<pre><code>/**
* clamp - return a value clamped to a given range with strict typechecking
* @val: current value
* @min: minimum allowable value
* @max: maximum allowable value
*
* This macro does strict typechecking of min/max to make sure they are of the
* same type as val. See the unnecessary pointer comparisons.
*/
#define clamp(val, min, max) ({ \
typeof(val) __val = (val); \
typeof(min) __min = (min); \
typeof(max) __max = (max); \
(void) (&__val == &__min); \
(void) (&__val == &__max); \
__val = __val < __min ? __min: __val; \
__val > __max ? __max: __val; })
</code></pre>
<p>=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164952011-04-14T12:30:05Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul></ul><p>=begin<br>
More off topic. Here is very similar discussion by phthonia.</p>
<p><a href="http://stackoverflow.com/questions/4092528/how-to-clamp-an-integer-to-some-range-in-python" class="external">http://stackoverflow.com/questions/4092528/how-to-clamp-an-integer-to-some-range-in-python</a><br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=164962011-04-14T19:49:07Zaprescott (Adam Prescott)
<ul></ul><p>=begin<br>
I think Numeric#within is perhaps less intuitive than something like Range#bound or Range#trim. It feels more natural to have it be a method on Range. I like Range#clamp but it might not be so obvious that restricts the argument to within the range; then again, (2..5).restrict(6) might lack some aesthetic appeal.<br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=165002011-04-15T07:23:33Zcjheath (Clifford Heath)clifford.heath@gmail.com
<ul></ul><p>=begin<br>
On 14/04/2011, at 9:40 PM, Nikolai Weibull wrote:</p>
<blockquote>
<p>On Thu, Apr 14, 2011 at 12:49, <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>I think Numeric#within is perhaps less intuitive than something<br>
like Range#bound or Range#trim. It feels more natural to have it be<br>
a method on Range. I like Range#clamp but it might not be so<br>
obvious that restricts the argument to within the range; then<br>
again, (2..5).restrict(6) might lack some aesthetic appeal.</p>
</blockquote>
<p>In my mind, Numeric#clamp is the right choice:</p>
</blockquote>
<p>clamp is also the term used in electronics for this function.</p>
<p>Clifford Heath.<br>
=end</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=190202011-07-10T15:15:27Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Target version</strong> changed from <i>1.9.3</i> to <i>2.0.0</i></li></ul><p>It's too late for 1.9.3.</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=257952012-04-10T18:43:31Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>I reject this propsal, since the name discussion diverged.<br>
If someone really wants this feature (and believes #clamp is the right name), resubmit the feature request.</p>
<p>Matz.</p> Ruby master - Feature #4574: Numeric#withinhttps://redmine.ruby-lang.org/issues/4574?journal_id=504012014-12-15T05:39:13Zfindchris (Chris Johnson)findchris@gmail.com
<ul></ul><p>Resubmitted as a new feature request here:<br>
<a href="https://bugs.ruby-lang.org/issues/10594" class="external">https://bugs.ruby-lang.org/issues/10594</a></p>