diff --git a/sources/BaseRealm/API/Math/MathAPI.uc b/sources/BaseRealm/API/Math/MathAPI.uc new file mode 100644 index 0000000..bc948b7 --- /dev/null +++ b/sources/BaseRealm/API/Math/MathAPI.uc @@ -0,0 +1,75 @@ +/** + * API that provides a collection of non-built in math methods used in Acedia. + * Copyright 2022 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class MathAPI extends AcediaObject; + +/** + * For storing result of integer division. + * + * If we divide `number` by `divisor`, then + * `number = divisor * quotient + remainder` + */ +struct IntegerDivisionResult +{ + var int quotient; + var int remainder; +}; + +/** + * Computes remainder of the integer division of `number` by `divisor`. + * + * This method is necessary as a replacement for `%` module operator, since it + * is an operation on `float`s in UnrealScript and does not have appropriate + * value range to work with big integer values. + * + * @see `IntegerDivision()` method if you need both quotient and remainder. + * + * @param number Number that we are dividing. + * @param divisor Number we are dividing by. + * @return Remainder of the integer division. + */ +public function int Remainder(int number, int divisor) +{ + local int quotient; + + quotient = number / divisor; + return (number - quotient * divisor); +} + +/** + * Computes quotient and remainder of the integer division of `number` by + * `divisor`. + * + * @see `IntegerDivision()` method if you only need remainder. + * @param number Number that we are dividing. + * @param divisor Number we are dividing by. + * @return `struct` with quotient and remainder of the integer division. + */ +public function IntegerDivisionResult IntegerDivision(int number, int divisor) +{ + local IntegerDivisionResult result; + + result.quotient = number / divisor; + result.remainder = (number - result.quotient * divisor); + return result; +} + +defaultproperties +{ +} \ No newline at end of file diff --git a/sources/BaseRealm/Global.uc b/sources/BaseRealm/Global.uc index 238c021..f26f92f 100644 --- a/sources/BaseRealm/Global.uc +++ b/sources/BaseRealm/Global.uc @@ -27,6 +27,7 @@ var protected Global myself; var public RefAPI ref; var public BoxAPI box; +var public MathAPI math; var public LoggerAPI logger; var public CollectionsAPI collections; var public AliasesAPI alias; @@ -65,6 +66,7 @@ protected function Initialize() ref = RefAPI(memory.Allocate(class'RefAPI')); box = BoxAPI(memory.Allocate(class'BoxAPI')); text = TextAPI(memory.Allocate(class'TextAPI')); + math = MathAPI(memory.Allocate(class'MathAPI')); collections = CollectionsAPI(memory.Allocate(class'CollectionsAPI')); logger = LoggerAPI(memory.Allocate(class'LoggerAPI')); color = ColorAPI(memory.Allocate(class'ColorAPI'));