Skip to content

Commit

Permalink
flisp: sunk jl_strtof_c inside the conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
inkydragon committed May 10, 2023
1 parent 322ce2d commit 28a4c42
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/flisp/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base)
return 1;
}

// NOTE(#49689): DO NOT convert double to float directly,
// indirect conversion (string->double->float) will lose precision.
f = jl_strtof_c(tok, &end);
// floats can end in f or f0
if (end > tok && end[0] == 'f' &&
(end[1] == '\0' ||
(end[1] == '0' && end[2] == '\0'))) {
if (pval) *pval = mk_float(fl_ctx, f);
if (pval) {
// NOTE(#49689): DO NOT convert double to float directly,
// indirect conversion (string->double->float) will lose precision.
f = jl_strtof_c(tok, &end);
*pval = mk_float(fl_ctx, f);
}
return 1;
}
}
Expand All @@ -67,14 +69,16 @@ int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base)
return 1;
}

// NOTE(#49689): DO NOT convert double to float directly,
// indirect conversion (string->double->float) will lose precision.
f = jl_strtof_c(tok, &end);
// floats can end in f or f0
if (end > tok && end[0] == 'f' &&
(end[1] == '\0' ||
(end[1] == '0' && end[2] == '\0'))) {
if (pval) *pval = mk_float(fl_ctx, f);
if (pval) {
// NOTE(#49689): DO NOT convert double to float directly,
// indirect conversion (string->double->float) will lose precision.
f = jl_strtof_c(tok, &end);
*pval = mk_float(fl_ctx, f);
}
return 1;
}
}
Expand Down

0 comments on commit 28a4c42

Please sign in to comment.