1

私は高校 1 年生で、時間の余裕があるので、一般的に使用される関数の動作を示すプログラムを作成することが有益であると判断しました。大なり演算子と小なり演算子には正確には何が入るのだろうといつも思っていたので、自分でそれらを定義することに着手しました。私が遭遇した唯一の障害は、大なり演算子または小なり演算子を使用せずに、値が負または正であることを主張する方法です。これまでのところ、次のようなものがあります。

a = 34
b = 42
c = a - b
puts "A is Greater than B" while is_positive?(c)

私がどのように定義するかについて誰かアイデアがありますis_positive?(c)か?

4

2 に答える 2

2
  1. This question should not be tagged ruby but mathematics.
  2. Then you absolutely do need the equality operator.
  3. If you want to restrict yourself to just the + and - operators, you have no other way of deciding whether a or b is greater, than to count up from 0 and see which value you hit first (which of course is tested using the equality operator)
于 2012-09-21T14:14:56.700 に答える
0

等しい場合、2番目より大きい場合、最初の引数<=>を返す演算子は小さいということですか?または、引数が0未満の場合、0の場合、または0より大きい場合に返される符号関数を意味しますか?-101-101

于 2012-09-21T14:02:13.997 に答える