Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Arithmetic operators with System.Decimal
Browse files Browse the repository at this point in the history
git-tfs-id: [http://falcon:8080/tfs/Projects]$/Phalanger/Main;C3673
  • Loading branch information
jakubmisek committed Nov 8, 2012
1 parent 1f66757 commit e96fd47
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Source/Core/Reflection/Objects.cs
Expand Up @@ -1727,7 +1727,7 @@ private object InvokeToString(out GetMemberResult lookupResult)
/// <param name="intValue">This instance converted to integer.</param>
/// <param name="longValue">Not applicable.</param>
/// <returns><see cref="Convert.NumberInfo.Integer"/>.</returns>
public Convert.NumberInfo ToNumber(out int intValue, out long longValue, out double doubleValue)
public virtual Convert.NumberInfo ToNumber(out int intValue, out long longValue, out double doubleValue)
{
intValue = 1;
doubleValue = 1.0;
Expand Down Expand Up @@ -3230,16 +3230,32 @@ public override PhpBytes ToPhpBytes()
}

/// <summary>
/// Overrides basic double cast of CLR object in case of <see cref="decimal"/> type.
/// Overrides default double cast of CLR object in case of <see cref="decimal"/> type.
/// </summary>
public override double ToDouble()
{
if (typeof(T) == typeof(decimal))
return (double)(decimal)(object)this.realValue;
return (double)(decimal)this.RealObject;

return base.ToDouble();
}

/// <summary>
/// Overrides default number conversion of CLR object in of <see cref="decimal"/> type.
/// </summary>
public override Convert.NumberInfo ToNumber(out int intValue, out long longValue, out double doubleValue)
{
if (typeof(T) == typeof(decimal))
{
doubleValue = (double)(decimal)this.RealObject;
intValue = unchecked((int)doubleValue);
longValue = unchecked((long)doubleValue);
return Convert.NumberInfo.Double | Convert.NumberInfo.IsNumber;
}

return base.ToNumber(out intValue, out longValue, out doubleValue);
}

#endregion

#region Clone
Expand Down

0 comments on commit e96fd47

Please sign in to comment.