diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 32 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs | 12 |
2 files changed, 29 insertions, 15 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 65b1b5c..da40995 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -1363,7 +1363,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1363 | 1363 | ||
1364 | public static explicit operator double(LSLString s) | 1364 | public static explicit operator double(LSLString s) |
1365 | { | 1365 | { |
1366 | return Convert.ToDouble(s.m_string); | 1366 | return new LSLFloat(s).value; |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | public static explicit operator LSLInteger(LSLString s) | 1369 | public static explicit operator LSLInteger(LSLString s) |
@@ -1401,7 +1401,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1401 | 1401 | ||
1402 | public static implicit operator LSLFloat(LSLString s) | 1402 | public static implicit operator LSLFloat(LSLString s) |
1403 | { | 1403 | { |
1404 | return new LSLFloat(Convert.ToDouble(s.m_string)); | 1404 | return new LSLFloat(s); |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | public static implicit operator list(LSLString s) | 1407 | public static implicit operator list(LSLString s) |
@@ -1737,7 +1737,21 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1737 | 1737 | ||
1738 | public LSLFloat(string s) | 1738 | public LSLFloat(string s) |
1739 | { | 1739 | { |
1740 | this.value = double.Parse(s); | 1740 | Regex r = new Regex("^ *(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?"); |
1741 | Match m = r.Match(s); | ||
1742 | string v = m.Groups[0].Value; | ||
1743 | |||
1744 | v = v.Trim(); | ||
1745 | |||
1746 | if (v == String.Empty || v == null) | ||
1747 | v = "0.0"; | ||
1748 | else | ||
1749 | if (!v.Contains(".") && !v.ToLower().Contains("e")) | ||
1750 | v = v + ".0"; | ||
1751 | else | ||
1752 | if (v.EndsWith(".")) | ||
1753 | v = v + "0"; | ||
1754 | this.value = double.Parse(v, System.Globalization.NumberStyles.Float); | ||
1741 | } | 1755 | } |
1742 | 1756 | ||
1743 | #endregion | 1757 | #endregion |
@@ -1783,17 +1797,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1783 | 1797 | ||
1784 | static public explicit operator LSLFloat(string s) | 1798 | static public explicit operator LSLFloat(string s) |
1785 | { | 1799 | { |
1786 | Regex r = new Regex("^[ ]*-?[0-9]*\\.?[0-9]*[eE]?-?[0-9]*"); | 1800 | return new LSLFloat(s); |
1787 | Match m = r.Match(s); | ||
1788 | string v = m.Groups[0].Value; | ||
1789 | |||
1790 | while (v.Length > 0 && v.Substring(0, 1) == " ") | ||
1791 | v = v.Substring(1); | ||
1792 | |||
1793 | if (v == String.Empty) | ||
1794 | v = "0"; | ||
1795 | |||
1796 | return new LSLFloat(double.Parse(v)); | ||
1797 | } | 1801 | } |
1798 | 1802 | ||
1799 | public static implicit operator list(LSLFloat f) | 1803 | public static implicit operator list(LSLFloat f) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs index 272d06c..d40a951 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLFloat.cs | |||
@@ -145,7 +145,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
145 | m_stringDoubleSet.Add("-548.5", -548.5); | 145 | m_stringDoubleSet.Add("-548.5", -548.5); |
146 | m_stringDoubleSet.Add("-2.0005", -2.0005); | 146 | m_stringDoubleSet.Add("-2.0005", -2.0005); |
147 | m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); | 147 | m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); |
148 | 148 | // some oddball combinations and exponents | |
149 | m_stringDoubleSet.Add("", 0.0); | ||
150 | m_stringDoubleSet.Add("1.0E+5", 100000.0); | ||
151 | m_stringDoubleSet.Add("-1.0E+5", -100000.0); | ||
152 | m_stringDoubleSet.Add("-1E+5", -100000.0); | ||
153 | m_stringDoubleSet.Add("-1.E+5", -100000.0); | ||
154 | m_stringDoubleSet.Add("-1.E+5.0", -100000.0); | ||
155 | m_stringDoubleSet.Add("1ef", 1.0); | ||
156 | m_stringDoubleSet.Add("e10", 0.0); | ||
157 | m_stringDoubleSet.Add("1.e0.0", 1.0); | ||
158 | |||
149 | m_doubleStringSet = new Dictionary<double, string>(); | 159 | m_doubleStringSet = new Dictionary<double, string>(); |
150 | m_doubleStringSet.Add(2.0, "2.000000"); | 160 | m_doubleStringSet.Add(2.0, "2.000000"); |
151 | m_doubleStringSet.Add(-2.0, "-2.000000"); | 161 | m_doubleStringSet.Add(-2.0, "-2.000000"); |