compare two big integers, returning the large value. assumes both are normalized. if the return value is negative, other is larger, if the return value is positive, this is larger, otherwise they are equal. the limbs are stored in little-endian order, so we must compare the limbs in ever order.
| 2278 | // the limbs are stored in little-endian order, so we |
| 2279 | // must compare the limbs in ever order. |
| 2280 | FASTFLOAT_CONSTEXPR20 int compare(const bigint& other) const noexcept { |
| 2281 | if (vec.len() > other.vec.len()) { |
| 2282 | return 1; |
| 2283 | } else if (vec.len() < other.vec.len()) { |
| 2284 | return -1; |
| 2285 | } else { |
| 2286 | for (size_t index = vec.len(); index > 0; index--) { |
| 2287 | limb xi = vec[index - 1]; |
| 2288 | limb yi = other.vec[index - 1]; |
| 2289 | if (xi > yi) { |
| 2290 | return 1; |
| 2291 | } else if (xi < yi) { |
| 2292 | return -1; |
| 2293 | } |
| 2294 | } |
| 2295 | return 0; |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | // shift left each limb n bits, carrying over to the new limb |
| 2300 | // returns true if we were able to shift all the digits. |
no test coverage detected