Skip to content

Conversation

toughengineer
Copy link
Contributor

@toughengineer toughengineer commented Sep 18, 2025

Since the question was raised in #320, I added template overloads for integer_times_pow10().

Usage:

const auto a = fast_float::integer_times_pow10(23, 42); // a is a double
const auto d = fast_float::integer_times_pow10<double>(23, 42); // d is a double
const auto f = fast_float::integer_times_pow10<float>(23, 42); // f is a float

Things to pay attention to:

  • please see comments in files.

Will add some docs to README later.

*/
template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda ugly, an option is to add a macro similar to FASTFLOAT_ENABLE_IF along the lines of

#define FASTFLOAT_ENABLE_IF_T(T, ...) typename std::enable_if<(__VA_ARGS__), T>::type

Then even the macro FASTFLOAT_ENABLE_IF can be reimplemented (DRY and whatnot):

#define FASTFLOAT_ENABLE_IF(...) FASTFLOAT_ENABLE_IF_T(int, __VA_ARGS__)

verify("3.5028234666e38", std::numeric_limits<float>::infinity(),
std::errc::result_out_of_range);
// FLT_MAX + 0.00000007e38
verify("3.40282357e38", std::numeric_limits<float>::infinity(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this, but, apparently, to really overflow FLT_MAX, +0.00000001e38 (i.e. seven zeros and one after the decimal point) is not enough.
I verified this with a different implementation and it seems to be correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant