Skip to content

Commit

Permalink
# 2
Browse files Browse the repository at this point in the history
  • Loading branch information
daliborjelinek committed Apr 23, 2017
1 parent 3bc767f commit c53c6c8
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 19 deletions.
Binary file added debugging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added profiling/Protokol.pdf
Binary file not shown.
Binary file added profiling/StandardDeviation 10.vsps
Binary file not shown.
Binary file added profiling/StandardDeviation 100.vsps
Binary file not shown.
Binary file added profiling/StandardDeviation 1000.vsps
Binary file not shown.
13 changes: 13 additions & 0 deletions src/Calculator/MathLib/Functions/Advanced/Factorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@

namespace MathLib.Functions.Advanced
{
/// <summary>
/// Represents factorial operation
/// </summary>
public class Factorial : IAdvancedMethod
{
/// <summary>
/// Calculate factorial by recursive method.
/// Max value for calculation is 69 to prevent stack od double overflow.
/// </summary>
/// <param name="operand">input value</param>
/// <returns>factorial of input value</returns>
public double Calculate(double operand)
{
if (operand.Equals(0))
{
return 1;
}
if (operand > 69)
{
return Double.NaN;
}

return operand * Calculate(operand - 1);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Calculator/MathLib/Functions/Advanced/Logarithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace MathLib.Functions.Advanced
{
/// <summary>
/// Represents logarithm operation.
/// </summary>
public class Logarithm : IAdvancedMethod
{
/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Calculator/MathLib/Functions/Advanced/Negation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

namespace MathLib.Functions.Advanced
{
/// <summary>
/// Represents negation of number
/// </summary>
public class Negation : IAdvancedMethod
{
/// <summary>
/// Number negation
/// </summary>
/// <param name="operand">value for negation</param>
/// <returns>-1* value</returns>
public double Calculate(double operand)
{
return operand = -1 * operand;
Expand Down
15 changes: 14 additions & 1 deletion src/Calculator/MathLib/Functions/Advanced/Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@

namespace MathLib.Functions.Advanced
{
/// <summary>
/// Provides methods for second or n-th power.
/// </summary>
public class Power : IAdvancedMethod
{
/// <summary>
/// calculate second power.
/// </summary>
/// <param name="operand">operand</param>
/// <returns>power of operand</returns>
public double Calculate(double operand)
{
return operand * operand;
}

/// <summary>
/// calculate n-th power of operand
/// </summary>
/// <param name="operand">operand</param>
/// <param name="exponent">exponent of power</param>
/// <returns></returns>
public double Calculate(double operand, double exponent)
{
return Math.Pow(operand, exponent);
Expand Down
15 changes: 14 additions & 1 deletion src/Calculator/MathLib/Functions/Advanced/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@

namespace MathLib.Functions.Advanced
{
/// <summary>
/// Provides methods for square or general root.
/// </summary>
public class Root : IAdvancedMethod
{
/// <summary>
/// Calculate square root of specified number.
/// </summary>
/// <param name="operand"></param>
/// <returns>square root of specified number</returns>
public double Calculate(double operand)
{
return Math.Sqrt(operand);
}

/// <summary>
/// Calculate n-th root of specified number.
/// </summary>
/// <param name="operand">root of this value will be computed</param>
/// <param name="exponent">n</param>
/// <returns></returns>
public double Calculate(double operand, int exponent)
{
return Math.Pow(operand, (1.0 / exponent));
Expand Down
28 changes: 24 additions & 4 deletions src/Calculator/MathLib/Functions/Basic/Addition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace MathLib.Functions.Basic
{
/// <summary>
/// Represents addition
/// </summary>
public class Addition : ISimpleMethod
{
private readonly List<double> operands;
Expand All @@ -12,7 +15,10 @@ public Addition()
{
operands = new List<double>();
}

///<summary>
/// sum all mambers of operands
///</summary>
/// <returns>result of sumation</returns>
public double Calculate()
{
if (operands.Count == 0)
Expand All @@ -22,17 +28,31 @@ public double Calculate()

return sum(operands);
}

/// <summary>
/// Add first and second operand.
/// </summary>
/// <param name="firstOperand">first operand of addition</param>
/// <param name="secondOperand">second operand of addition</param>
/// <returns>result of addition</returns>
public double Calculate(double firstOperand, double secondOperand)
{
return firstOperand + secondOperand;
}

/// <summary>
/// Add operand for addition.
/// After all operand will be added, you can sum them by calling
/// calculate mathod.
/// </summary>
/// <param name="operand">value</param>
public void AddOperand(double operand)
{
operands.Add(operand);
}

/// <summary>
/// sum all mambers of operands
/// </summary>
/// <param name="operands">values for addition</param>
/// <returns></returns>
private double sum(List<double> operands)
{
double result = 0;
Expand Down
27 changes: 24 additions & 3 deletions src/Calculator/MathLib/Functions/Basic/Division.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace MathLib.Functions.Basic
{
/// <summary>
/// Represents division
/// </summary>
public class Division : ISimpleMethod
{
private List<double> operands;
Expand All @@ -13,6 +16,10 @@ public Division()
{
operands = new List<double>();
}
/// <summary>
/// divide all mambers of operands
/// </summary>
/// <returns>result of division</returns>
public double Calculate()
{
if (!operands.Any())
Expand All @@ -39,7 +46,12 @@ public double Calculate()

return result;
}

/// <summary>
/// Divide first operad by second operand.
/// </summary>
/// <param name="firstOperand">first operand of division</param>
/// <param name="secondOperand">second operand of division</param>
/// <returns>result of division</returns>
public double Calculate(double firstOperand, double secondOperand)
{
if (isDoubleZero(secondOperand))
Expand All @@ -49,12 +61,21 @@ public double Calculate(double firstOperand, double secondOperand)

return firstOperand / secondOperand;
}

/// <summary>
/// Add operand for division.
/// After all operand will be added, you can divide them by calling
/// calculate mathod.
/// </summary>
/// <param name="operand">value</param>
public void AddOperand(double operand)
{
operands.Add(operand);
}

/// <summary>
/// Determinate if given number is zero.
/// </summary>
/// <param name="num">value</param>
/// <returns></returns>
private bool isDoubleZero(double num)
{
return (Math.Abs(num) < double.Epsilon);
Expand Down
26 changes: 20 additions & 6 deletions src/Calculator/MathLib/Functions/Basic/Multiplication.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using MathLib.Interfaces;
using MathLib.Interfaces;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -8,12 +7,17 @@ namespace MathLib.Functions.Basic
public class Multiplication : ISimpleMethod
{
private List<double> operands;

/// <summary>
/// Represents multiplication
/// </summary>
public Multiplication()
{
operands = new List<double>();
}

/// <summary>
/// multiply all mambers of operands
/// </summary>
/// <returns>result of multipication</returns>
public double Calculate()
{
if (!operands.Any())
Expand All @@ -30,12 +34,22 @@ public double Calculate()

return result;
}

/// <summary>
/// Multiplay first and second operand.
/// </summary>
/// <param name="firstOperand">first operand of multiplication</param>
/// <param name="secondOperand">second operand of multiplication</param>
/// <returns>result of multipication</returns>
public double Calculate(double firstOperand, double secondOperand)
{
return firstOperand * secondOperand;
}

/// <summary>
/// Add operand for multipication.
/// After all operand will be added, you can multiply them by calling
/// calculate mathod.
/// </summary>
/// <param name="operand">value</param>
public void AddOperand(double operand)
{
operands.Add(operand);
Expand Down
24 changes: 20 additions & 4 deletions src/Calculator/MathLib/Functions/Basic/Substraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
using MathLib.Exception;
using MathLib.Interfaces;


namespace MathLib.Functions.Basic
{
/// <summary>
/// Represents substraction.
/// </summary>
public class Substraction : ISimpleMethod
{
private readonly List<double> operands;

public Substraction()
{
operands = new List<double>();
}

/// <summary>
/// Substract all mambers of operands
/// </summary>
/// <returns>result of substraction</returns>
public double Calculate()
{
if (!operands.Any())
Expand All @@ -30,12 +36,22 @@ public double Calculate()

return result;
}

/// <summary>
/// Substract secondOperand from firstOperand
/// </summary>
/// <param name="firstOperand">first operand of substraction</param>
/// <param name="secondOperand">second operand of substraction</param>
/// <returns>result of substraction</returns>
public double Calculate(double firstOperand, double secondOperand)
{
return firstOperand - secondOperand;
}

/// <summary>
/// Add operand for substraction.
/// After all operand will be added, you can substract them by calling
/// calculate mathod.
/// </summary>
/// <param name="operand">value</param>
public void AddOperand(double operand)
{
operands.Add(operand);
Expand Down

0 comments on commit c53c6c8

Please sign in to comment.