mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-06 14:24:09 +00:00
[Destructive changes] add sprout::string constructor (already not an aggregate)
This commit is contained in:
parent
cb1077d247
commit
baf8995e81
17 changed files with 466 additions and 301 deletions
|
@ -44,31 +44,27 @@ namespace sprout {
|
|||
template<typename Elem, typename FloatType, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<Elem, sprout::printed_float_digits<FloatType>::value>
|
||||
float_to_string_impl(FloatType val, bool negative, int digits, int v, sprout::index_tuple<Indexes...>) {
|
||||
typedef sprout::basic_string<Elem, sprout::printed_float_digits<FloatType>::value> type;
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_digits<FloatType>::value> access_type;
|
||||
return negative
|
||||
? type{
|
||||
{
|
||||
static_cast<Elem>('-'),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
},
|
||||
static_cast<std::size_t>(digits + 2 + sprout::detail::decimal_places_length)
|
||||
}
|
||||
: type{
|
||||
{
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
},
|
||||
static_cast<std::size_t>(digits + 1 + sprout::detail::decimal_places_length)
|
||||
}
|
||||
? access_type::raw_construct(
|
||||
static_cast<std::size_t>(digits + 2 + sprout::detail::decimal_places_length),
|
||||
static_cast<Elem>('-'),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
)
|
||||
: access_type::raw_construct(
|
||||
static_cast<std::size_t>(digits + 1 + sprout::detail::decimal_places_length),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Elem, typename FloatType>
|
||||
|
@ -90,13 +86,13 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<Elem, sprout::printed_float_digits<FloatType>::value>
|
||||
float_to_string(FloatType val) {
|
||||
typedef sprout::basic_string<Elem, sprout::printed_float_digits<FloatType>::value> type;
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_digits<FloatType>::value> access_type;
|
||||
return sprout::math::isinf(val) ? sprout::math::signbit(val)
|
||||
? type{{static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f')}, 4}
|
||||
: type{{static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f')}, 3}
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: sprout::math::isnan(val) ? sprout::math::signbit(val)
|
||||
? type{{static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n')}, 4}
|
||||
: type{{static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n')}, 3}
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: sprout::detail::float_to_string<Elem>(
|
||||
sprout::detail::float_round_at(val < 0 ? -val : val, sprout::detail::decimal_places_length),
|
||||
sprout::math::signbit(val),
|
||||
|
@ -130,39 +126,35 @@ namespace sprout {
|
|||
template<typename Elem, typename FloatType, sprout::index_t... Indexes>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<Elem, sprout::printed_float_exp_digits<FloatType>::value>
|
||||
float_to_string_exp(FloatType val, bool negative, int exponent10, int e10_digits, sprout::index_tuple<Indexes...>) {
|
||||
typedef sprout::basic_string<Elem, sprout::printed_float_exp_digits<FloatType>::value> type;
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_exp_digits<FloatType>::value> access_type;
|
||||
return negative
|
||||
? type{
|
||||
{
|
||||
static_cast<Elem>('-'),
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
},
|
||||
static_cast<std::size_t>(5 + sprout::detail::decimal_places_length + e10_digits)
|
||||
}
|
||||
: type{
|
||||
{
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
},
|
||||
static_cast<std::size_t>(4 + sprout::detail::decimal_places_length + e10_digits)
|
||||
}
|
||||
? access_type::raw_construct(
|
||||
static_cast<std::size_t>(5 + sprout::detail::decimal_places_length + e10_digits),
|
||||
static_cast<Elem>('-'),
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
)
|
||||
: access_type::raw_construct(
|
||||
static_cast<std::size_t>(4 + sprout::detail::decimal_places_length + e10_digits),
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
@ -176,13 +168,13 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR sprout::basic_string<Elem, sprout::printed_float_exp_digits<FloatType>::value>
|
||||
float_to_string_exp(FloatType val) {
|
||||
typedef sprout::basic_string<Elem, sprout::printed_float_exp_digits<FloatType>::value> type;
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_exp_digits<FloatType>::value> access_type;
|
||||
return sprout::math::isinf(val) ? sprout::math::signbit(val)
|
||||
? type{{static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f')}, 4}
|
||||
: type{{static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f')}, 3}
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: sprout::math::isnan(val) ? sprout::math::signbit(val)
|
||||
? type{{static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n')}, 4}
|
||||
: type{{static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n')}, 3}
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: sprout::detail::float_to_string_exp<Elem>(
|
||||
sprout::detail::float_round_at(
|
||||
(val < 0 ? -val : val) / sprout::detail::float_pow10<FloatType>(sprout::detail::float_exponent10(val)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue