simplify last code a bit

0.9.1.0-post-fixes
UbitUmarov 2019-10-17 22:40:54 +01:00
parent 53c39bf25f
commit d6abf2a2fe
1 changed files with 13 additions and 8 deletions

View File

@ -42,6 +42,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
public partial class LSL_Types public partial class LSL_Types
{ {
// Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public unsafe static bool IsBadNumber(double d)
{
return (*(long*)(&d) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000;
}
[Serializable] [Serializable]
public struct Vector3 public struct Vector3
@ -246,17 +251,17 @@ namespace OpenSim.Region.ScriptEngine.Shared
public static Vector3 operator /(Vector3 v, float f) public static Vector3 operator /(Vector3 v, float f)
{ {
double r = v.x / f; double r = v.x / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.x = r; v.x = r;
r = v.y / f; r = v.y / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.y = r; v.y = r;
r = v.z / f; r = v.z / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.z = r; v.z = r;
@ -280,17 +285,17 @@ namespace OpenSim.Region.ScriptEngine.Shared
public static Vector3 operator /(Vector3 v, double f) public static Vector3 operator /(Vector3 v, double f)
{ {
double r = v.x / f; double r = v.x / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.x = r; v.x = r;
r = v.y / f; r = v.y / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.y = r; v.y = r;
r = v.z / f; r = v.z / f;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Vector division by zero"); throw new ScriptException("Vector division by zero");
v.z = r; v.z = r;
@ -2292,7 +2297,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
static public LSLFloat operator /(LSLFloat f, int i) static public LSLFloat operator /(LSLFloat f, int i)
{ {
double r = f.value / (double)i; double r = f.value / (double)i;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Float division by zero"); throw new ScriptException("Float division by zero");
return new LSLFloat(r); return new LSLFloat(r);
} }
@ -2315,7 +2320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs) static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs)
{ {
double r = lhs.value / rhs.value; double r = lhs.value / rhs.value;
if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) if (IsBadNumber(r))
throw new ScriptException("Float division by zero"); throw new ScriptException("Float division by zero");
return new LSLFloat(r); return new LSLFloat(r);
} }