@@ -380,17 +380,11 @@ public function div(Decimal $b, $scale = null)
380
380
$ divscale = $ scale + 1 ;
381
381
} else {
382
382
// $divscale is calculated in order to maintain a reasonable precision
383
- $ one = Decimal::fromInteger (1 );
384
383
$ this_abs = $ this ->abs ();
385
384
$ b_abs = $ b ->abs ();
386
385
387
- $ this_significative_digits = strlen ($ this ->value ) - (
388
- ($ this_abs ->comp ($ one ) === -1 ) ? 2 : ($ this ->scale > 0 ? 1 : 0 )
389
- ) - ($ this ->isNegative () ? 1 : 0 );
390
-
391
- $ b_significative_digits = strlen ($ b ->value ) - (
392
- ($ b_abs ->comp ($ one ) === -1 ) ? 2 : ($ b ->scale > 0 ? 1 : 0 )
393
- ) - ($ b ->isNegative () ? 1 : 0 );
386
+ $ this_significative_digits = self ::countSignificativeDigits ($ this , $ this_abs );
387
+ $ b_significative_digits = self ::countSignificativeDigits ($ b , $ b_abs );
394
388
395
389
$ log10_result =
396
390
self ::innerLog10 ($ this_abs ->value , $ this_abs ->scale , 1 ) -
@@ -830,6 +824,22 @@ private static function normalizeSign($sign)
830
824
return $ sign ;
831
825
}
832
826
827
+ /**
828
+ * Counts the number of significative digits of $val
829
+ *
830
+ * @param Decimal $val
831
+ * @param Decimal $abs $val->abs()
832
+ * @return integer
833
+ */
834
+ private static function countSignificativeDigits (Decimal $ val , Decimal $ abs )
835
+ {
836
+ $ one = Decimal::fromInteger (1 );
837
+
838
+ return strlen ($ val ->value ) - (
839
+ ($ abs ->comp ($ one ) === -1 ) ? 2 : max ($ val ->scale , 1 )
840
+ ) - ($ val ->isNegative () ? 1 : 0 );
841
+ }
842
+
833
843
/**
834
844
* @return string
835
845
*/
0 commit comments