diff options
| author | gingerBill <bill@gingerbill.org> | 2021-12-31 22:54:12 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-12-31 22:54:12 +0000 |
| commit | bdf66bb1e1096690be66eda90b35c6cfdc8a5cf0 (patch) | |
| tree | 9860325658cd5a80b1b09a681dcd1c4fa02509fc | |
| parent | 9b5cfe2677be92b0455af1d8e517821b28b7c7c8 (diff) | |
Correct `abs` type behaviour for quaternions
| -rw-r--r-- | src/check_builtin.cpp | 13 | ||||
| -rw-r--r-- | src/types.cpp | 7 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index f93cf9886..dc8c209c9 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1858,7 +1858,14 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 f64 r = operand->value.value_complex->real; f64 i = operand->value.value_complex->imag; operand->value = exact_value_float(gb_sqrt(r*r + i*i)); - + break; + } + case ExactValue_Quaternion: { + f64 r = operand->value.value_quaternion->real; + f64 i = operand->value.value_quaternion->imag; + f64 j = operand->value.value_quaternion->jmag; + f64 k = operand->value.value_quaternion->kmag; + operand->value = exact_value_float(gb_sqrt(r*r + i*i + j*j + k*k)); break; } default: @@ -1877,10 +1884,10 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } } - if (is_type_complex(operand->type)) { + if (is_type_complex_or_quaternion(operand->type)) { operand->type = base_complex_elem_type(operand->type); } - GB_ASSERT(!is_type_complex(operand->type)); + GB_ASSERT(!is_type_complex_or_quaternion(operand->type)); break; } diff --git a/src/types.cpp b/src/types.cpp index 2b7ea93dc..f621d4346 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1253,6 +1253,13 @@ bool is_type_quaternion(Type *t) { } return false; } +bool is_type_complex_or_quaternion(Type *t) { + t = core_type(t); + if (t->kind == Type_Basic) { + return (t->Basic.flags & (BasicFlag_Complex|BasicFlag_Quaternion)) != 0; + } + return false; +} bool is_type_f16(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { |