Skip to content

Commit

Permalink
Merge pull request sebastienros#2 from djMax/mm_updateupstream
Browse files Browse the repository at this point in the history
Update from main Jint repo
  • Loading branch information
djMax committed Nov 28, 2015
2 parents 01ff539 + fb1640c commit 2007627
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Jint/Runtime/TypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,17 @@ public static double ToInteger(JsValue o)
/// <returns></returns>
public static int ToInt32(JsValue o)
{
return (int)(uint)ToNumber(o);
double num = ToNumber(o);
if (double.IsNaN(num) || double.IsNegativeInfinity(num) || double.IsPositiveInfinity(num) || num == 0)
{
return 0;
}
long posIntWithMod = ((long)num) % 0x100000000;
if (posIntWithMod >= 0x100000000 - 1)
{
return (int)(posIntWithMod - 0x100000000);
}
return (int)posIntWithMod;
}

/// <summary>
Expand All @@ -230,7 +240,12 @@ public static int ToInt32(JsValue o)
/// <returns></returns>
public static uint ToUint32(JsValue o)
{
return (uint)ToNumber(o);
double num = ToNumber(o);
if (double.IsNaN(num) || double.IsNegativeInfinity(num) || double.IsPositiveInfinity(num) || num == 0)
{
return 0;
}
return (uint) (((long)num)%0x100000000);
}

/// <summary>
Expand Down

0 comments on commit 2007627

Please sign in to comment.