Skip to content

Commit

Permalink
Various cleanup tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanRL committed Oct 27, 2022
1 parent 8454cd7 commit 6efbbc6
Show file tree
Hide file tree
Showing 33 changed files with 90 additions and 156 deletions.
3 changes: 2 additions & 1 deletion .codeclimate.yml
Expand Up @@ -51,4 +51,5 @@ exclude_patterns:
- ".*.yml"
- ".gitignore"
- "LICENSE"
- "COPYRIGHT"
- "COPYRIGHT"
- "parallel.sh"
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,8 @@ vendor/
composer.lock
build
.phpunit.result.cache
site
site
tools/
.php-cs-fixer.cache
.phive/
phive.phar.asc
Empty file modified parallel.sh 100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/Samsara/Fermat/Complex/Types/ComplexNumber.php
Expand Up @@ -243,7 +243,7 @@ public function isLessThan($value): bool|null

/**
* @param $value
* @return bool
* @return bool|null
* @throws IncompatibleObjectState
*/
public function isLessThanOrEqualTo($value): bool|null
Expand Down
Expand Up @@ -3,15 +3,13 @@
namespace Samsara\Fermat\Complex\Types\Traits;

use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Exceptions\UsageError\OptionalExit;
use Samsara\Fermat\Complex\Types\ComplexNumber;
use Samsara\Fermat\Complex\Values\ImmutableComplexNumber;
use Samsara\Fermat\Complex\Values\MutableComplexNumber;
use Samsara\Fermat\Coordinates\Values\PolarCoordinate;
use Samsara\Fermat\Core\Numbers;
use Samsara\Fermat\Core\Provider\ArithmeticProvider;
use Samsara\Fermat\Core\Types\Traits\NumberNormalizationTrait;
use Samsara\Fermat\Core\Values\ImmutableDecimal;
use Samsara\Fermat\Core\Values\ImmutableFraction;
Expand Down
2 changes: 2 additions & 0 deletions src/Samsara/Fermat/Core/Provider/ArithmeticProvider.php
Expand Up @@ -115,6 +115,7 @@ private static function performBaseArithmetic(
$number1 = new Decimal($left, $decimalScale);
$number2 = new Decimal($right, $decimalScale);

/** @noinspection PhpUncoveredEnumCasesInspection */
$result = match ($operation) {
CalcOperation::Addition => $number1->add($number2)->toFixed($scale, false, Decimal::ROUND_TRUNCATE),
CalcOperation::Subtraction => $number1->sub($number2)->toFixed($scale, false, Decimal::ROUND_TRUNCATE),
Expand All @@ -124,6 +125,7 @@ private static function performBaseArithmetic(
CalcOperation::Compare => $number1->compareTo($number2)
};
} else {
/** @noinspection PhpUncoveredEnumCasesInspection */
$result = match ($operation) {
CalcOperation::Addition => \bcadd($left, $right, $scale),
CalcOperation::Subtraction => \bcsub($left, $right, $scale),
Expand Down
2 changes: 0 additions & 2 deletions src/Samsara/Fermat/Core/Provider/ConstantProvider.php
Expand Up @@ -4,7 +4,6 @@
namespace Samsara\Fermat\Core\Provider;


use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Core\Enums\CalcMode;
use Samsara\Fermat\Core\Enums\NumberBase;
Expand All @@ -30,7 +29,6 @@ class ConstantProvider
* @param int $digits
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
public static function makePi(int $digits): string
{
Expand Down
45 changes: 11 additions & 34 deletions src/Samsara/Fermat/Core/Provider/RandomProvider.php
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Random\RandomException;
use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Exceptions\UsageError\OptionalExit;
use Samsara\Fermat\Core\Enums\NumberBase;
Expand All @@ -23,17 +24,19 @@ class RandomProvider
{

/**
* @param int|string|Decimal $min
* @param int|string|Decimal $max
* @param int|float|string|Decimal $min
* @param int|float|string|Decimal $max
* @param RandomMode $mode
* @param int|null $seed
* @return ImmutableDecimal
* @throws RandomException
* @throws IntegrityConstraint
* @throws OptionalExit
* @throws IncompatibleObjectState
*/
public static function randomInt(
int|string|Decimal $min,
int|string|Decimal $max,
int|float|string|Decimal $min,
int|float|string|Decimal $max,
RandomMode $mode = RandomMode::Entropy,
?int $seed = null
): ImmutableDecimal
Expand Down Expand Up @@ -106,24 +109,9 @@ public static function randomInt(
*/
/** @noinspection PhpUnhandledExceptionInspection */
$range = $maxDecimal->subtract($minDecimal);
// /** @noinspection PhpUnhandledExceptionInspection */
// $bitsNeeded = $range->ln(2)->divide(Numbers::makeNaturalLog2(2), 2)->floor()->add(1);
// $bytesNeeded = $bitsNeeded->divide(8, 2)->ceil();

do {
try {
// /**
// * Returns random bytes based on sources of entropy within the system.
// *
// * For documentation on these sources please see:
// *
// * https://www.php.net/manual/en/function.random-bytes.php
// */
// $entropyBytes = $randomizer->getBytes($bytesNeeded->asInt());
// $baseTwoBytes = '';
// for($i = 0; $i < strlen($entropyBytes); $i++){
// $baseTwoBytes .= decbin( ord( $entropyBytes[$i] ) );
// }
$randomValue = '';

for ($i = 0; $i < $max->numberOfIntDigits();$i++) {
Expand All @@ -140,17 +128,6 @@ public static function randomInt(
);
}

// /**
// * Since the number of digits is equal to the bits needed, but random_bytes() only
// * returns in chunks of 8 bits (duh, bytes), we can substr() from the right to
// * select only the correct number of digits by multiplying the number of bits
// * needed by -1 and using that as the starting point.
// */
// $randomValue = BaseConversionProvider::convertStringToBaseTen(
// substr($baseTwoBytes, $bitsNeeded->multiply(-1)->asInt()),
// NumberBase::Two
// );

/**
* @var ImmutableDecimal $num
*/
Expand Down Expand Up @@ -202,16 +179,16 @@ public static function randomDecimal(
}

/**
* @param int|string|Decimal $min
* @param int|string|Decimal $max
* @param int|float|string|Decimal $min
* @param int|float|string|Decimal $max
* @param int $scale
* @param RandomMode $mode
* @return ImmutableDecimal
* @throws RandomException
*/
public static function randomReal(
int|string|Decimal $min,
int|string|Decimal $max,
int|float|string|Decimal $min,
int|float|string|Decimal $max,
int $scale,
RandomMode $mode = RandomMode::Entropy
): ImmutableDecimal
Expand Down
4 changes: 0 additions & 4 deletions src/Samsara/Fermat/Core/Provider/SequenceProvider.php
Expand Up @@ -3,7 +3,6 @@
namespace Samsara\Fermat\Core\Provider;

use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Core\Enums\CalcMode;
use Samsara\Fermat\Core\Enums\NumberBase;
Expand Down Expand Up @@ -81,7 +80,6 @@ class SequenceProvider
*
* @return ImmutableDecimal|NumberCollection
* @throws IntegrityConstraint
* @throws MissingPackage
*/
public static function nthOddNumber(int $n, int $scale = null, bool $asCollection = false, int $collectionSize = 10): ImmutableDecimal|NumberCollection
{
Expand Down Expand Up @@ -210,7 +208,6 @@ public static function nthEulerZigzag(int $n, bool $asCollection = false, int $c
* @return ImmutableDecimal
* @throws IncompatibleObjectState
* @throws IntegrityConstraint
* @throws MissingPackage
*/
public static function nthBernoulliNumber($n, ?int $scale = null): ImmutableDecimal
{
Expand Down Expand Up @@ -308,7 +305,6 @@ public static function nthBernoulliNumber($n, ?int $scale = null): ImmutableDeci
* @param int $n
* @return NumberCollection
* @throws IntegrityConstraint
* @throws MissingPackage
*/
public static function nthPrimeNumbers(int $n): NumberCollection
{
Expand Down
2 changes: 0 additions & 2 deletions src/Samsara/Fermat/Core/Provider/SeriesProvider.php
Expand Up @@ -3,7 +3,6 @@
namespace Samsara\Fermat\Core\Provider;

use ReflectionException;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Exceptions\UsageError\OptionalExit;
use Samsara\Fermat\Core\Enums\NumberBase;
Expand Down Expand Up @@ -161,7 +160,6 @@ public static function maclaurinSeries(
* @param int $sumMode
* @return ImmutableDecimal
* @throws IntegrityConstraint
* @throws MissingPackage
*/
public static function generalizedContinuedFraction(
ContinuedFractionTermInterface $aPart,
Expand Down
Expand Up @@ -3,9 +3,7 @@
namespace Samsara\Fermat\Core\Types\Base\Traits;

use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Complex\Types\ComplexNumber;
use Samsara\Fermat\Core\Enums\CalcOperation;
use Samsara\Fermat\Core\Enums\NumberBase;
use Samsara\Fermat\Core\Numbers;
Expand Down Expand Up @@ -127,7 +125,6 @@ protected function helperAddSubXor(
* @return static
* @throws IncompatibleObjectState
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function helperAddSubFraction(
ImmutableFraction $thisNum,
Expand Down
Expand Up @@ -186,6 +186,7 @@ protected function helperArcsecArccscSimple(
} elseif ($this->isEqual(-1)) {
$answer = $negOneInputVal;
} else {
/** @noinspection PhpUncoveredEnumCasesInspection */
$answer = match ($operation) {
CalcOperation::ArcSec => $this->arcsecSelector($scale),
CalcOperation::ArcCsc => $this->arccscSelector($scale),
Expand Down Expand Up @@ -241,6 +242,7 @@ protected function helperArcBasicSimple(
{
$finalScale = $scale ?? $this->getScale();

/** @noinspection PhpUncoveredEnumCasesInspection */
$answer = match ($operation) {
CalcOperation::ArcTan => $this->arctanSelector($scale),
CalcOperation::ArcCot => $this->arccotSelector($scale),
Expand Down Expand Up @@ -273,6 +275,7 @@ protected function helperArcsecArccscScale(ImmutableDecimal $zeroTerm, CalcOpera

$bPart = $this->helperArcsecArccscBPart($scale, $zeroTerm);

/** @noinspection PhpUncoveredEnumCasesInspection */
$answer = SeriesProvider::generalizedContinuedFraction(
$aPart,
$bPart,
Expand Down
Expand Up @@ -3,13 +3,11 @@
namespace Samsara\Fermat\Core\Types\Base\Traits;

use Samsara\Exceptions\SystemError\LogicalError\IncompatibleObjectState;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Core\Enums\CalcOperation;
use Samsara\Fermat\Core\Enums\NumberBase;
use Samsara\Fermat\Core\Enums\RoundingMode;
use Samsara\Fermat\Core\Numbers;
use Samsara\Fermat\Core\Types\Base\Traits\InverseTrigonometryHelpersTrait;
use Samsara\Fermat\Core\Types\Traits\NumberNormalizationTrait;
use Samsara\Fermat\Core\Values\ImmutableDecimal;
use Samsara\Fermat\Core\Values\MutableDecimal;
Expand All @@ -28,7 +26,6 @@ trait InverseTrigonometryScaleTrait
* @return string
* @throws IncompatibleObjectState
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function arcsinScale(int $scale = null): string
{
Expand Down Expand Up @@ -58,7 +55,6 @@ protected function arcsinScale(int $scale = null): string
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function arccosScale(int $scale = null): string
{
Expand Down Expand Up @@ -87,7 +83,6 @@ protected function arccosScale(int $scale = null): string
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function arctanScale(int $scale = null): string
{
Expand Down Expand Up @@ -121,7 +116,6 @@ protected function arctanScale(int $scale = null): string
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function arccotScale(int $scale = null): string
{
Expand Down
3 changes: 0 additions & 3 deletions src/Samsara/Fermat/Core/Types/Base/Traits/LogScaleTrait.php
Expand Up @@ -3,7 +3,6 @@
namespace Samsara\Fermat\Core\Types\Base\Traits;

use Decimal\Decimal;
use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Core\Enums\NumberBase;
use Samsara\Fermat\Core\Numbers;
Expand All @@ -22,7 +21,6 @@ trait LogScaleTrait
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function expScale(int $scale = null): string
{
Expand Down Expand Up @@ -134,7 +132,6 @@ public function __invoke(int $n): ImmutableDecimal
*
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function lnScale(int $scale = null): string
{
Expand Down
Expand Up @@ -2,7 +2,6 @@

namespace Samsara\Fermat\Core\Types\Base\Traits;

use Samsara\Exceptions\SystemError\PlatformError\MissingPackage;
use Samsara\Exceptions\UsageError\IntegrityConstraint;
use Samsara\Fermat\Core\Enums\CalcMode;

Expand All @@ -16,7 +15,6 @@ trait LogSelectionTrait
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function expSelector(?int $scale): string
{
Expand All @@ -32,7 +30,6 @@ protected function expSelector(?int $scale): string
* @param int|null $scale
* @return string
* @throws IntegrityConstraint
* @throws MissingPackage
*/
protected function lnSelector(?int $scale): string
{
Expand Down
Expand Up @@ -30,6 +30,7 @@ protected function helperBasicTrigSelector(?int $scale, bool $round, CalcOperati
{
$finalScale = $scale ?? $this->getScale();

/** @noinspection PhpUncoveredEnumCasesInspection */
$answer = match ($operation) {
CalcOperation::Sin => $this->sinSelector($scale),
CalcOperation::Cos => $this->cosSelector($scale),
Expand Down Expand Up @@ -116,12 +117,14 @@ function ($n) use ($negOne, $one) {
return $n % 2 ? $negOne : $one;
},
function ($n) use ($intScale, $operation) {
/** @noinspection PhpUncoveredEnumCasesInspection */
return match ($operation) {
CalcOperation::Cos => SequenceProvider::nthEvenNumber($n, $intScale),
CalcOperation::Sin => SequenceProvider::nthOddNumber($n, $intScale)
};
},
function ($n) use ($intScale, $operation) {
/** @noinspection PhpUncoveredEnumCasesInspection */
return match ($operation) {
CalcOperation::Cos => SequenceProvider::nthEvenNumber($n, $intScale)->factorial(),
CalcOperation::Sin => SequenceProvider::nthOddNumber($n, $intScale)->factorial()
Expand Down

0 comments on commit 6efbbc6

Please sign in to comment.