summaryrefslogtreecommitdiff
path: root/numeric.rb
diff options
context:
space:
mode:
authorS.H <gamelinks007@gmail.com>2021-02-20 04:11:19 +0900
committerGitHub <noreply@github.com>2021-02-19 11:11:19 -0800
commitefd19badf43f4f1f24d5aec8a28e94a6e1e47b5b (patch)
treed0f1b01082418d2434d5380cbb427bbccf095b6c /numeric.rb
parent837e77e0202e96060498794ff97a097e5440d148 (diff)
Improve performance some Numeric methods [Feature #17632] (#4190)
Notes
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'numeric.rb')
-rw-r--r--numeric.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/numeric.rb b/numeric.rb
index 0746a83820..0c191c01c0 100644
--- a/numeric.rb
+++ b/numeric.rb
@@ -1,3 +1,49 @@
+class Numeric
+ #
+ # call-seq:
+ # num.real? -> true or false
+ #
+ # Returns +true+ if +num+ is a real number (i.e. not Complex).
+ #
+ def real?
+ return true
+ end
+
+ #
+ # call-seq:
+ # num.integer? -> true or false
+ #
+ # Returns +true+ if +num+ is an Integer.
+ #
+ # 1.0.integer? #=> false
+ # 1.integer? #=> true
+ #
+ def integer?
+ return false
+ end
+
+ #
+ # call-seq:
+ # num.finite? -> true or false
+ #
+ # Returns +true+ if +num+ is a finite number, otherwise returns +false+.
+ #
+ def finite?
+ return true
+ end
+
+ #
+ # call-seq:
+ # num.infinite? -> -1, 1, or nil
+ #
+ # Returns +nil+, -1, or 1 depending on whether the value is
+ # finite, <code>-Infinity</code>, or <code>+Infinity</code>.
+ #
+ def infinite?
+ return nil
+ end
+end
+
class Integer
# call-seq:
# -int -> integer