| 542 | |
| 543 | template <typename T = ArrowType, typename CType = typename TypeTraits<T>::CType> |
| 544 | enable_if_floating_value<CType> Call(KernelContext* ctx, CType arg, Status* st) const { |
| 545 | // Do not process Inf or NaN because they will trigger the overflow error at end of |
| 546 | // function. |
| 547 | if (!std::isfinite(arg)) { |
| 548 | return arg; |
| 549 | } |
| 550 | auto round_val = arg / multiple; |
| 551 | auto frac = round_val - std::floor(round_val); |
| 552 | if (frac != T(0)) { |
| 553 | // Use std::round() if in tie-breaking mode and scaled value is not 0.5. |
| 554 | if ((kRoundMode >= RoundMode::HALF_DOWN) && (frac != T(0.5))) { |
| 555 | round_val = std::round(round_val); |
| 556 | } else { |
| 557 | round_val = RoundImpl<CType, kRoundMode>::Round(round_val); |
| 558 | } |
| 559 | round_val *= multiple; |
| 560 | if (!std::isfinite(round_val)) { |
| 561 | *st = Status::Invalid("overflow occurred during rounding"); |
| 562 | return arg; |
| 563 | } |
| 564 | } else { |
| 565 | // If scaled value is an integer, then no rounding is needed. |
| 566 | round_val = arg; |
| 567 | } |
| 568 | return round_val; |
| 569 | } |
| 570 | }; |
| 571 | |
| 572 | template <typename ArrowType, RoundMode kRoundMode> |