1
1
<?php
2
+ declare (strict_types=1 );
2
3
3
4
namespace Litipk \BigNumbers ;
4
5
7
8
use Litipk \BigNumbers \Errors \InfiniteInputError ;
8
9
use Litipk \BigNumbers \Errors \NaNInputError ;
9
10
use Litipk \BigNumbers \Errors \NotImplementedError ;
10
- use Litipk \Exceptions \InvalidArgumentTypeException as InvalidArgumentTypeException ;
11
11
12
12
/**
13
13
* Immutable object that represents a rational number
@@ -136,10 +136,10 @@ public static function fromString(string $strValue, int $scale = null, bool $rem
136
136
137
137
if (self ::normalizeSign ($ captures [4 ]) === '' ) {
138
138
$ min_scale = \max ($ mantissa_scale - $ exp_val , 0 );
139
- $ tmp_multiplier = \bcpow (10 , $ exp_val );
139
+ $ tmp_multiplier = \bcpow (' 10 ' , ( string ) $ exp_val );
140
140
} else {
141
141
$ 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 );
143
143
}
144
144
145
145
$ value = self ::normalizeSign ($ captures [1 ]) . \bcmul (
@@ -540,8 +540,8 @@ private function innerTruncate(int $scale = 0, bool $ceil = true): Decimal
540
540
541
541
if ($ mustTruncate ) {
542
542
$ 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 );
545
545
}
546
546
547
547
return self ::fromString ($ rounded , $ scale );
@@ -1110,8 +1110,8 @@ private static function innerRound(string $value, int $scale = 0): string
1110
1110
1111
1111
if ($ diffDigit >= 5 ) {
1112
1112
$ 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 );
1115
1115
}
1116
1116
1117
1117
return $ rounded ;
@@ -1136,10 +1136,10 @@ private static function innerLog10(string $value, int $in_scale, int $out_scale)
1136
1136
$ value_log10_approx = $ value_len - ($ in_scale > 0 ? ($ in_scale +2 ) : 1 );
1137
1137
1138
1138
return \bcadd (
1139
- $ value_log10_approx ,
1140
- \log10 (\bcdiv (
1139
+ ( string ) $ value_log10_approx ,
1140
+ ( string ) \log10 (( float ) \bcdiv (
1141
1141
$ value ,
1142
- \bcpow ('10 ' , $ value_log10_approx ),
1142
+ \bcpow ('10 ' , ( string ) $ value_log10_approx ),
1143
1143
\min ($ value_len , $ out_scale )
1144
1144
)),
1145
1145
$ out_scale
@@ -1149,10 +1149,10 @@ private static function innerLog10(string $value, int $in_scale, int $out_scale)
1149
1149
$ value_log10_approx = -\strlen ($ captures [1 ])-1 ;
1150
1150
1151
1151
return \bcadd (
1152
- $ value_log10_approx ,
1153
- \log10 (\bcmul (
1152
+ ( string ) $ value_log10_approx ,
1153
+ ( string ) \log10 (( float ) \bcmul (
1154
1154
$ value ,
1155
- \bcpow ('10 ' , -$ value_log10_approx ),
1155
+ \bcpow ('10 ' , ( string ) -$ value_log10_approx ),
1156
1156
$ in_scale + $ value_log10_approx
1157
1157
)),
1158
1158
$ out_scale
@@ -1178,7 +1178,7 @@ private static function innerPowWithLittleExponent(
1178
1178
int $ out_scale
1179
1179
): string
1180
1180
{
1181
- $ inner_scale = \ceil ($ exp_scale * \log (10 ) / \log (2 )) + 1 ;
1181
+ $ inner_scale = ( int ) \ceil ($ exp_scale * \log (10 ) / \log (2 )) + 1 ;
1182
1182
1183
1183
$ result_a = '1 ' ;
1184
1184
$ result_b = '0 ' ;
@@ -1216,10 +1216,10 @@ private static function computeSquareIndex(
1216
1216
int $ inner_scale
1217
1217
): array
1218
1218
{
1219
- $ actual_rt = \bcpow ('0.5 ' , $ actual_index , $ exp_scale );
1219
+ $ actual_rt = \bcpow ('0.5 ' , ( string ) $ actual_index , $ exp_scale );
1220
1220
$ r = \bcsub ($ exponent_remaining , $ actual_rt , $ inner_scale );
1221
1221
1222
- while (\bccomp ($ r , 0 , $ exp_scale ) === -1 ) {
1222
+ while (\bccomp ($ r , ' 0 ' , $ exp_scale ) === -1 ) {
1223
1223
++$ actual_index ;
1224
1224
$ actual_rt = \bcmul ('0.5 ' , $ actual_rt , $ inner_scale );
1225
1225
$ r = \bcsub ($ exponent_remaining , $ actual_rt , $ inner_scale );
0 commit comments