1--TEST-- 2bcdiv() function with numbers pow 10 3--EXTENSIONS-- 4bcmath 5--INI-- 6bcmath.scale=0 7--FILE-- 8<?php 9$dividend_cases = ['0.012345', '0.12345', '1.2345', '12.345', '123.45', '-0.012345', '-0.12345', '-1.2345', '-12.345', '-123.45']; 10$divisor_cases = ['0.01', '0.1', '1', '10', '100', '-0.01', '-0.1', '-1', '-10', '-100']; 11$scale_cases = [0, 3, 5]; 12 13foreach ($scale_cases as $scale) { 14 echo "scale: {$scale}\n"; 15 foreach ($divisor_cases as $divisor) { 16 foreach ($dividend_cases as $dividend) { 17 $dividend_label = str_pad($dividend, 9, ' ', STR_PAD_LEFT); 18 $divisor_label = str_pad($divisor, 5, ' ', STR_PAD_LEFT); 19 $quot = bcdiv($dividend, $divisor, $scale); 20 $quot_label = str_pad($quot, $scale + 7 + ($scale ? 1 : 0), ' ', STR_PAD_LEFT); 21 echo $dividend_label, ' / ', $divisor_label, ' = ', $quot_label, "\n"; 22 } 23 } 24 echo "\n"; 25} 26?> 27--EXPECT-- 28scale: 0 29 0.012345 / 0.01 = 1 30 0.12345 / 0.01 = 12 31 1.2345 / 0.01 = 123 32 12.345 / 0.01 = 1234 33 123.45 / 0.01 = 12345 34-0.012345 / 0.01 = -1 35 -0.12345 / 0.01 = -12 36 -1.2345 / 0.01 = -123 37 -12.345 / 0.01 = -1234 38 -123.45 / 0.01 = -12345 39 0.012345 / 0.1 = 0 40 0.12345 / 0.1 = 1 41 1.2345 / 0.1 = 12 42 12.345 / 0.1 = 123 43 123.45 / 0.1 = 1234 44-0.012345 / 0.1 = 0 45 -0.12345 / 0.1 = -1 46 -1.2345 / 0.1 = -12 47 -12.345 / 0.1 = -123 48 -123.45 / 0.1 = -1234 49 0.012345 / 1 = 0 50 0.12345 / 1 = 0 51 1.2345 / 1 = 1 52 12.345 / 1 = 12 53 123.45 / 1 = 123 54-0.012345 / 1 = 0 55 -0.12345 / 1 = 0 56 -1.2345 / 1 = -1 57 -12.345 / 1 = -12 58 -123.45 / 1 = -123 59 0.012345 / 10 = 0 60 0.12345 / 10 = 0 61 1.2345 / 10 = 0 62 12.345 / 10 = 1 63 123.45 / 10 = 12 64-0.012345 / 10 = 0 65 -0.12345 / 10 = 0 66 -1.2345 / 10 = 0 67 -12.345 / 10 = -1 68 -123.45 / 10 = -12 69 0.012345 / 100 = 0 70 0.12345 / 100 = 0 71 1.2345 / 100 = 0 72 12.345 / 100 = 0 73 123.45 / 100 = 1 74-0.012345 / 100 = 0 75 -0.12345 / 100 = 0 76 -1.2345 / 100 = 0 77 -12.345 / 100 = 0 78 -123.45 / 100 = -1 79 0.012345 / -0.01 = -1 80 0.12345 / -0.01 = -12 81 1.2345 / -0.01 = -123 82 12.345 / -0.01 = -1234 83 123.45 / -0.01 = -12345 84-0.012345 / -0.01 = 1 85 -0.12345 / -0.01 = 12 86 -1.2345 / -0.01 = 123 87 -12.345 / -0.01 = 1234 88 -123.45 / -0.01 = 12345 89 0.012345 / -0.1 = 0 90 0.12345 / -0.1 = -1 91 1.2345 / -0.1 = -12 92 12.345 / -0.1 = -123 93 123.45 / -0.1 = -1234 94-0.012345 / -0.1 = 0 95 -0.12345 / -0.1 = 1 96 -1.2345 / -0.1 = 12 97 -12.345 / -0.1 = 123 98 -123.45 / -0.1 = 1234 99 0.012345 / -1 = 0 100 0.12345 / -1 = 0 101 1.2345 / -1 = -1 102 12.345 / -1 = -12 103 123.45 / -1 = -123 104-0.012345 / -1 = 0 105 -0.12345 / -1 = 0 106 -1.2345 / -1 = 1 107 -12.345 / -1 = 12 108 -123.45 / -1 = 123 109 0.012345 / -10 = 0 110 0.12345 / -10 = 0 111 1.2345 / -10 = 0 112 12.345 / -10 = -1 113 123.45 / -10 = -12 114-0.012345 / -10 = 0 115 -0.12345 / -10 = 0 116 -1.2345 / -10 = 0 117 -12.345 / -10 = 1 118 -123.45 / -10 = 12 119 0.012345 / -100 = 0 120 0.12345 / -100 = 0 121 1.2345 / -100 = 0 122 12.345 / -100 = 0 123 123.45 / -100 = -1 124-0.012345 / -100 = 0 125 -0.12345 / -100 = 0 126 -1.2345 / -100 = 0 127 -12.345 / -100 = 0 128 -123.45 / -100 = 1 129 130scale: 3 131 0.012345 / 0.01 = 1.234 132 0.12345 / 0.01 = 12.345 133 1.2345 / 0.01 = 123.450 134 12.345 / 0.01 = 1234.500 135 123.45 / 0.01 = 12345.000 136-0.012345 / 0.01 = -1.234 137 -0.12345 / 0.01 = -12.345 138 -1.2345 / 0.01 = -123.450 139 -12.345 / 0.01 = -1234.500 140 -123.45 / 0.01 = -12345.000 141 0.012345 / 0.1 = 0.123 142 0.12345 / 0.1 = 1.234 143 1.2345 / 0.1 = 12.345 144 12.345 / 0.1 = 123.450 145 123.45 / 0.1 = 1234.500 146-0.012345 / 0.1 = -0.123 147 -0.12345 / 0.1 = -1.234 148 -1.2345 / 0.1 = -12.345 149 -12.345 / 0.1 = -123.450 150 -123.45 / 0.1 = -1234.500 151 0.012345 / 1 = 0.012 152 0.12345 / 1 = 0.123 153 1.2345 / 1 = 1.234 154 12.345 / 1 = 12.345 155 123.45 / 1 = 123.450 156-0.012345 / 1 = -0.012 157 -0.12345 / 1 = -0.123 158 -1.2345 / 1 = -1.234 159 -12.345 / 1 = -12.345 160 -123.45 / 1 = -123.450 161 0.012345 / 10 = 0.001 162 0.12345 / 10 = 0.012 163 1.2345 / 10 = 0.123 164 12.345 / 10 = 1.234 165 123.45 / 10 = 12.345 166-0.012345 / 10 = -0.001 167 -0.12345 / 10 = -0.012 168 -1.2345 / 10 = -0.123 169 -12.345 / 10 = -1.234 170 -123.45 / 10 = -12.345 171 0.012345 / 100 = 0.000 172 0.12345 / 100 = 0.001 173 1.2345 / 100 = 0.012 174 12.345 / 100 = 0.123 175 123.45 / 100 = 1.234 176-0.012345 / 100 = 0.000 177 -0.12345 / 100 = -0.001 178 -1.2345 / 100 = -0.012 179 -12.345 / 100 = -0.123 180 -123.45 / 100 = -1.234 181 0.012345 / -0.01 = -1.234 182 0.12345 / -0.01 = -12.345 183 1.2345 / -0.01 = -123.450 184 12.345 / -0.01 = -1234.500 185 123.45 / -0.01 = -12345.000 186-0.012345 / -0.01 = 1.234 187 -0.12345 / -0.01 = 12.345 188 -1.2345 / -0.01 = 123.450 189 -12.345 / -0.01 = 1234.500 190 -123.45 / -0.01 = 12345.000 191 0.012345 / -0.1 = -0.123 192 0.12345 / -0.1 = -1.234 193 1.2345 / -0.1 = -12.345 194 12.345 / -0.1 = -123.450 195 123.45 / -0.1 = -1234.500 196-0.012345 / -0.1 = 0.123 197 -0.12345 / -0.1 = 1.234 198 -1.2345 / -0.1 = 12.345 199 -12.345 / -0.1 = 123.450 200 -123.45 / -0.1 = 1234.500 201 0.012345 / -1 = -0.012 202 0.12345 / -1 = -0.123 203 1.2345 / -1 = -1.234 204 12.345 / -1 = -12.345 205 123.45 / -1 = -123.450 206-0.012345 / -1 = 0.012 207 -0.12345 / -1 = 0.123 208 -1.2345 / -1 = 1.234 209 -12.345 / -1 = 12.345 210 -123.45 / -1 = 123.450 211 0.012345 / -10 = -0.001 212 0.12345 / -10 = -0.012 213 1.2345 / -10 = -0.123 214 12.345 / -10 = -1.234 215 123.45 / -10 = -12.345 216-0.012345 / -10 = 0.001 217 -0.12345 / -10 = 0.012 218 -1.2345 / -10 = 0.123 219 -12.345 / -10 = 1.234 220 -123.45 / -10 = 12.345 221 0.012345 / -100 = 0.000 222 0.12345 / -100 = -0.001 223 1.2345 / -100 = -0.012 224 12.345 / -100 = -0.123 225 123.45 / -100 = -1.234 226-0.012345 / -100 = 0.000 227 -0.12345 / -100 = 0.001 228 -1.2345 / -100 = 0.012 229 -12.345 / -100 = 0.123 230 -123.45 / -100 = 1.234 231 232scale: 5 233 0.012345 / 0.01 = 1.23450 234 0.12345 / 0.01 = 12.34500 235 1.2345 / 0.01 = 123.45000 236 12.345 / 0.01 = 1234.50000 237 123.45 / 0.01 = 12345.00000 238-0.012345 / 0.01 = -1.23450 239 -0.12345 / 0.01 = -12.34500 240 -1.2345 / 0.01 = -123.45000 241 -12.345 / 0.01 = -1234.50000 242 -123.45 / 0.01 = -12345.00000 243 0.012345 / 0.1 = 0.12345 244 0.12345 / 0.1 = 1.23450 245 1.2345 / 0.1 = 12.34500 246 12.345 / 0.1 = 123.45000 247 123.45 / 0.1 = 1234.50000 248-0.012345 / 0.1 = -0.12345 249 -0.12345 / 0.1 = -1.23450 250 -1.2345 / 0.1 = -12.34500 251 -12.345 / 0.1 = -123.45000 252 -123.45 / 0.1 = -1234.50000 253 0.012345 / 1 = 0.01234 254 0.12345 / 1 = 0.12345 255 1.2345 / 1 = 1.23450 256 12.345 / 1 = 12.34500 257 123.45 / 1 = 123.45000 258-0.012345 / 1 = -0.01234 259 -0.12345 / 1 = -0.12345 260 -1.2345 / 1 = -1.23450 261 -12.345 / 1 = -12.34500 262 -123.45 / 1 = -123.45000 263 0.012345 / 10 = 0.00123 264 0.12345 / 10 = 0.01234 265 1.2345 / 10 = 0.12345 266 12.345 / 10 = 1.23450 267 123.45 / 10 = 12.34500 268-0.012345 / 10 = -0.00123 269 -0.12345 / 10 = -0.01234 270 -1.2345 / 10 = -0.12345 271 -12.345 / 10 = -1.23450 272 -123.45 / 10 = -12.34500 273 0.012345 / 100 = 0.00012 274 0.12345 / 100 = 0.00123 275 1.2345 / 100 = 0.01234 276 12.345 / 100 = 0.12345 277 123.45 / 100 = 1.23450 278-0.012345 / 100 = -0.00012 279 -0.12345 / 100 = -0.00123 280 -1.2345 / 100 = -0.01234 281 -12.345 / 100 = -0.12345 282 -123.45 / 100 = -1.23450 283 0.012345 / -0.01 = -1.23450 284 0.12345 / -0.01 = -12.34500 285 1.2345 / -0.01 = -123.45000 286 12.345 / -0.01 = -1234.50000 287 123.45 / -0.01 = -12345.00000 288-0.012345 / -0.01 = 1.23450 289 -0.12345 / -0.01 = 12.34500 290 -1.2345 / -0.01 = 123.45000 291 -12.345 / -0.01 = 1234.50000 292 -123.45 / -0.01 = 12345.00000 293 0.012345 / -0.1 = -0.12345 294 0.12345 / -0.1 = -1.23450 295 1.2345 / -0.1 = -12.34500 296 12.345 / -0.1 = -123.45000 297 123.45 / -0.1 = -1234.50000 298-0.012345 / -0.1 = 0.12345 299 -0.12345 / -0.1 = 1.23450 300 -1.2345 / -0.1 = 12.34500 301 -12.345 / -0.1 = 123.45000 302 -123.45 / -0.1 = 1234.50000 303 0.012345 / -1 = -0.01234 304 0.12345 / -1 = -0.12345 305 1.2345 / -1 = -1.23450 306 12.345 / -1 = -12.34500 307 123.45 / -1 = -123.45000 308-0.012345 / -1 = 0.01234 309 -0.12345 / -1 = 0.12345 310 -1.2345 / -1 = 1.23450 311 -12.345 / -1 = 12.34500 312 -123.45 / -1 = 123.45000 313 0.012345 / -10 = -0.00123 314 0.12345 / -10 = -0.01234 315 1.2345 / -10 = -0.12345 316 12.345 / -10 = -1.23450 317 123.45 / -10 = -12.34500 318-0.012345 / -10 = 0.00123 319 -0.12345 / -10 = 0.01234 320 -1.2345 / -10 = 0.12345 321 -12.345 / -10 = 1.23450 322 -123.45 / -10 = 12.34500 323 0.012345 / -100 = -0.00012 324 0.12345 / -100 = -0.00123 325 1.2345 / -100 = -0.01234 326 12.345 / -100 = -0.12345 327 123.45 / -100 = -1.23450 328-0.012345 / -100 = 0.00012 329 -0.12345 / -100 = 0.00123 330 -1.2345 / -100 = 0.01234 331 -12.345 / -100 = 0.12345 332 -123.45 / -100 = 1.23450 333