<?php $leftOperand = '-0.00000000099999'; $modulus = '-0.00056'; $scale =14; bcscale($scale); //echo bcmod($leftOperand, $modulus); foreach( [ [4,3,1], [-4,3,2], [-4,-3,1], [4,-3,-2], [3,4,3], [-3,4,1], [-3,-4,1], [3,-4,-1], ] as $d) { echo "\r\nia $d[0] % $d[1] =".iaBcMod($d[0], $d[1], 0). " vs bcmod=".bcmod($d[0], $d[1])." vs wolfman=".$d[2]; } function iaBcMod($leftOperand, $modulus, $scale) { $frac = bcdiv($leftOperand, $modulus, $scale); if( $frac[0] === '-') { return bcsub( $leftOperand, bcmul($modulus, ceil($frac), $scale), $scale ); } return bcsub( $leftOperand, bcmul($modulus, floor($frac), $scale), $scale ); }
You have javascript disabled. You will not be able to edit any code.