+/* Integer exponentiation: V1**V2, where both arguments are
+ integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
+static ULONGEST
+uinteger_pow (ULONGEST v1, LONGEST v2)
+{
+ if (v2 < 0)
+ {
+ if (v1 == 0)
+ error (_("Attempt to raise 0 to negative power."));
+ else
+ return 0;
+ }
+ else
+ {
+ /* The Russian Peasant's Algorithm */
+ ULONGEST v;
+
+ v = 1;
+ for (;;)
+ {
+ if (v2 & 1L)
+ v *= v1;
+ v2 >>= 1;
+ if (v2 == 0)
+ return v;
+ v1 *= v1;
+ }
+ }
+}
+
+/* Obtain decimal value of arguments for binary operation, converting from
+ other types if one of them is not decimal floating point. */
+static void
+value_args_as_decimal (struct value *arg1, struct value *arg2,
+ gdb_byte *x, int *len_x, enum bfd_endian *byte_order_x,
+ gdb_byte *y, int *len_y, enum bfd_endian *byte_order_y)
+{
+ struct type *type1, *type2;
+
+ type1 = check_typedef (value_type (arg1));
+ type2 = check_typedef (value_type (arg2));
+
+ /* At least one of the arguments must be of decimal float type. */
+ gdb_assert (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
+ || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT);
+
+ if (TYPE_CODE (type1) == TYPE_CODE_FLT
+ || TYPE_CODE (type2) == TYPE_CODE_FLT)
+ /* The DFP extension to the C language does not allow mixing of
+ * decimal float types with other float types in expressions
+ * (see WDTR 24732, page 12). */
+ error (_("Mixing decimal floating types with other floating types is not allowed."));
+
+ /* Obtain decimal value of arg1, converting from other types
+ if necessary. */
+
+ if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
+ {
+ *byte_order_x = gdbarch_byte_order (get_type_arch (type1));
+ *len_x = TYPE_LENGTH (type1);
+ memcpy (x, value_contents (arg1), *len_x);
+ }
+ else if (is_integral_type (type1))
+ {
+ *byte_order_x = gdbarch_byte_order (get_type_arch (type2));
+ *len_x = TYPE_LENGTH (type2);
+ decimal_from_integral (arg1, x, *len_x, *byte_order_x);
+ }
+ else
+ error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
+ TYPE_NAME (type2));
+
+ /* Obtain decimal value of arg2, converting from other types
+ if necessary. */
+
+ if (TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
+ {
+ *byte_order_y = gdbarch_byte_order (get_type_arch (type2));
+ *len_y = TYPE_LENGTH (type2);
+ memcpy (y, value_contents (arg2), *len_y);
+ }
+ else if (is_integral_type (type2))
+ {
+ *byte_order_y = gdbarch_byte_order (get_type_arch (type1));
+ *len_y = TYPE_LENGTH (type1);
+ decimal_from_integral (arg2, y, *len_y, *byte_order_y);
+ }
+ else
+ error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
+ TYPE_NAME (type2));
+}