Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

r""" 

Fast binary operations for basic types 

""" 

  

from .types cimport mpz_t, mpq_t 

from .mpz cimport mpz_set, mpz_add, mpz_mul 

from .mpq cimport mpq_canonicalize, mpq_numref, mpq_denref, mpq_add 

  

cdef inline void mpq_add_z(mpq_t res, mpq_t op1, mpz_t op2): 

mpz_mul(mpq_numref(res), mpq_denref(op1), op2) 

mpz_add(mpq_numref(res), mpq_numref(res), mpq_numref(op1)) 

mpz_set(mpq_denref(res), mpq_denref(op1)) 

  

cdef inline void mpq_div_zz(mpq_t res, mpz_t op1, mpz_t op2): 

mpz_set(mpq_numref(res), op1) 

mpz_set(mpq_denref(res), op2) 

mpq_canonicalize(res) 

  

cdef inline void mpq_mul_z(mpq_t res, mpq_t op1, mpz_t op2): 

# (A/B) * C = (C/B) * A 

mpq_div_zz(res, op2, mpq_denref(op1)) 

mpz_mul(mpq_numref(res), mpq_numref(res), mpq_numref(op1))