diff options
author | S.H <[email protected]> | 2021-02-09 13:29:42 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-08 20:29:42 -0800 |
commit | fad7908a5de4ab08367914d53780ff6518d5f552 (patch) | |
tree | e60ba6f472bd046a0f7259c0b92420427c2ca104 /numeric.rb | |
parent | 97cf290063ab940d08819cd96cbcca0ef6d50e4c (diff) |
Improve performance Float#positive? and Float#negative? [Feature #17614] (#4160)
Notes
Notes:
Merged-By: k0kubun <[email protected]>
Diffstat (limited to 'numeric.rb')
-rw-r--r-- | numeric.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/numeric.rb b/numeric.rb index fbddaa9f6d..0746a83820 100644 --- a/numeric.rb +++ b/numeric.rb @@ -204,4 +204,26 @@ class Float Primitive.attr! 'inline' Primitive.cexpr! 'FLOAT_ZERO_P(self) ? Qtrue : Qfalse' end + + # + # call-seq: + # float.positive? -> true or false + # + # Returns +true+ if +float+ is greater than 0. + # + def positive? + Primitive.attr! 'inline' + Primitive.cexpr! 'RFLOAT_VALUE(self) > 0.0 ? Qtrue : Qfalse' + end + + # + # call-seq: + # float.negative? -> true or false + # + # Returns +true+ if +float+ is less than 0. + # + def negative? + Primitive.attr! 'inline' + Primitive.cexpr! 'RFLOAT_VALUE(self) < 0.0 ? Qtrue : Qfalse' + end end |