@@ -156,23 +156,18 @@ cdef class acb(flint_scalar):
156
156
return (self .real._mpf_, self .imag._mpf_)
157
157
158
158
def __richcmp__ (s , t , int op ):
159
- cdef acb_struct sval[1 ]
160
159
cdef acb_struct tval[1 ]
161
160
cdef bint res
162
- cdef int stype, ttype
161
+ cdef int ttype
163
162
if not (op == 2 or op == 3 ):
164
163
raise ValueError (" comparing complex numbers" )
165
- stype = acb_set_any_ref(sval, s)
166
- if stype == FMPZ_UNKNOWN:
167
- return NotImplemented
168
164
ttype = acb_set_any_ref(tval, t)
169
165
if ttype == FMPZ_UNKNOWN:
170
166
return NotImplemented
171
167
if op == 2 :
172
- res = acb_eq(sval , tval)
168
+ res = acb_eq(s.val , tval)
173
169
else :
174
- res = acb_ne(sval, tval)
175
- if stype == FMPZ_TMP: acb_clear(sval)
170
+ res = acb_ne(s.val, tval)
176
171
if ttype == FMPZ_TMP: acb_clear(tval)
177
172
return res
178
173
@@ -363,92 +358,114 @@ cdef class acb(flint_scalar):
363
358
return res
364
359
365
360
def __add__ (s , t ):
366
- cdef acb_struct sval[1 ]
367
361
cdef acb_struct tval[1 ]
368
- cdef int stype, ttype
369
- stype = acb_set_any_ref(sval, s )
370
- if stype == FMPZ_UNKNOWN:
362
+ cdef int ttype
363
+ ttype = acb_set_any_ref(tval, t )
364
+ if ttype == FMPZ_UNKNOWN:
371
365
return NotImplemented
366
+ u = acb.__new__ (acb)
367
+ acb_add((< acb> u).val, s.val, tval, getprec())
368
+ if ttype == FMPZ_TMP: acb_clear(tval)
369
+ return u
370
+
371
+ def __radd__ (s , t ):
372
+ cdef acb_struct tval[1 ]
373
+ cdef int ttype
372
374
ttype = acb_set_any_ref(tval, t)
373
375
if ttype == FMPZ_UNKNOWN:
374
376
return NotImplemented
375
377
u = acb.__new__ (acb)
376
- acb_add((< acb> u).val, sval, tval, getprec())
377
- if stype == FMPZ_TMP: acb_clear(sval)
378
+ acb_add((< acb> u).val, tval, s.val, getprec())
378
379
if ttype == FMPZ_TMP: acb_clear(tval)
379
380
return u
380
381
381
382
def __sub__ (s , t ):
382
- cdef acb_struct sval[1 ]
383
383
cdef acb_struct tval[1 ]
384
- cdef int stype, ttype
385
- stype = acb_set_any_ref(sval, s )
386
- if stype == FMPZ_UNKNOWN:
384
+ cdef int ttype
385
+ ttype = acb_set_any_ref(tval, t )
386
+ if ttype == FMPZ_UNKNOWN:
387
387
return NotImplemented
388
+ u = acb.__new__ (acb)
389
+ acb_sub((< acb> u).val, s.val, tval, getprec())
390
+ if ttype == FMPZ_TMP: acb_clear(tval)
391
+ return u
392
+
393
+ def __rsub__ (s , t ):
394
+ cdef acb_struct tval[1 ]
395
+ cdef int ttype
388
396
ttype = acb_set_any_ref(tval, t)
389
397
if ttype == FMPZ_UNKNOWN:
390
398
return NotImplemented
391
399
u = acb.__new__ (acb)
392
- acb_sub((< acb> u).val, sval, tval, getprec())
393
- if stype == FMPZ_TMP: acb_clear(sval)
400
+ acb_sub((< acb> u).val, tval, s.val, getprec())
394
401
if ttype == FMPZ_TMP: acb_clear(tval)
395
402
return u
396
403
397
404
def __mul__ (s , t ):
398
- cdef acb_struct sval[1 ]
399
405
cdef acb_struct tval[1 ]
400
- cdef int stype, ttype
401
- stype = acb_set_any_ref(sval, s)
402
- if stype == FMPZ_UNKNOWN:
403
- return NotImplemented
406
+ cdef int ttype
404
407
ttype = acb_set_any_ref(tval, t)
405
408
if ttype == FMPZ_UNKNOWN:
406
409
return NotImplemented
407
410
u = acb.__new__ (acb)
408
- acb_mul((< acb> u).val, sval, tval, getprec())
409
- if stype == FMPZ_TMP: acb_clear(sval)
411
+ acb_mul((< acb> u).val, s.val, tval, getprec())
410
412
if ttype == FMPZ_TMP: acb_clear(tval)
411
413
return u
412
414
413
- # important: must not be cdef because of cython magic
414
- @staticmethod
415
- def _div_ (s , t ):
416
- cdef acb_struct sval[1 ]
415
+ def __rmul__ (s , t ):
417
416
cdef acb_struct tval[1 ]
418
- cdef int stype, ttype
419
- stype = acb_set_any_ref(sval, s)
420
- if stype == FMPZ_UNKNOWN:
421
- return NotImplemented
417
+ cdef int ttype
422
418
ttype = acb_set_any_ref(tval, t)
423
419
if ttype == FMPZ_UNKNOWN:
424
420
return NotImplemented
425
421
u = acb.__new__ (acb)
426
- acb_div((< acb> u).val, sval, tval, getprec())
427
- if stype == FMPZ_TMP: acb_clear(sval)
422
+ acb_mul((< acb> u).val, tval, s.val, getprec())
428
423
if ttype == FMPZ_TMP: acb_clear(tval)
429
424
return u
430
425
431
426
def __truediv__ (s , t ):
432
- return acb._div_(s, t)
427
+ cdef acb_struct tval[1 ]
428
+ cdef int ttype
429
+ ttype = acb_set_any_ref(tval, t)
430
+ if ttype == FMPZ_UNKNOWN:
431
+ return NotImplemented
432
+ u = acb.__new__ (acb)
433
+ acb_div((< acb> u).val, s.val, tval, getprec())
434
+ if ttype == FMPZ_TMP: acb_clear(tval)
435
+ return u
433
436
434
- def __div__ (s , t ):
435
- return acb._div_(s, t)
437
+ def __rtruediv__ (s , t ):
438
+ cdef acb_struct tval[1 ]
439
+ cdef int ttype
440
+ ttype = acb_set_any_ref(tval, t)
441
+ if ttype == FMPZ_UNKNOWN:
442
+ return NotImplemented
443
+ u = acb.__new__ (acb)
444
+ acb_div((< acb> u).val, tval, s.val, getprec())
445
+ if ttype == FMPZ_TMP: acb_clear(tval)
446
+ return u
436
447
437
448
def __pow__ (s , t , u ):
438
- cdef acb_struct sval[1 ]
439
449
cdef acb_struct tval[1 ]
440
- cdef int stype, ttype
450
+ cdef int ttype
441
451
if u is not None :
442
452
raise ValueError (" modular exponentiation of complex number" )
443
- stype = acb_set_any_ref(sval, s )
444
- if stype == FMPZ_UNKNOWN:
453
+ ttype = acb_set_any_ref(tval, t )
454
+ if ttype == FMPZ_UNKNOWN:
445
455
return NotImplemented
456
+ u = acb.__new__ (acb)
457
+ acb_pow((< acb> u).val, s.val, tval, getprec())
458
+ if ttype == FMPZ_TMP: acb_clear(tval)
459
+ return u
460
+
461
+ def __rpow__ (s , t ):
462
+ cdef acb_struct tval[1 ]
463
+ cdef int ttype
446
464
ttype = acb_set_any_ref(tval, t)
447
465
if ttype == FMPZ_UNKNOWN:
448
466
return NotImplemented
449
467
u = acb.__new__ (acb)
450
- acb_pow((< acb> u).val, sval, tval, getprec())
451
- if stype == FMPZ_TMP: acb_clear(sval)
468
+ acb_pow((< acb> u).val, tval, s.val, getprec())
452
469
if ttype == FMPZ_TMP: acb_clear(tval)
453
470
return u
454
471
@@ -2560,4 +2577,3 @@ cdef class acb(flint_scalar):
2560
2577
acb_hypgeom_coulomb(NULL , (< acb> G).val, NULL , NULL ,
2561
2578
(< acb> l).val, (< acb> eta).val, (< acb> self ).val, getprec())
2562
2579
return G
2563
-
0 commit comments