Skip to content

python ints becomes double in matlab land #165

@sdvillal

Description

@sdvillal

Just food for thought. The following little snippet shows the (potential) problem:

from pymatbridge import Octave
o = Octave()
o.start()
o.set_variable('x', 12)
o.run_code('class(x)')

Being more catholic than the pope, class(x) in matlab land should probably be "int{32|64}", however it is "double". In theory and in my experience casting all numbers to floats in matlab land is a good default, that matches better what matlab expect (the literal "2" in matlab is a double, so it is str2num('2')). But perhaps there should be a way to move ints as ints, just in case someone ever find code that does expect ints (I have seen it, but do not ask me where). I think oct2py approach is the way to go.

An alternative is always to set the variable, run 'x=int64(x)' and then run the call. But that is not as convenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions