From 6267db0c4c5cc36ffce709ce0798689630b32e04 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Sun, 27 Jul 2008 05:42:47 +0000 Subject: [PATCH] Implement LSLFloat {+,-,*,/} LSLFloat operations. Fix issues 1532, 1701, 1824 & 1832. --- .../Region/ScriptEngine/Common/LSL_Types.cs | 20 ++++++ .../Region/ScriptEngine/Shared/LSL_Types.cs | 20 ++++++ .../Common/LSL_TypesTestLSLFloat.cs | 63 +++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 7ac7a651ff..d5211f5107 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -1511,6 +1511,26 @@ namespace OpenSim.Region.ScriptEngine.Common return new LSLFloat(f.value / (double)i); } + static public LSLFloat operator +(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value + rhs.value); + } + + static public LSLFloat operator -(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value - rhs.value); + } + + static public LSLFloat operator *(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value * rhs.value); + } + + static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value / rhs.value); + } + static public LSLFloat operator -(LSLFloat f) { return new LSLFloat(-f.value); diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 7eb5e77af7..77bb426999 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -1579,6 +1579,26 @@ namespace OpenSim.Region.ScriptEngine.Shared return new LSLFloat(f.value / (double)i); } + static public LSLFloat operator +(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value + rhs.value); + } + + static public LSLFloat operator -(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value - rhs.value); + } + + static public LSLFloat operator *(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value * rhs.value); + } + + static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs) + { + return new LSLFloat(lhs.value / rhs.value); + } + static public LSLFloat operator -(LSLFloat f) { return new LSLFloat(-f.value); diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs index 2d553a7ac4..2a2603186b 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs @@ -496,5 +496,68 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests Assert.AreEqual(number.Value, testFloat.ToString()); } } + + /// + /// Tests addition of two LSLFloats. + /// + [Test] + public void TestAddTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests subtraction of two LSLFloats. + /// + [Test] + public void TestSubtractTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests multiplication of two LSLFloats. + /// + [Test] + public void TestMultiplyTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests division of two LSLFloats. + /// + [Test] + public void TestDivideTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + if (number.Value != 0.0) // Let's avoid divide by zero. + { + testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); + } + } + } } }