Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Sqrt completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paris committed Oct 23, 2010
1 parent 315dab2 commit dc48d10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion IronAHK/Site/docs/developing/status/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
["SplashTextOff", false, false, false, false, ""],
["SplashTextOn", false, false, false, false, ""],
["SplitPath", false, false, false, false, ""],
["Sqrt", false, false, false, false, ""],
["Sqrt", true, true, true, true, ""],
["StatusBarGetText", false, false, false, false, ""],
["StatusBarWait", false, false, false, false, ""],
["StringCaseSense", false, false, false, false, ""],
Expand Down
10 changes: 5 additions & 5 deletions Rusty/Core/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ public static double Sin(double n)
}

/// <summary>
/// Returns the square root of Number. The result is formatted as floating point. If Number is negative, the function yields a blank result (empty string).
/// Returns the square root of a specified number.
/// </summary>
/// <param name="Number"></param>
/// <returns></returns>
public static decimal Sqrt(decimal Number)
/// <param name="n">A number.</param>
/// <returns>The positive square root of <paramref name="n"/>.</returns>
public static double Sqrt(double n)
{
return (decimal)Math.Sqrt((double)Number);
return n < 0 ? 0 : Math.Sqrt(n);
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions Tests/Rusty/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,14 @@ public void Sin()
Assert.AreEqual(Math.Sin(v), Core.Sin(v));
}
}

[Test, Category("Math")]
public void Sqrt()
{
foreach (var n in new[] { 0, 1, 4, 9, 36, 12769, 8 })
Assert.AreEqual(Math.Sqrt(n), Core.Sqrt(n));

Assert.AreEqual(0, Core.Sqrt(-1));
}
}
}

0 comments on commit dc48d10

Please sign in to comment.