Add casts from integer to float. Fix issue 1822.

0.6.0-stable
Mike Mazur 2008-07-25 07:50:31 +00:00
parent 84cc69573b
commit 19ad7db5e1
3 changed files with 41 additions and 1 deletions

View File

@ -1454,6 +1454,11 @@ namespace OpenSim.Region.ScriptEngine.Common
return new LSLFloat(i);
}
static public implicit operator LSLFloat(LSLInteger i)
{
return new LSLFloat(i.value);
}
static public implicit operator LSLFloat(string s)
{
return new LSLFloat(double.Parse(s));

View File

@ -1509,6 +1509,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
return new LSLFloat(i);
}
static public implicit operator LSLFloat(LSLInteger i)
{
return new LSLFloat(i.value);
}
static public implicit operator LSLFloat(string s)
{
return new LSLFloat(double.Parse(s));

View File

@ -303,6 +303,36 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
}
}
/// <summary>
/// Tests LSLInteger is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestImplicitCastLSLIntegerToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (int number in m_intList)
{
testFloat = new LSL_Types.LSLInteger(number);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests LSLInteger is correctly cast explicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLIntegerToLSLFloat()
{
LSL_Types.LSLFloat testFloat;
foreach (int number in m_intList)
{
testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number);
Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
}
}
/// <summary>
/// Tests string is correctly cast implicitly to LSLFloat.
/// </summary>
@ -319,7 +349,7 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
}
/// <summary>
/// Tests string is correctly cast implicitly to LSLFloat.
/// Tests LSLString is correctly cast implicitly to LSLFloat.
/// </summary>
[Test]
public void TestExplicitCastLSLStringToLSLFloat()