mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Corrected hex double literal parsing (although it's not 100% correct yet)
This commit is contained in:
@@ -397,6 +397,23 @@ static inline bool scan_hex(Lexer *lexer)
|
||||
while (is_digit(peek(lexer))) next(lexer);
|
||||
}
|
||||
if (prev(lexer) == '_') return add_error_token(lexer, "The number ended with '_', but that character needs to be between, not after, digits.");
|
||||
if (is_float)
|
||||
{
|
||||
// IMPROVE
|
||||
// For the float we actually parse things, using strtold
|
||||
// this is not ideal, we should try to use f128 if possible for example.
|
||||
// Possibly we should move to a BigDecimal implementation or at least a soft float 256
|
||||
// implementation for the constants.
|
||||
char *end = NULL;
|
||||
long double fval = strtold(lexer->lexing_start, &end);
|
||||
if (end != lexer->current)
|
||||
{
|
||||
return add_error_token(lexer, "Invalid float value.");
|
||||
}
|
||||
add_generic_token(lexer, TOKEN_REAL);
|
||||
lexer->latest_token_data->value = fval;
|
||||
return true;
|
||||
}
|
||||
return add_token(lexer, is_float ? TOKEN_REAL : TOKEN_INTEGER, lexer->lexing_start);
|
||||
}
|
||||
|
||||
|
||||
13
test/test_suite/expressions/parsed_numbers.c3t
Normal file
13
test/test_suite/expressions/parsed_numbers.c3t
Normal file
@@ -0,0 +1,13 @@
|
||||
module numbers;
|
||||
|
||||
double a = 0x1.1p+1;
|
||||
double b = -12.3e-12;
|
||||
double c = 0x1.1p-1;
|
||||
double d = 12.3e+12;
|
||||
|
||||
// #expect: numbers.ll
|
||||
|
||||
@numbers.a = global double 2.125000e+00, align 8
|
||||
@numbers.b = global double -1.230000e-11, align 8
|
||||
@numbers.c = global double 5.312500e-01, align 8
|
||||
@numbers.d = global double 1.230000e+13, align 8
|
||||
Reference in New Issue
Block a user