mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add d as floating point suffix for double types.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
- Allow the use of `has_tagof` on builtin types.
|
||||
- `@jump` now included in `--list-attributes` #2155.
|
||||
- Add `$$matrix_mul` and `$$matrix_transpose` builtins.
|
||||
- Add `d` as floating point suffix for `double` types.
|
||||
|
||||
### Fixes
|
||||
- Assert triggered when casting from `int[2]` to `uint[2]` #2115
|
||||
|
||||
@@ -23,7 +23,7 @@ P [Pp][+-]?{D}+
|
||||
B64 [ \t\v\n\f]?[A-Za-z0-9+/][ \t\v\n\fA-Za-z0-9+/=]+
|
||||
HEX [ \t\v\n\f]?[A-Fa-f0-9][ \t\v\n\fA-Fa-f0-9]+
|
||||
INTTYPE ([ui](8|16|32|64|128)|[Uu][Ll]?|[Ll])
|
||||
REALTYPE ([f](8|16|32|64|128)?)
|
||||
REALTYPE ([fd])
|
||||
INT {D}(_?{D})*
|
||||
HINT {H}(_?{H})*
|
||||
OINT {O}(_?{O})*
|
||||
|
||||
@@ -100,6 +100,7 @@ Float float_neg(Float op)
|
||||
static char *err_invalid_float_width = "The float width is not valid, it must be one of 16, 32, 64 and 128.";
|
||||
static char *err_float_out_of_range = "The float value is out of range.";
|
||||
static char *err_float_format_invalid = "The float format is invalid.";
|
||||
static char *err_hex_float_format_invalid = "Hex floating points must end with 'p' or 'P' and a valid exponent, e.g. 0x1.0p10 or 0x1.0P10.";
|
||||
|
||||
TypeKind float_suffix(char c, const char **index_ref, char** error_ref)
|
||||
{
|
||||
@@ -108,6 +109,7 @@ TypeKind float_suffix(char c, const char **index_ref, char** error_ref)
|
||||
(*index_ref) += 4;
|
||||
return TYPE_BF16;
|
||||
}
|
||||
if (c == 'd') return TYPE_F64;
|
||||
if (c == 'f')
|
||||
{
|
||||
int i = 0;
|
||||
@@ -226,19 +228,21 @@ Float float_from_hex(const char *string, char **error)
|
||||
scratch_buffer_append_char(c);
|
||||
}
|
||||
}
|
||||
if (c == 'p' || c == 'P')
|
||||
if (c != 'p' && c != 'P')
|
||||
{
|
||||
*error = err_hex_float_format_invalid;
|
||||
return (Float){ .type = TYPE_POISONED };
|
||||
}
|
||||
scratch_buffer_append_char(c);
|
||||
if (*index == '-')
|
||||
{
|
||||
scratch_buffer_append_char('-');
|
||||
index++;
|
||||
}
|
||||
else if (*index == '+') index++;
|
||||
while ((c = *(index++)) && (c >= '0' && c <= '9'))
|
||||
{
|
||||
scratch_buffer_append_char(c);
|
||||
if (*index == '-')
|
||||
{
|
||||
scratch_buffer_append_char('-');
|
||||
index++;
|
||||
}
|
||||
else if (*index == '+') index++;
|
||||
while ((c = *(index++)) && (c >= '0' && c <= '9'))
|
||||
{
|
||||
scratch_buffer_append_char(c);
|
||||
}
|
||||
}
|
||||
TypeKind kind = float_suffix(c, &index, error);
|
||||
if (kind == TYPE_POISONED) return (Float){ .type = TYPE_POISONED };
|
||||
|
||||
@@ -408,6 +408,10 @@ static bool scan_number_suffix(Lexer *lexer, bool *is_float)
|
||||
next(lexer);
|
||||
while (char_is_digit(c = peek(lexer))) next(lexer);
|
||||
break;
|
||||
case 'd':
|
||||
c = next(lexer);
|
||||
*is_float = true;
|
||||
break;
|
||||
case 'f':
|
||||
next(lexer);
|
||||
*is_float = true;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
uint f0 = $typeof(1.0f).sizeof;
|
||||
uint f32 = $typeof(1.0f32).sizeof;
|
||||
uint f64 = $typeof(1.0f64).sizeof;
|
||||
uint f32 = $typeof(1.0f).sizeof;
|
||||
uint f64 = $typeof(1.0d).sizeof;
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
|
||||
1
test/test_suite/floats/double_float.c3
Normal file
1
test/test_suite/floats/double_float.c3
Normal file
@@ -0,0 +1 @@
|
||||
int x = 5d; // #error: 'double' cannot implicitly be converted to 'int'
|
||||
1
test/test_suite/floats/hex_floats_malformed.c3
Normal file
1
test/test_suite/floats/hex_floats_malformed.c3
Normal file
@@ -0,0 +1 @@
|
||||
double x = 0x12.00; // #error: must end with 'p' or 'P'
|
||||
Reference in New Issue
Block a user