Feature #11151
Numeric#positive? and Numeric#negative?
| ステータス: | Closed | ||
|---|---|---|---|
| 優先度: | Normal | ||
| 担当者: |
説明
We just added Interger#positive? and Interger#negative? to Active Support.
I was wondering if we could get that implemented in Ruby itself and searched if it was already requested before to Ruby code.
I found that it was requested in #5513, but rejected. Since they were requested with more methods, and I don't know Japanese enough to see if there are technical reasons, I thought to request just these two methods again.
The implementation would be something like:
def positive? self > 0 end def negative? self < 0 end
And one of its use case is filtering, like:
bunch_of_numbers.select(&:positive?)
If this feature is accepted I can work in a patch.
Related #5513
関係しているリビジョン
numeric.c: Numeric#positive? and Numeric#negative?
- numeric.c (num_positive_p, num_negative_p): add methods Numeric#positive? and Numeric#negative?. [Feature #11151]
- numeric.c (flo_positive_p, flo_negative_p): specialiazed functions for Float.
- complex.c (Init_Complex): Complex do not have positive? and negative? methods
numeric.c: Bignum 0 is not positive
- numeric.c (num_positive_p): should false on Bignum 0. http://twitter.com/rafaelfranca/status/600509783427391488 [Feature #11151]
numeric.c: return true
- numeric.c (num_positive_p): return true instead of Fixnum 0. [Feature #11151]
履歴
#1
Usaku NAKAMURA が6日前に更新
In #5113, matz said
- We can use
> 0and< 0for the purpose. - Complex is Numeric, but we cannot define positive? and negative? for it.
The latter is just appropriate comment, I think.
#2
Rafael França が6日前に更新
Right. Thank you for the explanation.
So maybe just to Fixnum and Float?
#3
Matthew Kerwin が6日前に更新
On 14/05/2015, rafaelmfranca@gmail.com rafaelmfranca@gmail.com wrote:
Issue #11151 has been updated by Rafael França.
Right. Thank you for the explanation.
So maybe just to
FixnumandFloat?
You probably mean Integer and Float. And possibly also Rational.
That, or add it to Numeric and have it raise in Complex.
--
Matthew Kerwin
http://matthew.kerwin.net.au/
#4
Rafael França が6日前に更新
You probably mean Integer and Float. And possibly also Rational.
Yeah.
For what I could see, probably we'll just need to publish two functions that we are already using internally. https://github.com/ruby/ruby/blob/d77f4934f8ede19d8a97d4bc748c92e9b8883133/numeric.c#L166 and https://github.com/ruby/ruby/blob/d77f4934f8ede19d8a97d4bc748c92e9b8883133/numeric.c#L182
#5
Yukihiro Matsumoto が6日前に更新
Realistic use-case is written. Accepted.
But it should recognize complex numbers (should raise exception).
Matz.
#6
Nobuyoshi Nakada が3日前に更新
- ステータス を Open から Closed に変更
Applied in changeset r50522.
numeric.c: Numeric#positive? and Numeric#negative?
- numeric.c (num_positive_p, num_negative_p): add methods Numeric#positive? and Numeric#negative?. [Feature #11151]
- numeric.c (flo_positive_p, flo_negative_p): specialiazed functions for Float.
- complex.c (Init_Complex): Complex do not have positive? and negative? methods