swig icon indicating copy to clipboard operation
swig copied to clipboard

Output typemap of int should be double

Open jaeandersson opened this issue 10 years ago • 3 comments

The MATLAB int64 type is quite rarely used in practise. If you call numel(zeros(3)) or shape(zeros(3)) you'll get a double and a vector of doubles respectively. Therefore, it makes sense to have a int in C/C++ map to double in MATLAB by default.

Since the IEEE floating point standard guarantees that integers up to a certain number are represented exactly, I see no problem with this.

jaeandersson avatar Dec 17 '14 17:12 jaeandersson

@KrisThielemans @ibell @tesch1 - any objections?

jaeandersson avatar Dec 17 '14 17:12 jaeandersson

it's one of those things that I hate in MATLAB. Nevertheless, I think your suggestion makes sense. how would this work when then call a function expecting an int as argument? I guess this already works now, but I wouldn't want to break something like

functionExpectingInt(functionReturningInt())

KrisThielemans avatar Dec 17 '14 18:12 KrisThielemans

This won't influence that. There would still be a "MATLAB double"-to-"C++ int" input typemap. We are talking about how to define the output typemap.

jaeandersson avatar Dec 17 '14 18:12 jaeandersson