Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. template<class F>
  2. void
  3. number::
  4. assign(F v
  5. ,typename std::enable_if<
  6. std::is_floating_point<
  7. F>::value>::type*) noexcept
  8. {
  9. static exponent_type const bias =
  10. static_cast<exponent_type>(std::floor(
  11. std::log10((std::numeric_limits<
  12. mantissa_type>::max)()))) - 2;
  13. if(v < 0)
  14. {
  15. v = std::abs(v);
  16. neg_ = true;
  17. }
  18. else
  19. {
  20. neg_ = false;
  21. }
  22. exp_ = static_cast<exponent_type>(
  23. std::floor(std::log10(v))) - bias;
  24. mant_ = static_cast<mantissa_type>(
  25. v / std::pow(10, exp_));
  26. normalize();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement