mpq_cmp_z
Marco Bodrato
bodrato at mail.dm.unipi.it
Wed Aug 26 15:42:47 UTC 2015
Ciao,
Il Mar, 25 Agosto 2015 1:43 pm, Torbjörn Granlund ha scritto:
> static int
> cmp_helper (mpq_srcptr op1, mpz_srcptr op2num, mpz_srcptr op2den)
The code with this signature is attached.
> My idea was to have a file-local mpz_struct, which could be checked for
> in the helper to suppress *some* of the more expensive operations. Or
> not.
My idea is to check if the den{ominator} is one by checking this condition:
(SIZ(den) | PTR(den)[0]) == 1
... again, we OR a signed type with an unsigned and we compare the result
with an int ... seems correct to me ...
If the (second) denominator is one, only the cross product is skipped.
It is slightly slower than the code with casts, but it's surely cleaner.
But it is in some sense asymmetric, if you call mpq_cmp(A,B) and B happens
to be an integer, the code exploits it. If only A is an integer, the code
will not detect nor exploit the information.
Regards,
m
--
http://bodrato.it/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmp.c
Type: text/x-csrc
Size: 4837 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20150826/f7c93ef2/attachment.bin>
More information about the gmp-devel
mailing list