1--TEST-- 2BcMath\Number compare() with scale 3--EXTENSIONS-- 4bcmath 5--FILE-- 6<?php 7 8$values1 = [ 9 new BcMath\Number('0.001'), 10 new BcMath\Number('-0.001'), 11]; 12 13$values2 = [ 14 0, 15 -0, 16 '0.0011', 17 '-0.0011', 18]; 19 20$value1 = new BcMath\Number('0.001'); 21 22$scales = [0, 2, 3, 4]; 23 24foreach ($scales as $scale) { 25 echo "========== scale is {$scale} ==========\n"; 26 foreach ($values1 as $value1) { 27 foreach ($values2 as $value2) { 28 $output = str_pad("{$value1} <=> {$value2}: ", 20, ' ', STR_PAD_LEFT); 29 $output .= str_pad((string) $value1->compare($value2, $scale), 2, ' ', STR_PAD_LEFT); 30 echo "{$output}\n"; 31 } 32 } 33} 34?> 35--EXPECT-- 36========== scale is 0 ========== 37 0.001 <=> 0: 0 38 0.001 <=> 0: 0 39 0.001 <=> 0.0011: 0 40 0.001 <=> -0.0011: 0 41 -0.001 <=> 0: 0 42 -0.001 <=> 0: 0 43 -0.001 <=> 0.0011: 0 44-0.001 <=> -0.0011: 0 45========== scale is 2 ========== 46 0.001 <=> 0: 0 47 0.001 <=> 0: 0 48 0.001 <=> 0.0011: 0 49 0.001 <=> -0.0011: 0 50 -0.001 <=> 0: 0 51 -0.001 <=> 0: 0 52 -0.001 <=> 0.0011: 0 53-0.001 <=> -0.0011: 0 54========== scale is 3 ========== 55 0.001 <=> 0: 1 56 0.001 <=> 0: 1 57 0.001 <=> 0.0011: 0 58 0.001 <=> -0.0011: 1 59 -0.001 <=> 0: -1 60 -0.001 <=> 0: -1 61 -0.001 <=> 0.0011: -1 62-0.001 <=> -0.0011: 0 63========== scale is 4 ========== 64 0.001 <=> 0: 1 65 0.001 <=> 0: 1 66 0.001 <=> 0.0011: -1 67 0.001 <=> -0.0011: 1 68 -0.001 <=> 0: -1 69 -0.001 <=> 0: -1 70 -0.001 <=> 0.0011: -1 71-0.001 <=> -0.0011: 1 72