/* PBXB64 C frontend: exercise complex-number value lowering
 * (c_frontend_lexer_value.c: c_value_to_ir, c_complex_parts_from_value,
 * c_emit_complex_temp, c_emit_complex_binary, c_emit_complex_extract_part).
 */

int main(void)
{
    float _Complex fc = __builtin_complex(3.0f, 4.0f);
    double _Complex dc = __builtin_complex(1.0, 2.0);

    /* complex addition and multiplication */
    double _Complex sum = dc + __builtin_complex(2.0, 3.0);
    double _Complex prod = dc * __builtin_complex(2.0, 0.0);

    double r = creal(sum);
    double i = cimag(sum);

    if (r != 3.0) return 1;
    if (i != 5.0) return 2;

    if (creal(prod) != 2.0) return 3;
    if (cimag(prod) != 4.0) return 4;

    /* scalar-to-complex conversion through c_complex_parts_from_value */
    double _Complex from_real = __builtin_complex(7.0, 0.0);
    if (creal(from_real) != 7.0) return 5;

    (void)fc;
    return 0;
}
