Wolfgang,
The problem seems to be the fact that the literals are stored as REAL8 and not as FLOAT. The exception occurs when casting the OBJECT containing a REAL8 to a FLOAT.
When you compile with /vo14 the program runs fine.
The Vulcan compiler has the same problem b.t.w.
I will see what I can do to fix this.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Wolfgang,
I looked at this and it is not so easy, especially since the Vulcan runtime has problems in this area.
The safest solution for now is to add a call to the function below to convert from Object to FLOAT
FUNCTION Object2Float(oValue AS OBJECT) AS FLOAT
LOCAL typ := oValue:GetType() AS System.Type
IF typ == typeof(FLOAT)
RETURN (FLOAT) oValue
ENDIF
LOCAL tc := System.Type.GetTypeCode(typ) AS TypeCode
SWITCH tc
CASE System.TypeCode.SByte
RETURN (FLOAT) (System.SByte) oValue
CASE System.TypeCode.Byte
RETURN (FLOAT) (System.Byte) oValue
CASE System.TypeCode.Double
RETURN (FLOAT) (System.Double) oValue
CASE System.TypeCode.Single
RETURN (FLOAT) (System.Single) oValue
CASE System.TypeCode.UInt16
RETURN (FLOAT) (System.UInt16) oValue
CASE System.TypeCode.UInt32
RETURN (FLOAT) (System.UInt32) oValue
CASE System.TypeCode.UInt64
RETURN (FLOAT) (System.UInt64) oValue
CASE System.TypeCode.Int16
RETURN (FLOAT) (System.Int16) oValue
CASE System.TypeCode.Int32
RETURN (FLOAT) (System.Int32) oValue
CASE System.TypeCode.Int64
RETURN (FLOAT) (System.Int64) oValue
CASE System.TypeCode.Decimal
RETURN (FLOAT) (System.Decimal) oValue
OTHERWISE
THROW InvalidCastException{"Cannot convert from type "+typ:FullName+" to FLOAT"}
END SWITCH
XSharp Development Team
The Netherlands
robert@xsharp.eu
Will this function be added to the runtime?
I don't know how many people used something like this in Vulcan, but in new X# code I'm using "object" instead of "usual" when I need variable datatypes for flexibility.
I had found this problem when I worked on the migration of my report engine, and for now the only way to solve it was a Round() call.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it