From 19ad7db5e1ebcce8fc13995270b2ebe94f8a9a52 Mon Sep 17 00:00:00 2001
From: Mike Mazur
Date: Fri, 25 Jul 2008 07:50:31 +0000
Subject: Add casts from integer to float. Fix issue 1822.
---
OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 5 ++++
OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 5 ++++
.../ScriptEngine/Common/LSL_TypesTestLSLFloat.cs | 32 +++++++++++++++++++++-
3 files changed, 41 insertions(+), 1 deletion(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 0b28af0..7ac7a65 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -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));
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index f49d453..7eb5e77 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -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));
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
index aba87ac..2d553a7 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
@@ -304,6 +304,36 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
}
///
+ /// Tests LSLInteger is correctly cast implicitly to LSLFloat.
+ ///
+ [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));
+ }
+ }
+
+ ///
+ /// Tests LSLInteger is correctly cast explicitly to LSLFloat.
+ ///
+ [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));
+ }
+ }
+
+ ///
/// Tests string is correctly cast implicitly to LSLFloat.
///
[Test]
@@ -319,7 +349,7 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
}
///
- /// Tests string is correctly cast implicitly to LSLFloat.
+ /// Tests LSLString is correctly cast implicitly to LSLFloat.
///
[Test]
public void TestExplicitCastLSLStringToLSLFloat()
--
cgit v1.1