For more infomation about this bug, visit <https://www.fmtc.be/bugzilla/orocos/show_bug.cgi?id=516>
Summary: [Scripting]No conversions available from int -> double -
>float etc.
Product: RTT
Version: rtt-trunk
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Real-Time Toolkit (RTT)
AssignedTo: orocos-dev at lists [dot] mech [dot] kuleuven [dot] be
ReportedBy: peter.soetens at fmtc [dot] be
CC: orocos-dev at lists [dot] mech [dot] kuleuven [dot] be
Estimated Hours: 0.0
There is sometimes a lot of confusion when a scripting methodi takes a float
argument and the user writes plain '3.0' (a double), which is rejected by the
parser.
In the RTT, it is possible to define constructor functions like:
var double d = double(4) // convert int to double
For these 1-to-1 conversions, the scripting engine could look up the
constructor table of double() itself and see if it is possible to construct a
double from an int. That would allow you to write:
var double d = 4 // automatic construction of a double from an int
A lot of newcomers have been bitten by this, and the constructor infrastructure
is already in place. Only the automatic lookup needs to be done at the right
places, which is a small patch.
We could have the following conversion table:
Automatic:
float ->[double]
double ->[float]
int ->[double, float]
char ->[int, uint]
Automatic, with a warning:
float -> [int, uint]
double-> [int, uint]
int -> [uint]
uint -> [int]
Any other suggestions ?
To supress the warnings, we could require the user to write C++ style casts:
var int i = int(3.333)
for example.
Peter