3.2.4.5 Binary Operations

C++ Function: gccjit::rvalue gccjit::context::new_binary_op (enum gcc_jit_binary_op, gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)

Build a binary operation out of two constituent rvalues.

Parameter loc is optional.

This is a thin wrapper around the C API’s gcc_jit_context_new_binary_op() and the available binary operations are documented there.

There are shorter ways to spell the various specific kinds of binary operation:

C++ Function: gccjit::rvalue gccjit::context::new_plus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_mult (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_divide (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_modulo (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_bitwise_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_bitwise_xor (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_bitwise_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_logical_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)
C++ Function: gccjit::rvalue gccjit::context::new_logical_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc)

The most concise way to spell them is with overloaded operators:

C++ Function: gccjit::rvalue operator+ (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue sum = a + b;
C++ Function: gccjit::rvalue operator- (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue diff = a - b;
C++ Function: gccjit::rvalue operator* (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue prod = a * b;
C++ Function: gccjit::rvalue operator/ (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue result = a / b;
C++ Function: gccjit::rvalue operator% (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue mod = a % b;
C++ Function: gccjit::rvalue operator& (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue x = a & b;
C++ Function: gccjit::rvalue operator^ (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue x = a ^ b;
C++ Function: gccjit::rvalue operator| (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue x = a | b;
C++ Function: gccjit::rvalue operator&& (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue cond = a && b;
C++ Function: gccjit::rvalue operator|| (gccjit::rvalue a, gccjit::rvalue b)
gccjit::rvalue cond = a || b;

These can of course be combined, giving a terse way to build compound expressions:

gccjit::rvalue discriminant = (b * b) - (four * a * c);