| @@ 979-995 (lines=17) @@ | ||
| 976 | if ($startMs < $targetMs) { |
|
| 977 | $max = 1; |
|
| 978 | // Find a value that is too large |
|
| 979 | while (true) { |
|
| 980 | $this->setTimeInMillis($startMs); |
|
| 981 | $this->add($field, $max); |
|
| 982 | $ms = (float) $this->getTimeInMillis(); |
|
| 983 | if ($ms == $targetMs) { |
|
| 984 | return $max; |
|
| 985 | } elseif ($ms > $targetMs) { |
|
| 986 | break; |
|
| 987 | } else { |
|
| 988 | $max <<= 1; |
|
| 989 | if ($max < 0) { |
|
| 990 | // TODO: check if we can change this to float to support a larger range |
|
| 991 | // Field difference too large to fit into int32_t |
|
| 992 | throw new \InvalidArgumentException('The difference is to large to fit into an integer'); |
|
| 993 | } |
|
| 994 | } |
|
| 995 | } |
|
| 996 | // Do a binary search |
|
| 997 | while (($max - $min) > 1) { |
|
| 998 | $t = (int) (($min + $max) / 2); |
|
| @@ 1013-1029 (lines=17) @@ | ||
| 1010 | } elseif ($startMs > $targetMs) { |
|
| 1011 | $max = -1; |
|
| 1012 | // Find a value that is too small |
|
| 1013 | while (true) { |
|
| 1014 | $this->setTimeInMillis($startMs); |
|
| 1015 | $this->add($field, $max); |
|
| 1016 | $ms = (float) $this->getTimeInMillis(); |
|
| 1017 | if ($ms == $targetMs) { |
|
| 1018 | return $max; |
|
| 1019 | } elseif ($ms < $targetMs) { |
|
| 1020 | break; |
|
| 1021 | } else { |
|
| 1022 | $max <<= 1; |
|
| 1023 | if ($max == 0) { |
|
| 1024 | // TODO: see above |
|
| 1025 | // Field difference too large to fit into int32_t |
|
| 1026 | throw new \InvalidArgumentException('The difference is to large to fit into an integer'); |
|
| 1027 | } |
|
| 1028 | } |
|
| 1029 | } |
|
| 1030 | // Do a binary search |
|
| 1031 | while (($min - $max) > 1) { |
|
| 1032 | $t = (int) (($min + $max) / 2); |
|