[number] Turn hb_parse_float into hb_parse_double

This commit is contained in:
Ebrahim Byagowi 2019-09-04 01:20:50 +04:30
parent 65690b5a4b
commit 57f88e11d4
4 changed files with 37 additions and 33 deletions

View File

@ -991,7 +991,11 @@ static bool
parse_variation_value (const char **pp, const char *end, hb_variation_t *variation)
{
parse_char (pp, end, '='); /* Optional. */
return hb_parse_float (pp, end, &variation->value);
double v;
if (unlikely (!hb_parse_double (pp, end, &v))) return false;
variation->value = v;
return true;
}
static bool

View File

@ -131,10 +131,10 @@ get_C_locale ()
#endif /* USE_XLOCALE */
bool
hb_parse_float (const char **pp, const char *end, float *pv,
hb_parse_double (const char **pp, const char *end, double *pv,
bool whole_buffer)
{
return _parse_number<float> (pp, end, pv, whole_buffer,
return _parse_number<double> (pp, end, pv, whole_buffer,
[] (const char *p, char **end)
{
#ifdef USE_XLOCALE

View File

@ -35,7 +35,7 @@ hb_parse_uint (const char **pp, const char *end, unsigned int *pv,
bool whole_buffer = false, int base = 10);
HB_INTERNAL bool
hb_parse_float (const char **pp, const char *end, float *pv,
hb_parse_double (const char **pp, const char *end, double *pv,
bool whole_buffer = false);
#endif /* HB_NUMBER_HH */

View File

@ -140,9 +140,9 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str);
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == 123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == 123);
assert (pp - str == 4);
assert (end - pp == 1);
}
@ -152,9 +152,9 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == 123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == 123);
assert (pp - str == 5);
assert (end - pp == 0);
}
@ -164,9 +164,9 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == 123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == 123);
assert (pp - str == 7);
assert (end - pp == 0);
}
@ -176,9 +176,9 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == 123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == 123);
assert (pp - str == 6);
assert (end - pp == 0);
}
@ -188,9 +188,9 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == 123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == 123);
assert (pp - str == 10);
assert (end - pp == 0);
}
@ -200,21 +200,21 @@ main (int argc, char **argv)
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == -123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == -123);
assert (pp - str == 13);
assert (end - pp == 0);
}
{
const char str[] = "-1.23e-1";
const char str[] = "-1.23E-1";
const char *pp = str;
const char *end = str + ARRAY_LENGTH (str) - 1;
float pv;
assert (hb_parse_float (&pp, end, &pv));
assert ((int) (pv * 1000.f) == -123);
double pv;
assert (hb_parse_double (&pp, end, &pv));
assert ((int) (pv * 1000.) == -123);
assert (pp - str == 8);
assert (end - pp == 0);
}