- /* If only one type is float, use its type.
- Otherwise use the bigger type. */
- if (TYPE_CODE (type1) != TYPE_CODE_FLT)
- result_type = type2;
- else if (TYPE_CODE (type2) != TYPE_CODE_FLT)
- result_type = type1;
- else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
- result_type = type2;
- else
- result_type = type1;
+ return value_from_longest (value_type (x1), v1);
+ }
+ break;
+
+ default:
+ error (_("Invalid binary operation on numbers."));
+ }
+
+ return value_literal_complex (result_real, result_imag, result_type);
+}
+
+/* Perform a binary operation on two operands which have reasonable
+ representations as integers or floats. This includes booleans,
+ characters, integers, or floats.
+ Does not support addition and subtraction on pointers;
+ use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
+
+static struct value *
+scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
+{
+ struct value *val;
+ struct type *type1, *type2, *result_type;
+
+ arg1 = coerce_ref (arg1);
+ arg2 = coerce_ref (arg2);
+
+ type1 = check_typedef (value_type (arg1));
+ type2 = check_typedef (value_type (arg2));
+
+ if (type1->code () == TYPE_CODE_COMPLEX
+ || type2->code () == TYPE_CODE_COMPLEX)
+ return complex_binop (arg1, arg2, op);
+
+ if ((!is_floating_value (arg1) && !is_integral_type (type1))
+ || (!is_floating_value (arg2) && !is_integral_type (type2)))
+ error (_("Argument to arithmetic operation not a number or boolean."));