@@ -35,6 +35,8 @@ int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base)
3535 int64_t i64 ;
3636 uint64_t ui64 ;
3737 double d ;
38+ float f ;
39+
3840 if (* tok == '\0' )
3941 return 0 ;
4042 if (!((tok [0 ]== '0' && tok [1 ]== 'x' ) || (base >= 15 )) &&
@@ -44,11 +46,15 @@ int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base)
4446 if (pval ) * pval = mk_double (fl_ctx , d );
4547 return 1 ;
4648 }
49+
50+ // NOTE(#49689): DO NOT convert double to float directly,
51+ // indirect conversion (string->double->float) will lose precision.
52+ f = jl_strtof_c (tok , & end );
4753 // floats can end in f or f0
4854 if (end > tok && end [0 ] == 'f' &&
4955 (end [1 ] == '\0' ||
5056 (end [1 ] == '0' && end [2 ] == '\0' ))) {
51- if (pval ) * pval = mk_float (fl_ctx , ( float ) d );
57+ if (pval ) * pval = mk_float (fl_ctx , f );
5258 return 1 ;
5359 }
5460 }
@@ -60,11 +66,15 @@ int isnumtok_base(fl_context_t *fl_ctx, char *tok, value_t *pval, int base)
6066 if (pval ) * pval = mk_double (fl_ctx , d );
6167 return 1 ;
6268 }
69+
70+ // NOTE(#49689): DO NOT convert double to float directly,
71+ // indirect conversion (string->double->float) will lose precision.
72+ f = jl_strtof_c (tok , & end );
6373 // floats can end in f or f0
6474 if (end > tok && end [0 ] == 'f' &&
6575 (end [1 ] == '\0' ||
6676 (end [1 ] == '0' && end [2 ] == '\0' ))) {
67- if (pval ) * pval = mk_float (fl_ctx , ( float ) d );
77+ if (pval ) * pval = mk_float (fl_ctx , f );
6878 return 1 ;
6979 }
7080 }
0 commit comments