Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit e9b38e9

Browse files
author
Andreu Correa Casablanca
committed
Declare strict types
1 parent 182f1a9 commit e9b38e9

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/Decimal.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace Litipk\BigNumbers;
45

@@ -7,7 +8,6 @@
78
use Litipk\BigNumbers\Errors\InfiniteInputError;
89
use Litipk\BigNumbers\Errors\NaNInputError;
910
use Litipk\BigNumbers\Errors\NotImplementedError;
10-
use Litipk\Exceptions\InvalidArgumentTypeException as InvalidArgumentTypeException;
1111

1212
/**
1313
* Immutable object that represents a rational number
@@ -136,10 +136,10 @@ public static function fromString(string $strValue, int $scale = null, bool $rem
136136

137137
if (self::normalizeSign($captures[4]) === '') {
138138
$min_scale = \max($mantissa_scale - $exp_val, 0);
139-
$tmp_multiplier = \bcpow(10, $exp_val);
139+
$tmp_multiplier = \bcpow('10', (string)$exp_val);
140140
} else {
141141
$min_scale = $mantissa_scale + $exp_val;
142-
$tmp_multiplier = \bcpow(10, -$exp_val, $exp_val);
142+
$tmp_multiplier = \bcpow('10', (string)-$exp_val, $exp_val);
143143
}
144144

145145
$value = self::normalizeSign($captures[1]) . \bcmul(
@@ -540,8 +540,8 @@ private function innerTruncate(int $scale = 0, bool $ceil = true): Decimal
540540

541541
if ($mustTruncate) {
542542
$rounded = $ceil
543-
? \bcadd($rounded, \bcpow('10', -$scale, $scale), $scale)
544-
: \bcsub($rounded, \bcpow('10', -$scale, $scale), $scale);
543+
? \bcadd($rounded, \bcpow('10', (string)-$scale, $scale), $scale)
544+
: \bcsub($rounded, \bcpow('10', (string)-$scale, $scale), $scale);
545545
}
546546

547547
return self::fromString($rounded, $scale);
@@ -1110,8 +1110,8 @@ private static function innerRound(string $value, int $scale = 0): string
11101110

11111111
if ($diffDigit >= 5) {
11121112
$rounded = ($diffDigit >= 5 && $value[0] !== '-')
1113-
? \bcadd($rounded, \bcpow('10', -$scale, $scale), $scale)
1114-
: \bcsub($rounded, \bcpow('10', -$scale, $scale), $scale);
1113+
? \bcadd($rounded, \bcpow('10', (string)-$scale, $scale), $scale)
1114+
: \bcsub($rounded, \bcpow('10', (string)-$scale, $scale), $scale);
11151115
}
11161116

11171117
return $rounded;
@@ -1136,10 +1136,10 @@ private static function innerLog10(string $value, int $in_scale, int $out_scale)
11361136
$value_log10_approx = $value_len - ($in_scale > 0 ? ($in_scale+2) : 1);
11371137

11381138
return \bcadd(
1139-
$value_log10_approx,
1140-
\log10(\bcdiv(
1139+
(string)$value_log10_approx,
1140+
(string)\log10((float)\bcdiv(
11411141
$value,
1142-
\bcpow('10', $value_log10_approx),
1142+
\bcpow('10', (string)$value_log10_approx),
11431143
\min($value_len, $out_scale)
11441144
)),
11451145
$out_scale
@@ -1149,10 +1149,10 @@ private static function innerLog10(string $value, int $in_scale, int $out_scale)
11491149
$value_log10_approx = -\strlen($captures[1])-1;
11501150

11511151
return \bcadd(
1152-
$value_log10_approx,
1153-
\log10(\bcmul(
1152+
(string)$value_log10_approx,
1153+
(string)\log10((float)\bcmul(
11541154
$value,
1155-
\bcpow('10', -$value_log10_approx),
1155+
\bcpow('10', (string)-$value_log10_approx),
11561156
$in_scale + $value_log10_approx
11571157
)),
11581158
$out_scale
@@ -1178,7 +1178,7 @@ private static function innerPowWithLittleExponent(
11781178
int $out_scale
11791179
): string
11801180
{
1181-
$inner_scale = \ceil($exp_scale * \log(10) / \log(2)) + 1;
1181+
$inner_scale = (int)\ceil($exp_scale * \log(10) / \log(2)) + 1;
11821182

11831183
$result_a = '1';
11841184
$result_b = '0';
@@ -1216,10 +1216,10 @@ private static function computeSquareIndex(
12161216
int $inner_scale
12171217
): array
12181218
{
1219-
$actual_rt = \bcpow('0.5', $actual_index, $exp_scale);
1219+
$actual_rt = \bcpow('0.5', (string)$actual_index, $exp_scale);
12201220
$r = \bcsub($exponent_remaining, $actual_rt, $inner_scale);
12211221

1222-
while (\bccomp($r, 0, $exp_scale) === -1) {
1222+
while (\bccomp($r, '0', $exp_scale) === -1) {
12231223
++$actual_index;
12241224
$actual_rt = \bcmul('0.5', $actual_rt, $inner_scale);
12251225
$r = \bcsub($exponent_remaining, $actual_rt, $inner_scale);

src/DecimalConstants.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace Litipk\BigNumbers;
45

56
use Litipk\BigNumbers\Decimal as Decimal;
67

78

89
/**
9-
* git statu class that holds many important numeric constants
10+
* Class that holds many important numeric constants
1011
*
1112
* @author Andreu Correa Casablanca <[email protected]>
1213
*/

0 commit comments

Comments
 (0)