diff options
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 6af4a54..949fe98 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -42,6 +42,11 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
42 | public partial class LSL_Types | 42 | public partial class LSL_Types |
43 | { | 43 | { |
44 | // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain | 44 | // Types are kept is separate .dll to avoid having to add whatever .dll it is in it to script AppDomain |
45 | [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] | ||
46 | public unsafe static bool IsBadNumber(double d) | ||
47 | { | ||
48 | return (*(long*)(&d) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000; | ||
49 | } | ||
45 | 50 | ||
46 | [Serializable] | 51 | [Serializable] |
47 | public struct Vector3 | 52 | public struct Vector3 |
@@ -246,17 +251,17 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
246 | public static Vector3 operator /(Vector3 v, float f) | 251 | public static Vector3 operator /(Vector3 v, float f) |
247 | { | 252 | { |
248 | double r = v.x / f; | 253 | double r = v.x / f; |
249 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 254 | if (IsBadNumber(r)) |
250 | throw new ScriptException("Vector division by zero"); | 255 | throw new ScriptException("Vector division by zero"); |
251 | v.x = r; | 256 | v.x = r; |
252 | 257 | ||
253 | r = v.y / f; | 258 | r = v.y / f; |
254 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 259 | if (IsBadNumber(r)) |
255 | throw new ScriptException("Vector division by zero"); | 260 | throw new ScriptException("Vector division by zero"); |
256 | v.y = r; | 261 | v.y = r; |
257 | 262 | ||
258 | r = v.z / f; | 263 | r = v.z / f; |
259 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 264 | if (IsBadNumber(r)) |
260 | throw new ScriptException("Vector division by zero"); | 265 | throw new ScriptException("Vector division by zero"); |
261 | v.z = r; | 266 | v.z = r; |
262 | 267 | ||
@@ -280,17 +285,17 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
280 | public static Vector3 operator /(Vector3 v, double f) | 285 | public static Vector3 operator /(Vector3 v, double f) |
281 | { | 286 | { |
282 | double r = v.x / f; | 287 | double r = v.x / f; |
283 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 288 | if (IsBadNumber(r)) |
284 | throw new ScriptException("Vector division by zero"); | 289 | throw new ScriptException("Vector division by zero"); |
285 | v.x = r; | 290 | v.x = r; |
286 | 291 | ||
287 | r = v.y / f; | 292 | r = v.y / f; |
288 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 293 | if (IsBadNumber(r)) |
289 | throw new ScriptException("Vector division by zero"); | 294 | throw new ScriptException("Vector division by zero"); |
290 | v.y = r; | 295 | v.y = r; |
291 | 296 | ||
292 | r = v.z / f; | 297 | r = v.z / f; |
293 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 298 | if (IsBadNumber(r)) |
294 | throw new ScriptException("Vector division by zero"); | 299 | throw new ScriptException("Vector division by zero"); |
295 | v.z = r; | 300 | v.z = r; |
296 | 301 | ||
@@ -2292,7 +2297,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
2292 | static public LSLFloat operator /(LSLFloat f, int i) | 2297 | static public LSLFloat operator /(LSLFloat f, int i) |
2293 | { | 2298 | { |
2294 | double r = f.value / (double)i; | 2299 | double r = f.value / (double)i; |
2295 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 2300 | if (IsBadNumber(r)) |
2296 | throw new ScriptException("Float division by zero"); | 2301 | throw new ScriptException("Float division by zero"); |
2297 | return new LSLFloat(r); | 2302 | return new LSLFloat(r); |
2298 | } | 2303 | } |
@@ -2315,7 +2320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
2315 | static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs) | 2320 | static public LSLFloat operator /(LSLFloat lhs, LSLFloat rhs) |
2316 | { | 2321 | { |
2317 | double r = lhs.value / rhs.value; | 2322 | double r = lhs.value / rhs.value; |
2318 | if (double.IsNaN(r) || double.IsNegativeInfinity(r) || double.IsPositiveInfinity(r)) | 2323 | if (IsBadNumber(r)) |
2319 | throw new ScriptException("Float division by zero"); | 2324 | throw new ScriptException("Float division by zero"); |
2320 | return new LSLFloat(r); | 2325 | return new LSLFloat(r); |
2321 | } | 2326 | } |