90534 {
90535 using result_t = typename T::ResultType;
90536 if (!state.Flush()) {
90537 return false;
90538 }
90539
90541 if (e < -38) {
90542 state.result = 0;
90543 return true;
90544 }
90545
90546
90547 result_t remainder = 0;
90548 if (e < 0) {
90549 state.result = T::Operation::DivMod(state.result, T::Operation::POWERS_OF_TEN[-e], remainder);
90550 if (remainder < 0) {
90551 result_t negate_result;
90552 if (!T::Operation::TryNegate(remainder, negate_result)) {
90553 return false;
90554 }
90555 remainder = negate_result;
90556 }
90557 state.decimal = remainder;
90558 state.decimal_total_digits =
static_cast<uint16_t>(-e);
90559 state.decimal_intermediate = 0;
90560 state.decimal_intermediate_digits = 0;
90561 return Finalize<T, NEGATIVE>(state);
90562 }
90563
90564
90565 if (state.result != 0) {
90566 if (e > 38 || !TryMultiplyOperator::Operation(state.result, T::Operation::POWERS_OF_TEN[e], state.result)) {
90567 return false;
90568 }
90569 }
90570 if (!state.FlushDecimal()) {
90571 return false;
90572 }
90573 if (state.decimal == 0) {
90574 return Finalize<T, NEGATIVE>(state);
90575 }
90576
90577 e = exponent - state.decimal_total_digits;
90578 if (e < 0) {
90579 if (e < -38) {
90580 return false;
90581 }
90582 state.decimal = T::Operation::DivMod(state.decimal, T::Operation::POWERS_OF_TEN[-e], remainder);
90583 state.decimal_total_digits -= (exponent);
90584 } else {
90585 if (e > 38 ||
90586 !TryMultiplyOperator::Operation(state.decimal, T::Operation::POWERS_OF_TEN[e], state.decimal)) {
90587 return false;
90588 }
90589 }
90590
90591 if (NEGATIVE) {
90592 if (!TrySubtractOperator::Operation(state.result, state.decimal, state.result)) {
90593 return false;
90594 }
90595 } else if (!TryAddOperator::Operation(state.result, state.decimal, state.result)) {
90596 return false;
90597 }
90598 state.decimal = remainder;
90599 return Finalize<T, NEGATIVE>(state);
90600 }