[#69616] [Ruby trunk - Feature #11258] add 'x' mode character for O_EXCL — cremno@...
Issue #11258 has been updated by cremno phobia.
3 messages
2015/06/16
[#69643] [Ruby trunk - Misc #11276] [RFC] compile.c: convert to use ccan/list — normalperson@...
Issue #11276 has been updated by Eric Wong.
3 messages
2015/06/17
[#69751] [Ruby trunk - Bug #11001] 2.2.1 Segmentation fault in reserve_stack() function. — kubo@...
Issue #11001 has been updated by Takehiro Kubo.
3 messages
2015/06/27
[ruby-core:69815] [Ruby trunk - Bug #10594] Numeric#clamp
From:
0x0dea+redmine@...
Date:
2015-06-30 10:26:32 UTC
List:
ruby-core #69815
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/