diff options
author | Charles Krinke | 2008-07-16 14:30:22 +0000 |
---|---|---|
committer | Charles Krinke | 2008-07-16 14:30:22 +0000 |
commit | 0106f967161b2fa0dbf131a56e9c5498d1b16270 (patch) | |
tree | 62e0cbad5193521f7a2549bb782207306ca9e92c /OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |
parent | squashing warnings critters (diff) | |
download | opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.zip opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.gz opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.bz2 opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.xz |
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.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 3dfa711..c630c27 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |||
@@ -1276,11 +1276,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1276 | return new LSLInteger(int.Parse(s)); | 1276 | return new LSLInteger(int.Parse(s)); |
1277 | } | 1277 | } |
1278 | 1278 | ||
1279 | static public implicit operator LSLInteger(double d) | 1279 | static public implicit operator LSLInteger(uint u) |
1280 | { | 1280 | { |
1281 | return new LSLInteger(d); | 1281 | return new LSLInteger(u); |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | static public bool operator ==(LSLInteger i1, LSLInteger i2) | 1284 | static public bool operator ==(LSLInteger i1, LSLInteger i2) |
1285 | { | 1285 | { |
1286 | bool ret = i1.value == i2.value; | 1286 | bool ret = i1.value == i2.value; |
@@ -1312,6 +1312,31 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1312 | { | 1312 | { |
1313 | return new LSLInteger(i1.value / i2); | 1313 | return new LSLInteger(i1.value / i2); |
1314 | } | 1314 | } |
1315 | |||
1316 | static public LSLFloat operator +(LSLInteger i1, double f) | ||
1317 | { | ||
1318 | return new LSLFloat((double)i1.value + f); | ||
1319 | } | ||
1320 | |||
1321 | static public LSLFloat operator -(LSLInteger i1, double f) | ||
1322 | { | ||
1323 | return new LSLFloat((double)i1.value - f); | ||
1324 | } | ||
1325 | |||
1326 | static public LSLFloat operator *(LSLInteger i1, double f) | ||
1327 | { | ||
1328 | return new LSLFloat((double)i1.value * f); | ||
1329 | } | ||
1330 | |||
1331 | static public LSLFloat operator /(LSLInteger i1, double f) | ||
1332 | { | ||
1333 | return new LSLFloat((double)i1.value / f); | ||
1334 | } | ||
1335 | |||
1336 | static public LSLInteger operator -(LSLInteger i) | ||
1337 | { | ||
1338 | return new LSLInteger(-i.value); | ||
1339 | } | ||
1315 | 1340 | ||
1316 | public override bool Equals(Object o) | 1341 | public override bool Equals(Object o) |
1317 | { | 1342 | { |
@@ -1392,16 +1417,6 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1392 | 1417 | ||
1393 | #region Operators | 1418 | #region Operators |
1394 | 1419 | ||
1395 | static public implicit operator int(LSLFloat f) | ||
1396 | { | ||
1397 | return (int)f.value; | ||
1398 | } | ||
1399 | |||
1400 | static public implicit operator uint(LSLFloat f) | ||
1401 | { | ||
1402 | return (uint) Math.Abs(f.value); | ||
1403 | } | ||
1404 | |||
1405 | static public implicit operator Boolean(LSLFloat f) | 1420 | static public implicit operator Boolean(LSLFloat f) |
1406 | { | 1421 | { |
1407 | if (f.value == 0.0) | 1422 | if (f.value == 0.0) |
@@ -1450,17 +1465,37 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1450 | f.value--; | 1465 | f.value--; |
1451 | return f; | 1466 | return f; |
1452 | } | 1467 | } |
1468 | |||
1469 | static public LSLFloat operator +(LSLFloat f, int i) | ||
1470 | { | ||
1471 | return new LSLFloat(f.value + (double)i); | ||
1472 | } | ||
1473 | |||
1474 | static public LSLFloat operator -(LSLFloat f, int i) | ||
1475 | { | ||
1476 | return new LSLFloat(f.value - (double)i); | ||
1477 | } | ||
1478 | |||
1479 | static public LSLFloat operator *(LSLFloat f, int i) | ||
1480 | { | ||
1481 | return new LSLFloat(f.value * (double)i); | ||
1482 | } | ||
1483 | |||
1484 | static public LSLFloat operator /(LSLFloat f, int i) | ||
1485 | { | ||
1486 | return new LSLFloat(f.value / (double)i); | ||
1487 | } | ||
1488 | |||
1489 | static public LSLFloat operator -(LSLFloat f) | ||
1490 | { | ||
1491 | return new LSLFloat(-f.value); | ||
1492 | } | ||
1453 | 1493 | ||
1454 | static public implicit operator System.Double(LSLFloat f) | 1494 | static public implicit operator System.Double(LSLFloat f) |
1455 | { | 1495 | { |
1456 | return f.value; | 1496 | return f.value; |
1457 | } | 1497 | } |
1458 | 1498 | ||
1459 | //static public implicit operator System.Int32(LSLFloat f) | ||
1460 | //{ | ||
1461 | // return (int)f.value; | ||
1462 | //} | ||
1463 | |||
1464 | #endregion | 1499 | #endregion |
1465 | 1500 | ||
1466 | #region Overriders | 1501 | #region Overriders |