MCPcopy Create free account
hub / github.com/boostorg/parser / scale

Function scale

include/boost/parser/detail/numeric.hpp:625–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623
624 template<typename T>
625 inline bool scale(int exp, T & n)
626 {
627 constexpr auto max_exp = std::numeric_limits<T>::max_exponent10;
628 constexpr auto min_exp = std::numeric_limits<T>::min_exponent10;
629
630 if (exp >= 0)
631 {
632 // return false if exp exceeds the max_exp
633 // do this check only for primitive types!
634 if (std::is_floating_point_v<T> && exp > max_exp)
635 return false;
636 n *= detail_spirit_x3::pow10<T>(exp);
637 }
638 else
639 {
640 if (exp < min_exp)
641 {
642 n /= detail_spirit_x3::pow10<T>(-min_exp);
643
644 // return false if exp still exceeds the min_exp
645 // do this check only for primitive types!
646 exp += -min_exp;
647 if (std::is_floating_point_v<T> && exp < min_exp)
648 return false;
649
650 n /= detail_spirit_x3::pow10<T>(-exp);
651 }
652 else
653 {
654 n /= detail_spirit_x3::pow10<T>(-exp);
655 }
656 }
657 return true;
658 }
659
660 template<typename T>
661 bool scale(int exp, int frac, T & n)

Callers 1

parseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected