mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
Issue #90: accept custom decimal point
This commit is contained in:
parent
3bd0c01c6c
commit
3881ea6937
@ -81,7 +81,10 @@ struct parsed_number_string {
|
|||||||
// Assuming that you use no more than 19 digits, this will
|
// Assuming that you use no more than 19 digits, this will
|
||||||
// parse an ASCII string.
|
// parse an ASCII string.
|
||||||
fastfloat_really_inline
|
fastfloat_really_inline
|
||||||
parsed_number_string parse_number_string(const char *p, const char *pend, chars_format fmt) noexcept {
|
parsed_number_string parse_number_string(const char *p, const char *pend, parse_options options) noexcept {
|
||||||
|
const chars_format fmt = options.format;
|
||||||
|
const char decimal_point = options.decimal_point;
|
||||||
|
|
||||||
parsed_number_string answer;
|
parsed_number_string answer;
|
||||||
answer.valid = false;
|
answer.valid = false;
|
||||||
answer.too_many_digits = false;
|
answer.too_many_digits = false;
|
||||||
@ -91,7 +94,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
|
|||||||
if (p == pend) {
|
if (p == pend) {
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
if (!is_integer(*p) && (*p != '.')) { // a sign must be followed by an integer or the dot
|
if (!is_integer(*p) && (*p != decimal_point)) { // a sign must be followed by an integer or the dot
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +112,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
|
|||||||
const char *const end_of_integer_part = p;
|
const char *const end_of_integer_part = p;
|
||||||
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
|
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
|
||||||
int64_t exponent = 0;
|
int64_t exponent = 0;
|
||||||
if ((p != pend) && (*p == '.')) {
|
if ((p != pend) && (*p == decimal_point)) {
|
||||||
++p;
|
++p;
|
||||||
// Fast approach only tested under little endian systems
|
// Fast approach only tested under little endian systems
|
||||||
if ((p + 8 <= pend) && is_made_of_eight_digits_fast(p)) {
|
if ((p + 8 <= pend) && is_made_of_eight_digits_fast(p)) {
|
||||||
@ -179,7 +182,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
|
|||||||
// We need to be mindful of the case where we only have zeroes...
|
// We need to be mindful of the case where we only have zeroes...
|
||||||
// E.g., 0.000000000...000.
|
// E.g., 0.000000000...000.
|
||||||
const char *start = start_digits;
|
const char *start = start_digits;
|
||||||
while ((start != pend) && (*start == '0' || *start == '.')) {
|
while ((start != pend) && (*start == '0' || *start == decimal_point)) {
|
||||||
if(*start == '0') { digit_count --; }
|
if(*start == '0') { digit_count --; }
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
@ -196,7 +199,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
|
|||||||
if (i >= minimal_nineteen_digit_integer) { // We have a big integers
|
if (i >= minimal_nineteen_digit_integer) { // We have a big integers
|
||||||
exponent = end_of_integer_part - p + exp_number;
|
exponent = end_of_integer_part - p + exp_number;
|
||||||
} else { // We have a value with a fractional component.
|
} else { // We have a value with a fractional component.
|
||||||
p++; // skip the '.'
|
p++; // skip the dot
|
||||||
const char *first_after_period = p;
|
const char *first_after_period = p;
|
||||||
while((i < minimal_nineteen_digit_integer) && (p != pend) && is_integer(*p)) {
|
while((i < minimal_nineteen_digit_integer) && (p != pend) && is_integer(*p)) {
|
||||||
i = i * 10 + uint64_t(*p - '0');
|
i = i * 10 + uint64_t(*p - '0');
|
||||||
@ -217,7 +220,9 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
|
|||||||
// This function could be optimized. In particular, we could stop after 19 digits
|
// This function could be optimized. In particular, we could stop after 19 digits
|
||||||
// and try to bail out. Furthermore, we should be able to recover the computed
|
// and try to bail out. Furthermore, we should be able to recover the computed
|
||||||
// exponent from the pass in parse_number_string.
|
// exponent from the pass in parse_number_string.
|
||||||
fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) noexcept {
|
fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend, parse_options options) noexcept {
|
||||||
|
const char decimal_point = options.decimal_point;
|
||||||
|
|
||||||
decimal answer;
|
decimal answer;
|
||||||
answer.num_digits = 0;
|
answer.num_digits = 0;
|
||||||
answer.decimal_point = 0;
|
answer.decimal_point = 0;
|
||||||
@ -237,7 +242,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
|
|||||||
answer.num_digits++;
|
answer.num_digits++;
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
if ((p != pend) && (*p == '.')) {
|
if ((p != pend) && (*p == decimal_point)) {
|
||||||
++p;
|
++p;
|
||||||
const char *first_after_period = p;
|
const char *first_after_period = p;
|
||||||
// if we have not yet encountered a zero, we have to skip it as well
|
// if we have not yet encountered a zero, we have to skip it as well
|
||||||
@ -276,7 +281,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
|
|||||||
// we have at least one non-zero digit.
|
// we have at least one non-zero digit.
|
||||||
const char *preverse = p - 1;
|
const char *preverse = p - 1;
|
||||||
int32_t trailing_zeros = 0;
|
int32_t trailing_zeros = 0;
|
||||||
while ((*preverse == '0') || (*preverse == '.')) {
|
while ((*preverse == '0') || (*preverse == decimal_point)) {
|
||||||
if(*preverse == '0') { trailing_zeros++; };
|
if(*preverse == '0') { trailing_zeros++; };
|
||||||
--preverse;
|
--preverse;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,17 @@ struct from_chars_result {
|
|||||||
std::errc ec;
|
std::errc ec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct parse_options {
|
||||||
|
explicit parse_options(chars_format fmt = chars_format::general,
|
||||||
|
char dot = '.')
|
||||||
|
: format(fmt), decimal_point(dot) {}
|
||||||
|
|
||||||
|
/** Which number formats are accepted */
|
||||||
|
chars_format format;
|
||||||
|
/** The character used as decimal point */
|
||||||
|
char decimal_point;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function parses the character sequence [first,last) for a number. It parses floating-point numbers expecting
|
* This function parses the character sequence [first,last) for a number. It parses floating-point numbers expecting
|
||||||
* a locale-indepent format equivalent to what is used by std::strtod in the default ("C") locale.
|
* a locale-indepent format equivalent to what is used by std::strtod in the default ("C") locale.
|
||||||
@ -40,6 +51,13 @@ template<typename T>
|
|||||||
from_chars_result from_chars(const char *first, const char *last,
|
from_chars_result from_chars(const char *first, const char *last,
|
||||||
T &value, chars_format fmt = chars_format::general) noexcept;
|
T &value, chars_format fmt = chars_format::general) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like from_chars, but accepts an `options` argument to govern number parsing.
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||||
|
T &value, parse_options options) noexcept;
|
||||||
|
|
||||||
}
|
}
|
||||||
#include "parse_number.h"
|
#include "parse_number.h"
|
||||||
#endif // FASTFLOAT_FAST_FLOAT_H
|
#endif // FASTFLOAT_FAST_FLOAT_H
|
||||||
|
|||||||
@ -85,6 +85,13 @@ fastfloat_really_inline void to_float(bool negative, adjusted_mantissa am, T &va
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
from_chars_result from_chars(const char *first, const char *last,
|
from_chars_result from_chars(const char *first, const char *last,
|
||||||
T &value, chars_format fmt /*= chars_format::general*/) noexcept {
|
T &value, chars_format fmt /*= chars_format::general*/) noexcept {
|
||||||
|
return from_chars_advanced(first, last, value, parse_options{fmt});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||||
|
T &value, parse_options options) noexcept {
|
||||||
|
|
||||||
static_assert (std::is_same<T, double>::value || std::is_same<T, float>::value, "only float and double are supported");
|
static_assert (std::is_same<T, double>::value || std::is_same<T, float>::value, "only float and double are supported");
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +101,7 @@ from_chars_result from_chars(const char *first, const char *last,
|
|||||||
answer.ptr = first;
|
answer.ptr = first;
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
parsed_number_string pns = parse_number_string(first, last, fmt);
|
parsed_number_string pns = parse_number_string(first, last, options);
|
||||||
if (!pns.valid) {
|
if (!pns.valid) {
|
||||||
return detail::parse_infnan(first, last, value);
|
return detail::parse_infnan(first, last, value);
|
||||||
}
|
}
|
||||||
@ -116,7 +123,7 @@ from_chars_result from_chars(const char *first, const char *last,
|
|||||||
}
|
}
|
||||||
// If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0),
|
// If we called compute_float<binary_format<T>>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0),
|
||||||
// then we need to go the long way around again. This is very uncommon.
|
// then we need to go the long way around again. This is very uncommon.
|
||||||
if(am.power2 < 0) { am = parse_long_mantissa<binary_format<T>>(first,last); }
|
if(am.power2 < 0) { am = parse_long_mantissa<binary_format<T>>(first, last, options); }
|
||||||
detail::to_float(pns.negative, am, value);
|
detail::to_float(pns.negative, am, value);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -351,8 +351,8 @@ adjusted_mantissa compute_float(decimal &d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename binary>
|
template <typename binary>
|
||||||
adjusted_mantissa parse_long_mantissa(const char *first, const char* last) {
|
adjusted_mantissa parse_long_mantissa(const char *first, const char* last, parse_options options) {
|
||||||
decimal d = parse_decimal(first, last);
|
decimal d = parse_decimal(first, last, options);
|
||||||
return compute_float<binary>(d);
|
return compute_float<binary>(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -184,6 +184,41 @@ TEST_CASE("check_behavior") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("decimal_point_parsing") {
|
||||||
|
double result;
|
||||||
|
fast_float::parse_options options{};
|
||||||
|
{
|
||||||
|
const std::string input = "1,25";
|
||||||
|
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
|
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
||||||
|
"Parsing should have stopped at comma");
|
||||||
|
CHECK_EQ(result, 1.0);
|
||||||
|
|
||||||
|
options.decimal_point = ',';
|
||||||
|
answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
|
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
||||||
|
"Parsing should have stopped at end");
|
||||||
|
CHECK_EQ(result, 1.25);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const std::string input = "1.25";
|
||||||
|
auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
|
CHECK_MESSAGE(answer.ptr == input.data() + 1,
|
||||||
|
"Parsing should have stopped at dot");
|
||||||
|
CHECK_EQ(result, 1.0);
|
||||||
|
|
||||||
|
options.decimal_point = '.';
|
||||||
|
answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options);
|
||||||
|
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
|
||||||
|
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
|
||||||
|
"Parsing should have stopped at end");
|
||||||
|
CHECK_EQ(result, 1.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("issue19") {
|
TEST_CASE("issue19") {
|
||||||
const std::string input = "3.14e";
|
const std::string input = "3.14e";
|
||||||
double result;
|
double result;
|
||||||
@ -349,20 +384,34 @@ std::string append_zeros(std::string str, size_t number_of_zeros) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void basic_test(std::string str, T expected) {
|
void check_basic_test_result(const std::string& str, fast_float::from_chars_result result,
|
||||||
T actual;
|
T actual, T expected) {
|
||||||
auto result = fast_float::from_chars(str.data(), str.data() + str.size(), actual);
|
|
||||||
INFO("str=" << str << "\n"
|
INFO("str=" << str << "\n"
|
||||||
<< " expected=" << fHexAndDec(expected) << "\n"
|
<< " expected=" << fHexAndDec(expected) << "\n"
|
||||||
<< " ..actual=" << fHexAndDec(actual) << "\n"
|
<< " ..actual=" << fHexAndDec(actual) << "\n"
|
||||||
<< " expected mantissa=" << iHexAndDec(get_mantissa(expected)) << "\n"
|
<< " expected mantissa=" << iHexAndDec(get_mantissa(expected)) << "\n"
|
||||||
<< " ..actual mantissa=" << iHexAndDec(get_mantissa(actual)));
|
<< " ..actual mantissa=" << iHexAndDec(get_mantissa(actual)));
|
||||||
CHECK_EQ(result.ec, std::errc());
|
CHECK_EQ(result.ec, std::errc());
|
||||||
|
CHECK_EQ(result.ptr, str.data() + str.size());
|
||||||
CHECK_EQ(copysign(1, actual), copysign(1, expected));
|
CHECK_EQ(copysign(1, actual), copysign(1, expected));
|
||||||
CHECK_EQ(std::isnan(actual), std::isnan(expected));
|
CHECK_EQ(std::isnan(actual), std::isnan(expected));
|
||||||
CHECK_EQ(actual, expected);
|
CHECK_EQ(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void basic_test(std::string str, T expected) {
|
||||||
|
T actual;
|
||||||
|
auto result = fast_float::from_chars(str.data(), str.data() + str.size(), actual);
|
||||||
|
check_basic_test_result(str, result, actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void basic_test(std::string str, T expected, fast_float::parse_options options) {
|
||||||
|
T actual;
|
||||||
|
auto result = fast_float::from_chars_advanced(str.data(), str.data() + str.size(), actual, options);
|
||||||
|
check_basic_test_result(str, result, actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
void basic_test(float val) {
|
void basic_test(float val) {
|
||||||
{
|
{
|
||||||
std::string long_vals = to_long_string(val);
|
std::string long_vals = to_long_string(val);
|
||||||
@ -379,6 +428,8 @@ void basic_test(float val) {
|
|||||||
#define verify(lhs, rhs) { INFO(lhs); basic_test(lhs, rhs); }
|
#define verify(lhs, rhs) { INFO(lhs); basic_test(lhs, rhs); }
|
||||||
#define verify32(val) { INFO(#val); basic_test(val); }
|
#define verify32(val) { INFO(#val); basic_test(val); }
|
||||||
|
|
||||||
|
#define verify_options(lhs, rhs) { INFO(lhs); basic_test(lhs, rhs, options); }
|
||||||
|
|
||||||
TEST_CASE("64bit.inf") {
|
TEST_CASE("64bit.inf") {
|
||||||
verify("INF", std::numeric_limits<double>::infinity());
|
verify("INF", std::numeric_limits<double>::infinity());
|
||||||
verify("-INF", -std::numeric_limits<double>::infinity());
|
verify("-INF", -std::numeric_limits<double>::infinity());
|
||||||
@ -456,6 +507,65 @@ TEST_CASE("64bit.general") {
|
|||||||
verify("1438456663141390273526118207642235581183227845246331231162636653790368152091394196930365828634687637948157940776599182791387527135353034738357134110310609455693900824193549772792016543182680519740580354365467985440183598701312257624545562331397018329928613196125590274187720073914818062530830316533158098624984118889298281371812288789537310599037529113415438738954894752124724983067241108764488346454376699018673078404751121414804937224240805993123816932326223683090770561597570457793932985826162604255884529134126396282202126526253389383421806727954588525596114379801269094096329805054803089299736996870951258573010877404407451953846698609198213926882692078557033228265259305481198526059813164469187586693257335779522020407645498684263339921905227556616698129967412891282231685504660671277927198290009824680186319750978665734576683784255802269708917361719466043175201158849097881370477111850171579869056016061666173029059588433776015644439705050377554277696143928278093453792803846252715966016733222646442382892123940052441346822429721593884378212558701004356924243030059517489346646577724622498919752597382095222500311124181823512251071356181769376577651390028297796156208815375089159128394945710515861334486267101797497111125909272505194792870889617179758703442608016143343262159998149700606597792535574457560429226974273443630323818747730771316763398572110874959981923732463076884528677392654150010269822239401993427482376513231389212353583573566376915572650916866553612366187378959554983566712767093372906030188976220169058025354973622211666504549316958271880975697143546564469806791358707318873075708383345004090151974068325838177531266954177406661392229801349994695941509935655355652985723782153570084089560139142231.738475042362596875449154552392299548947138162081694168675340677843807613129780449323363759027012972466987370921816813162658754726545121090545507240267000456594786540949605260722461937870630634874991729398208026467698131898691830012167897399682179601734569071423681e-733", std::numeric_limits<double>::infinity());
|
verify("1438456663141390273526118207642235581183227845246331231162636653790368152091394196930365828634687637948157940776599182791387527135353034738357134110310609455693900824193549772792016543182680519740580354365467985440183598701312257624545562331397018329928613196125590274187720073914818062530830316533158098624984118889298281371812288789537310599037529113415438738954894752124724983067241108764488346454376699018673078404751121414804937224240805993123816932326223683090770561597570457793932985826162604255884529134126396282202126526253389383421806727954588525596114379801269094096329805054803089299736996870951258573010877404407451953846698609198213926882692078557033228265259305481198526059813164469187586693257335779522020407645498684263339921905227556616698129967412891282231685504660671277927198290009824680186319750978665734576683784255802269708917361719466043175201158849097881370477111850171579869056016061666173029059588433776015644439705050377554277696143928278093453792803846252715966016733222646442382892123940052441346822429721593884378212558701004356924243030059517489346646577724622498919752597382095222500311124181823512251071356181769376577651390028297796156208815375089159128394945710515861334486267101797497111125909272505194792870889617179758703442608016143343262159998149700606597792535574457560429226974273443630323818747730771316763398572110874959981923732463076884528677392654150010269822239401993427482376513231389212353583573566376915572650916866553612366187378959554983566712767093372906030188976220169058025354973622211666504549316958271880975697143546564469806791358707318873075708383345004090151974068325838177531266954177406661392229801349994695941509935655355652985723782153570084089560139142231.738475042362596875449154552392299548947138162081694168675340677843807613129780449323363759027012972466987370921816813162658754726545121090545507240267000456594786540949605260722461937870630634874991729398208026467698131898691830012167897399682179601734569071423681e-733", std::numeric_limits<double>::infinity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("64bit.decimal_point") {
|
||||||
|
fast_float::parse_options options{};
|
||||||
|
options.decimal_point = ',';
|
||||||
|
|
||||||
|
// infinities
|
||||||
|
verify_options("1,8e308", std::numeric_limits<double>::infinity());
|
||||||
|
verify_options("1,832312213213213232132132143451234453123412321321312e308", std::numeric_limits<double>::infinity());
|
||||||
|
verify_options("2e30000000000000000", std::numeric_limits<double>::infinity());
|
||||||
|
verify_options("2e3000", std::numeric_limits<double>::infinity());
|
||||||
|
verify_options("1,9e308", std::numeric_limits<double>::infinity());
|
||||||
|
|
||||||
|
// finites
|
||||||
|
verify_options("-2,2222222222223e-322",-0x1.68p-1069);
|
||||||
|
verify_options("9007199254740993,0", 0x1p+53);
|
||||||
|
verify_options("860228122,6654514319E+90", 0x1.92bb20990715fp+328);
|
||||||
|
verify_options(append_zeros("9007199254740993,0",1000), 0x1p+53);
|
||||||
|
verify_options("1,1920928955078125e-07", 1.1920928955078125e-07);
|
||||||
|
verify_options("9355950000000000000,00000000000000000000000000000000001844674407370955161600000184467440737095516161844674407370955161407370955161618446744073709551616000184467440737095516166000001844674407370955161618446744073709551614073709551616184467440737095516160001844674407370955161601844674407370955674451616184467440737095516140737095516161844674407370955161600018446744073709551616018446744073709551611616000184467440737095001844674407370955161600184467440737095516160018446744073709551168164467440737095516160001844073709551616018446744073709551616184467440737095516160001844674407536910751601611616000184467440737095001844674407370955161600184467440737095516160018446744073709551616184467440737095516160001844955161618446744073709551616000184467440753691075160018446744073709",0x1.03ae05e8fca1cp+63);
|
||||||
|
verify_options("2,22507385850720212418870147920222032907240528279439037814303133837435107319244194686754406432563881851382188218502438069999947733013005649884107791928741341929297200970481951993067993290969042784064731682041565926728632933630474670123316852983422152744517260835859654566319282835244787787799894310779783833699159288594555213714181128458251145584319223079897504395086859412457230891738946169368372321191373658977977723286698840356390251044443035457396733706583981055420456693824658413747607155981176573877626747665912387199931904006317334709003012790188175203447190250028061277777916798391090578584006464715943810511489154282775041174682194133952466682503431306181587829379004205392375072083366693241580002758391118854188641513168478436313080237596295773983001708984375e-308", 0x1.0000000000002p-1022);
|
||||||
|
verify_options("1,0000000000000006661338147750939242541790008544921875",1.0000000000000007);
|
||||||
|
verify_options("2,2250738585072013e-308", 2.2250738585072013e-308);
|
||||||
|
verify_options("1,00000000000000188558920870223463870174566020691753515394643550663070558368373221972569761144603605635692374830246134201063722058e-309", 1.00000000000000188558920870223463870174566020691753515394643550663070558368373221972569761144603605635692374830246134201063722058e-309);
|
||||||
|
verify_options("-2402844368454405395,2", -2402844368454405395.2);
|
||||||
|
verify_options("2402844368454405395,2", 2402844368454405395.2);
|
||||||
|
verify_options("7,0420557077594588669468784357561207962098443483187940792729600000e+59", 7.0420557077594588669468784357561207962098443483187940792729600000e+59);
|
||||||
|
verify_options("7,0420557077594588669468784357561207962098443483187940792729600000e+59", 7.0420557077594588669468784357561207962098443483187940792729600000e+59);
|
||||||
|
verify_options("-1,7339253062092163730578609458683877051596800000000000000000000000e+42", -1.7339253062092163730578609458683877051596800000000000000000000000e+42);
|
||||||
|
verify_options("-2,0972622234386619214559824785284023792871122537545728000000000000e+52", -2.0972622234386619214559824785284023792871122537545728000000000000e+52);
|
||||||
|
verify_options("-1,0001803374372191849407179462120053338028379051879898808320000000e+57", -1.0001803374372191849407179462120053338028379051879898808320000000e+57);
|
||||||
|
verify_options("-1,8607245283054342363818436991534856973992070520151142825984000000e+58", -1.8607245283054342363818436991534856973992070520151142825984000000e+58);
|
||||||
|
verify_options("-1,9189205311132686907264385602245237137907390376574976000000000000e+52", -1.9189205311132686907264385602245237137907390376574976000000000000e+52);
|
||||||
|
verify_options("-2,8184483231688951563253238886553506793085187889855201280000000000e+54", -2.8184483231688951563253238886553506793085187889855201280000000000e+54);
|
||||||
|
verify_options("-1,7664960224650106892054063261344555646357024359107788800000000000e+53", -1.7664960224650106892054063261344555646357024359107788800000000000e+53);
|
||||||
|
verify_options("-2,1470977154320536489471030463761883783915110400000000000000000000e+45", -2.1470977154320536489471030463761883783915110400000000000000000000e+45);
|
||||||
|
verify_options("-4,4900312744003159009338275160799498340862630046359789166919680000e+61", -4.4900312744003159009338275160799498340862630046359789166919680000e+61);
|
||||||
|
verify_options("1", 1.0);
|
||||||
|
verify_options("1,797693134862315700000000000000001e308", 1.7976931348623157e308);
|
||||||
|
verify_options("3e-324", 0x0.0000000000001p-1022);
|
||||||
|
verify_options("1,00000006e+09", 0x1.dcd651ep+29);
|
||||||
|
verify_options("4,9406564584124653e-324", 0x0.0000000000001p-1022);
|
||||||
|
verify_options("4,9406564584124654e-324", 0x0.0000000000001p-1022);
|
||||||
|
verify_options("2,2250738585072009e-308", 0x0.fffffffffffffp-1022);
|
||||||
|
verify_options("2,2250738585072014e-308", 0x1p-1022);
|
||||||
|
verify_options("1,7976931348623157e308", 0x1.fffffffffffffp+1023);
|
||||||
|
verify_options("1,7976931348623158e308", 0x1.fffffffffffffp+1023);
|
||||||
|
verify_options("4503599627370496,5", 4503599627370496.5);
|
||||||
|
verify_options("4503599627475352,5", 4503599627475352.5);
|
||||||
|
verify_options("4503599627475353,5", 4503599627475353.5);
|
||||||
|
verify_options("2251799813685248,25", 2251799813685248.25);
|
||||||
|
verify_options("1125899906842624,125", 1125899906842624.125);
|
||||||
|
verify_options("1125899906842901,875", 1125899906842901.875);
|
||||||
|
verify_options("2251799813685803,75", 2251799813685803.75);
|
||||||
|
verify_options("4503599627370497,5", 4503599627370497.5);
|
||||||
|
verify_options("45035996,273704995", 45035996.273704995);
|
||||||
|
verify_options("45035996,273704985", 45035996.273704985);
|
||||||
|
verify_options("0,000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044501477170144022721148195934182639518696390927032912960468522194496444440421538910330590478162701758282983178260792422137401728773891892910553144148156412434867599762821265346585071045737627442980259622449029037796981144446145705102663115100318287949527959668236039986479250965780342141637013812613333119898765515451440315261253813266652951306000184917766328660755595837392240989947807556594098101021612198814605258742579179000071675999344145086087205681577915435923018910334964869420614052182892431445797605163650903606514140377217442262561590244668525767372446430075513332450079650686719491377688478005309963967709758965844137894433796621993967316936280457084866613206797017728916080020698679408551343728867675409720757232455434770912461317493580281734466552734375", 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044501477170144022721148195934182639518696390927032912960468522194496444440421538910330590478162701758282983178260792422137401728773891892910553144148156412434867599762821265346585071045737627442980259622449029037796981144446145705102663115100318287949527959668236039986479250965780342141637013812613333119898765515451440315261253813266652951306000184917766328660755595837392240989947807556594098101021612198814605258742579179000071675999344145086087205681577915435923018910334964869420614052182892431445797605163650903606514140377217442262561590244668525767372446430075513332450079650686719491377688478005309963967709758965844137894433796621993967316936280457084866613206797017728916080020698679408551343728867675409720757232455434770912461317493580281734466552734375);
|
||||||
|
verify_options("0,000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022250738585072008890245868760858598876504231122409594654935248025624400092282356951787758888037591552642309780950434312085877387158357291821993020294379224223559819827501242041788969571311791082261043971979604000454897391938079198936081525613113376149842043271751033627391549782731594143828136275113838604094249464942286316695429105080201815926642134996606517803095075913058719846423906068637102005108723282784678843631944515866135041223479014792369585208321597621066375401613736583044193603714778355306682834535634005074073040135602968046375918583163124224521599262546494300836851861719422417646455137135420132217031370496583210154654068035397417906022589503023501937519773030945763173210852507299305089761582519159720757232455434770912461317493580281734466552734375", 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022250738585072008890245868760858598876504231122409594654935248025624400092282356951787758888037591552642309780950434312085877387158357291821993020294379224223559819827501242041788969571311791082261043971979604000454897391938079198936081525613113376149842043271751033627391549782731594143828136275113838604094249464942286316695429105080201815926642134996606517803095075913058719846423906068637102005108723282784678843631944515866135041223479014792369585208321597621066375401613736583044193603714778355306682834535634005074073040135602968046375918583163124224521599262546494300836851861719422417646455137135420132217031370496583210154654068035397417906022589503023501937519773030945763173210852507299305089761582519159720757232455434770912461317493580281734466552734375);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("32bit.inf") {
|
TEST_CASE("32bit.inf") {
|
||||||
verify("INF", std::numeric_limits<float>::infinity());
|
verify("INF", std::numeric_limits<float>::infinity());
|
||||||
@ -546,3 +656,43 @@ TEST_CASE("32bit.general") {
|
|||||||
verify("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875f);
|
verify("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875f);
|
||||||
verify("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875f);
|
verify("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("32bit.decimal_point") {
|
||||||
|
fast_float::parse_options options{};
|
||||||
|
options.decimal_point = ',';
|
||||||
|
|
||||||
|
// infinity
|
||||||
|
verify_options("3,5028234666e38", std::numeric_limits<float>::infinity());
|
||||||
|
|
||||||
|
// finites
|
||||||
|
verify_options("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125", 0x1.2ced3p+0f);
|
||||||
|
verify_options("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125e-38", 0x1.fffff8p-127f);
|
||||||
|
verify_options(append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",655), 0x1.2ced3p+0f);
|
||||||
|
verify_options(append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",656), 0x1.2ced3p+0f);
|
||||||
|
verify_options(append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",1000), 0x1.2ced3p+0f);
|
||||||
|
std::string test_string;
|
||||||
|
test_string = append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",655) + std::string("e-38");
|
||||||
|
verify_options(test_string, 0x1.fffff8p-127f);
|
||||||
|
test_string = append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",656) + std::string("e-38");
|
||||||
|
verify_options(test_string, 0x1.fffff8p-127f);
|
||||||
|
test_string = append_zeros("1,1754941406275178592461758986628081843312458647327962400313859427181746759860647699724722770042717456817626953125",1000) + std::string("e-38");
|
||||||
|
verify_options(test_string, 0x1.fffff8p-127f);
|
||||||
|
verify_options("1,1754943508e-38", 1.1754943508e-38f);
|
||||||
|
verify_options("30219,0830078125", 30219.0830078125f);
|
||||||
|
verify_options("1,1754947011469036e-38", 0x1.000006p-126f);
|
||||||
|
verify_options("7,0064923216240854e-46", 0x1p-149f);
|
||||||
|
verify_options("8388614,5", 8388614.5f);
|
||||||
|
verify_options("0e9999999999999999999999999999", 0.f);
|
||||||
|
verify_options("4,7019774032891500318749461488889827112746622270883500860350068251e-38",4.7019774032891500318749461488889827112746622270883500860350068251e-38f);
|
||||||
|
verify_options("3,1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679", 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679f);
|
||||||
|
verify_options("2,3509887016445750159374730744444913556373311135441750430175034126e-38", 2.3509887016445750159374730744444913556373311135441750430175034126e-38f);
|
||||||
|
verify_options("1", 1.f);
|
||||||
|
verify_options("7,0060e-46", 0.f);
|
||||||
|
verify_options("3,4028234664e38", 0x1.fffffep+127f);
|
||||||
|
verify_options("3,4028234665e38", 0x1.fffffep+127f);
|
||||||
|
verify_options("3,4028234666e38", 0x1.fffffep+127f);
|
||||||
|
verify_options("0,000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625", 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625);
|
||||||
|
verify_options("0,00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125f);
|
||||||
|
verify_options("0,00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875f);
|
||||||
|
verify_options("0,00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875f);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user