Xengine: more on division by Zero

0.9.1.0-post-fixes
UbitUmarov 2019-10-18 15:02:32 +01:00
parent f09a18a7a8
commit 9d698bcffb
1 changed files with 70 additions and 22 deletions

View File

@ -2020,31 +2020,43 @@ namespace OpenSim.Region.ScriptEngine.Shared
{ {
return new LSLInteger(i1.value / i2); return new LSLInteger(i1.value / i2);
} }
catch(DivideByZeroException) catch (DivideByZeroException)
{ {
throw new ScriptException("Integer division by Zero"); throw new ScriptException("Integer division by Zero");
} }
} }
// static public LSLFloat operator +(LSLInteger i1, double f) static public LSLInteger operator %(LSLInteger i1, int i2)
// { {
// return new LSLFloat((double)i1.value + f); try
// } {
// return new LSLInteger(i1.value % i2);
// static public LSLFloat operator -(LSLInteger i1, double f) }
// { catch (DivideByZeroException)
// return new LSLFloat((double)i1.value - f); {
// } throw new ScriptException("Integer division by Zero");
// }
// static public LSLFloat operator *(LSLInteger i1, double f) }
// {
// return new LSLFloat((double)i1.value * f); // static public LSLFloat operator +(LSLInteger i1, double f)
// } // {
// // return new LSLFloat((double)i1.value + f);
// static public LSLFloat operator /(LSLInteger i1, double f) // }
// { //
// return new LSLFloat((double)i1.value / f); // static public LSLFloat operator -(LSLInteger i1, double f)
// } // {
// return new LSLFloat((double)i1.value - f);
// }
//
// static public LSLFloat operator *(LSLInteger i1, double f)
// {
// return new LSLFloat((double)i1.value * f);
// }
//
// static public LSLFloat operator /(LSLInteger i1, double f)
// {
// return new LSLFloat((double)i1.value / f);
// }
static public LSLInteger operator -(LSLInteger i) static public LSLInteger operator -(LSLInteger i)
{ {
@ -2084,11 +2096,31 @@ namespace OpenSim.Region.ScriptEngine.Shared
return ret; return ret;
} }
static public LSLInteger operator /(LSLInteger i1, LSLInteger i2)
{
try
{
int ret = i1.value / i2.value;
return ret;
}
catch (DivideByZeroException)
{
throw new ScriptException("Integer division by Zero");
}
}
static public LSLInteger operator %(LSLInteger i1, LSLInteger i2) static public LSLInteger operator %(LSLInteger i1, LSLInteger i2)
{
try
{ {
int ret = i1.value % i2.value; int ret = i1.value % i2.value;
return ret; return ret;
} }
catch (DivideByZeroException)
{
throw new ScriptException("Integer division by Zero");
}
}
static public LSLInteger operator |(LSLInteger i1, LSLInteger i2) static public LSLInteger operator |(LSLInteger i1, LSLInteger i2)
{ {
@ -2302,6 +2334,14 @@ namespace OpenSim.Region.ScriptEngine.Shared
return new LSLFloat(r); return new LSLFloat(r);
} }
static public LSLFloat operator %(LSLFloat f, int i)
{
double r = f.value % (double)i;
if (IsBadNumber(r))
throw new ScriptException("Float division by zero");
return new LSLFloat(r);
}
static public LSLFloat operator +(LSLFloat lhs, LSLFloat rhs) static public LSLFloat operator +(LSLFloat lhs, LSLFloat rhs)
{ {
return new LSLFloat(lhs.value + rhs.value); return new LSLFloat(lhs.value + rhs.value);
@ -2325,6 +2365,14 @@ namespace OpenSim.Region.ScriptEngine.Shared
return new LSLFloat(r); return new LSLFloat(r);
} }
static public LSLFloat operator %(LSLFloat lhs, LSLFloat rhs)
{
double r = lhs.value % rhs.value;
if (IsBadNumber(r))
throw new ScriptException("Float division by zero");
return new LSLFloat(r);
}
static public LSLFloat operator -(LSLFloat f) static public LSLFloat operator -(LSLFloat f)
{ {
return new LSLFloat(-f.value); return new LSLFloat(-f.value);