nyaplot icon indicating copy to clipboard operation
nyaplot copied to clipboard

Four arithmetic operations

Open genya0407 opened this issue 9 years ago • 0 comments

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>

genya0407 avatar Jun 19 '16 14:06 genya0407