-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #48 implemented odd and even functions
- Loading branch information
Showing
5 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/************************************************************************************************* | ||
Required Notice: Copyright (C) EPPlus Software AB. | ||
This software is licensed under PolyForm Noncommercial License 1.0.0 | ||
and may only be used for noncommercial purposes | ||
https://polyformproject.org/licenses/noncommercial/1.0.0/ | ||
A commercial license to use this software can be purchased at https://epplussoftware.com | ||
************************************************************************************************* | ||
Date Author Change | ||
************************************************************************************************* | ||
01/27/2020 EPPlus Software AB Initial release EPPlus 5 | ||
*************************************************************************************************/ | ||
using OfficeOpenXml.FormulaParsing.ExpressionGraph; | ||
using OfficeOpenXml.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Math | ||
{ | ||
internal class Even : ExcelFunction | ||
{ | ||
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context) | ||
{ | ||
ValidateArguments(arguments, 1); | ||
var arg = arguments.ElementAt(0).Value; | ||
if (!IsNumeric(arg)) return new CompileResult(eErrorType.Value); | ||
var number = ConvertUtil.GetValueDouble(arg); | ||
if (number % 1 != 0) | ||
{ | ||
if (number >= 0) | ||
{ | ||
number = number - (number % 1) + 1; | ||
} | ||
else | ||
{ | ||
number = number - (number % 1) - 1; | ||
} | ||
} | ||
var intNumber = Convert.ToInt32(number); | ||
if (intNumber % 2 == 1) | ||
{ | ||
intNumber = intNumber >= 0 ? intNumber + 1 : intNumber - 1; | ||
} | ||
return CreateResult(intNumber, DataType.Integer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/************************************************************************************************* | ||
Required Notice: Copyright (C) EPPlus Software AB. | ||
This software is licensed under PolyForm Noncommercial License 1.0.0 | ||
and may only be used for noncommercial purposes | ||
https://polyformproject.org/licenses/noncommercial/1.0.0/ | ||
A commercial license to use this software can be purchased at https://epplussoftware.com | ||
************************************************************************************************* | ||
Date Author Change | ||
************************************************************************************************* | ||
01/27/2020 EPPlus Software AB Initial release EPPlus 5 | ||
*************************************************************************************************/ | ||
using OfficeOpenXml.FormulaParsing.ExpressionGraph; | ||
using OfficeOpenXml.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Math | ||
{ | ||
internal class Odd : ExcelFunction | ||
{ | ||
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context) | ||
{ | ||
ValidateArguments(arguments, 1); | ||
var arg = arguments.ElementAt(0).Value; | ||
if (!IsNumeric(arg)) return new CompileResult(eErrorType.Value); | ||
var number = ConvertUtil.GetValueDouble(arg); | ||
if(number % 1 > 0) | ||
{ | ||
if (number >= 0) | ||
{ | ||
number = number - (number % 1) + 1; | ||
} | ||
else | ||
{ | ||
number = number - (number % 1) - 1; | ||
} | ||
} | ||
var intNumber = Convert.ToInt32(number); | ||
if(intNumber % 2 == 0) | ||
{ | ||
intNumber = intNumber >= 0 ? intNumber + 1 : intNumber - 1; | ||
} | ||
return CreateResult(intNumber, DataType.Integer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters