[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #53231] Range type should implement division o
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #53231] Range type should implement division operator for scalars |
Date: |
Mon, 26 Feb 2018 20:43:28 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 |
URL:
<http://savannah.gnu.org/bugs/?53231>
Summary: Range type should implement division operator for
scalars
Project: GNU Octave
Submitted by: rik5
Submitted on: Mon 26 Feb 2018 05:43:27 PM PST
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Feature Request
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: dev
Operating System: Any
_______________________________________________________
Details:
While fixing a bug in hist.m I accidentally discovered that division by a
scalar is not implement for Range values.
For example:
octave:2> x = 1:10
x =
1 2 3 4 5 6 7 8 9 10
octave:3> typeinfo (x)
ans = range
octave:4> y = 3 * x
y =
3 6 9 12 15 18 21 24 27 30
octave:5> typeinfo (y)
ans = range
octave:6> z = x / 1
z =
1 2 3 4 5 6 7 8 9 10
octave:7> typeinfo (z)
ans = matrix
This is rather surprising and likely to trip up users.
I was able to work around the limitation by using multiplication, but the code
looks awkward.
new_range = old_range * (1/scalar)
The issue is confirmed by looking at liboctave/array/Range.h where the list of
operators implemented does not include division.
friend OCTAVE_API Range operator - (const Range& r);
friend OCTAVE_API Range operator + (double x, const Range& r);
friend OCTAVE_API Range operator + (const Range& r, double x);
friend OCTAVE_API Range operator - (double x, const Range& r);
friend OCTAVE_API Range operator - (const Range& r, double x);
friend OCTAVE_API Range operator * (double x, const Range& r);
friend OCTAVE_API Range operator * (const Range& r, double x);
This seems like a simple enough fix to introduce function prototypes for
division by a scalar in Range.h and copy/modify the existing multiplication
code in Range.cc to work for division.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?53231>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #53231] Range type should implement division operator for scalars,
Rik <=