Skip to content

Conversation

genya0407
Copy link

I defined four arithmetic operations (+, -, *, /) of Nyaplot::Series.

These operators work like this:

series = Nyaplot::Series.new(:series, [10,20])
another_series = Nyaplot::Series.new(:another_series, [30, 40])

scalar = 10

# addition
series + another_series # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[40, 60], @label=:series>
series + scalar # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[20, 30], @label=:series>

# subtraction
series - another_series # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[-20, -20], @label=:series>
series - scalar # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[0, 10], @label=:series>

# multiplication
series * another_series # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[300, 800], @label=:series>
series * scalar # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[100, 200], @label=:series>

# division
series / another_series # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[0, 0], @label=:series>
series / scalar # => <Nyaplot::Series:0x00561200fa5fb0 @arr=[1, 2], @label=:series>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant