Skip to content

Commit

Permalink
Update Rational
Browse files Browse the repository at this point in the history
  • Loading branch information
sampersand committed Feb 28, 2024
1 parent b85cd82 commit 531ee8f
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 231 deletions.
65 changes: 65 additions & 0 deletions core/numeric.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,71 @@
# * #step: Invokes the given block with the sequence of specified numbers.
#
class Numeric
interface _Coerce[Other, EquivOther, EquivSelf]
def coerce: (Other rhs) -> [EquivOther, EquivSelf]
end

interface _Add[Other, Return]
def +: (Other other) -> Return
end

interface _Subtract[Other, Return]
def -: (Other other) -> Return
end

interface _Multiply[Other, Return]
def *: (Other other) -> Return
end

interface _Divide[Other, Return]
def /: (Other other) -> Return
end

interface _Modulo[Other, Return]
def %: (Other other) -> Return
end

interface _Power[Other, Return]
def **: (Other other) -> Return
end

interface _Divmod[Other, Whole, Part]
def divmod: (Other other) -> [Whole, Part]
end

interface _Compare[Other]
def <=>: (Other other) -> (-1 | 0 | 1)
| (untyped other) -> (-1 | 0 | 1)?
end

interface _GreaterThan[Other, Return]
def >: (Other other) -> Return
end

interface _GreaterOrEqualTo[Other, Return]
def >=: (Other other) -> Return
end

interface _LessThan[Other, Return]
def <: (Other other) -> Return
end

interface _LessOrEqualTo[Other, Return]
def <=: (Other other) -> Return
end

type round_direction = :up | :down | :even | 'up' | 'down' | 'even' | string | nil

# The interface for the sole optional argument to subclasses of `Numeric`'s `rationalize` function.
interface _Eps
# Get the absolute value of this variable.
#
# Technically, the return value needs to be usable within `<subclass>#-` and `<subclass>#+`, but
# it's a bit specific; if you have a usecase for this please create a PR
def abs: () -> Numeric
end

public
include Comparable

public
Expand Down
Loading

0 comments on commit 531ee8f

Please sign in to comment.