Mantis#1755. Thank you kindly, Matth for a patch that solves:
When using math operators +,-,*,/ in an LSL script with an LSLFloat and an integer literal the wrong result is returned. This patch adds operators to the LSLFloat type to handle this case.0.6.0-stable
parent
1e39bfb036
commit
0106f96716
|
@ -1276,9 +1276,9 @@ namespace OpenSim.Region.ScriptEngine.Common
|
||||||
return new LSLInteger(int.Parse(s));
|
return new LSLInteger(int.Parse(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
static public implicit operator LSLInteger(double d)
|
static public implicit operator LSLInteger(uint u)
|
||||||
{
|
{
|
||||||
return new LSLInteger(d);
|
return new LSLInteger(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool operator ==(LSLInteger i1, LSLInteger i2)
|
static public bool operator ==(LSLInteger i1, LSLInteger i2)
|
||||||
|
@ -1313,6 +1313,31 @@ namespace OpenSim.Region.ScriptEngine.Common
|
||||||
return new LSLInteger(i1.value / i2);
|
return new LSLInteger(i1.value / i2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator +(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value + f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value - f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator *(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value * f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator /(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value / f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLInteger operator -(LSLInteger i)
|
||||||
|
{
|
||||||
|
return new LSLInteger(-i.value);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Equals(Object o)
|
public override bool Equals(Object o)
|
||||||
{
|
{
|
||||||
if (!(o is LSLInteger))
|
if (!(o is LSLInteger))
|
||||||
|
@ -1392,16 +1417,6 @@ namespace OpenSim.Region.ScriptEngine.Common
|
||||||
|
|
||||||
#region Operators
|
#region Operators
|
||||||
|
|
||||||
static public implicit operator int(LSLFloat f)
|
|
||||||
{
|
|
||||||
return (int)f.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public implicit operator uint(LSLFloat f)
|
|
||||||
{
|
|
||||||
return (uint) Math.Abs(f.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static public implicit operator Boolean(LSLFloat f)
|
static public implicit operator Boolean(LSLFloat f)
|
||||||
{
|
{
|
||||||
if (f.value == 0.0)
|
if (f.value == 0.0)
|
||||||
|
@ -1451,16 +1466,36 @@ namespace OpenSim.Region.ScriptEngine.Common
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator +(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value + (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value - (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator *(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value * (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator /(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value / (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLFloat f)
|
||||||
|
{
|
||||||
|
return new LSLFloat(-f.value);
|
||||||
|
}
|
||||||
|
|
||||||
static public implicit operator System.Double(LSLFloat f)
|
static public implicit operator System.Double(LSLFloat f)
|
||||||
{
|
{
|
||||||
return f.value;
|
return f.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//static public implicit operator System.Int32(LSLFloat f)
|
|
||||||
//{
|
|
||||||
// return (int)f.value;
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Overriders
|
#region Overriders
|
||||||
|
|
|
@ -1304,9 +1304,9 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
return new LSLInteger(int.Parse(s));
|
return new LSLInteger(int.Parse(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
static public implicit operator LSLInteger(double d)
|
static public implicit operator LSLInteger(uint u)
|
||||||
{
|
{
|
||||||
return new LSLInteger(d);
|
return new LSLInteger(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool operator ==(LSLInteger i1, LSLInteger i2)
|
static public bool operator ==(LSLInteger i1, LSLInteger i2)
|
||||||
|
@ -1341,9 +1341,34 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
return new LSLInteger(i1.value / i2);
|
return new LSLInteger(i1.value / i2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator +(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value + f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value - f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator *(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value * f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator /(LSLInteger i1, double f)
|
||||||
|
{
|
||||||
|
return new LSLFloat((double)i1.value / f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLInteger operator -(LSLInteger i)
|
||||||
|
{
|
||||||
|
return new LSLInteger(-i.value);
|
||||||
|
}
|
||||||
|
|
||||||
static public LSLInteger operator &(LSLInteger i1, LSLInteger i2)
|
static public LSLInteger operator &(LSLInteger i1, LSLInteger i2)
|
||||||
{
|
{
|
||||||
int ret = i1.value & i2.value;
|
int ret = i1.value & i2.value;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1447,16 +1472,6 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
|
|
||||||
#region Operators
|
#region Operators
|
||||||
|
|
||||||
static public implicit operator int(LSLFloat f)
|
|
||||||
{
|
|
||||||
return (int)f.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public implicit operator uint(LSLFloat f)
|
|
||||||
{
|
|
||||||
return (uint) Math.Abs(f.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static public implicit operator Boolean(LSLFloat f)
|
static public implicit operator Boolean(LSLFloat f)
|
||||||
{
|
{
|
||||||
if (f.value == 0.0)
|
if (f.value == 0.0)
|
||||||
|
@ -1519,6 +1534,31 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator +(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value + (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value - (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator *(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value * (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator /(LSLFloat f, int i)
|
||||||
|
{
|
||||||
|
return new LSLFloat(f.value / (double)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public LSLFloat operator -(LSLFloat f)
|
||||||
|
{
|
||||||
|
return new LSLFloat(-f.value);
|
||||||
|
}
|
||||||
|
|
||||||
static public implicit operator System.Double(LSLFloat f)
|
static public implicit operator System.Double(LSLFloat f)
|
||||||
{
|
{
|
||||||
return f.value;
|
return f.value;
|
||||||
|
|
|
@ -133,7 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
|
||||||
|
|
||||||
foreach (KeyValuePair<double, int> number in numberSet)
|
foreach (KeyValuePair<double, int> number in numberSet)
|
||||||
{
|
{
|
||||||
testNumber = new LSL_Types.LSLFloat(number.Key);
|
testNumber = (int)(new LSL_Types.LSLFloat(number.Key));
|
||||||
Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value);
|
Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
|
||||||
|
|
||||||
foreach (KeyValuePair<double, int> number in numberSet)
|
foreach (KeyValuePair<double, int> number in numberSet)
|
||||||
{
|
{
|
||||||
testNumber = new LSL_Types.LSLFloat(number.Key);
|
testNumber = (uint)(new LSL_Types.LSLFloat(number.Key));
|
||||||
Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value);
|
Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue