This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Implement floordiv operator for gdb.Value


This is my attempt to implement the // operator on gdb.Value objects.
There is already BINOP_INTDIV which works fine for integral types, but
for floats I use BINOP_DIV and then call floor() on the result. This
doesn't support decimal floats though.

Is this a reasonable solution? Is the test sufficient?

I have a follow-up patch which changes the meaning of the / operator
for gdb.Value when built against Python 3, to be consistent with
Python (see comment 1 in the Bugzilla PR) but I expect that to be more
controversial :-)


gdb/ChangeLog:
2016-09-20  Jonathan Wakely  <jwakely@redhat.com>

	PR python/20624
	* python/py-value.c (VALPY_FLOORDIV): Define new enumerator.
	(valpy_binop_throw): Handle VALPY_FLOORDIV.
	(valpy_floordiv): New function.
	(value_object_as_number): Set valpy_floordiv in relevant slot.

gdb/testsuite/ChangeLog:
2016-09-20  Jonathan Wakely  <jwakely@redhat.com>

	PR python/20624
	* gdb.python/py-value.exp: Test floor division.

Attachment: floordiv.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]