Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with radix char different from "." (#1326108) #11

Merged
merged 2 commits into from
Apr 26, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Neutralize the radix char before passing string to MPFR (#1326108)
It doesn't really understand locales and doesn't play with different radix chars
well.
  • Loading branch information
vpodzime committed Apr 22, 2016
commit db18fc88ead68c0c2731d3ff95009f0724b75f86
22 changes: 18 additions & 4 deletions src/bs_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,24 @@ BSSize bs_size_mul_float_str (const BSSize size, const char *float_str, BSError
mpf_t op1, op2;
int status = 0;
BSSize ret = NULL;
const char *radix_char = NULL;
char *loc_float_str = NULL;

radix_char = nl_langinfo (RADIXCHAR);

mpf_init2 (op1, BS_FLOAT_PREC_BITS);
mpf_init2 (op2, BS_FLOAT_PREC_BITS);

mpf_set_z (op1, size->bytes);
status = mpf_set_str (op2, float_str, 10);
loc_float_str = replace_char_with_str (float_str, '.', radix_char);
status = mpf_set_str (op2, loc_float_str, 10);
if (status != 0) {
set_error (error, BS_ERROR_INVALID_SPEC, strdup_printf ("'%s' is not a valid floating point number string", float_str));
set_error (error, BS_ERROR_INVALID_SPEC, strdup_printf ("'%s' is not a valid floating point number string", loc_float_str));
free (loc_float_str);
mpf_clears (op1, op2, NULL);
return NULL;
}
free (loc_float_str);

mpf_mul (op1, op1, op2);

Expand All @@ -784,17 +791,24 @@ BSSize bs_size_mul_float_str (const BSSize size, const char *float_str, BSError
BSSize bs_size_grow_mul_float_str (BSSize size, const char *float_str, BSError **error) {
mpf_t op1, op2;
int status = 0;
const char *radix_char = NULL;
char *loc_float_str = NULL;

radix_char = nl_langinfo (RADIXCHAR);

mpf_init2 (op1, BS_FLOAT_PREC_BITS);
mpf_init2 (op2, BS_FLOAT_PREC_BITS);

mpf_set_z (op1, size->bytes);
status = mpf_set_str (op2, float_str, 10);
loc_float_str = replace_char_with_str (float_str, '.', radix_char);
status = mpf_set_str (op2, loc_float_str, 10);
if (status != 0) {
set_error (error, BS_ERROR_INVALID_SPEC, strdup_printf ("'%s' is not a valid floating point number string", float_str));
set_error (error, BS_ERROR_INVALID_SPEC, strdup_printf ("'%s' is not a valid floating point number string", loc_float_str));
free (loc_float_str);
mpf_clears (op1, op2, NULL);
return NULL;
}
free (loc_float_str);

mpf_mul (op1, op1, op2);

Expand Down