libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

zor.c (878B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "internals.h"
      3 
      4 
      5 void
      6 zor(z_t a, z_t b, z_t c)
      7 {
      8 	size_t n, m;
      9 
     10 	if (unlikely(zzero(b))) {
     11 		SET(a, c);
     12 		return;
     13 	} else if (unlikely(zzero(c))) {
     14 		SET(a, b);
     15 		return;
     16 	}
     17 
     18 	MIN_MAX_1(n, m, b->used, c->used);
     19 	ENSURE_SIZE(a, m);
     20 
     21 	if (a == b) {
     22 		ZMEM_2OP_PRECISE(a->chars, a->chars, c->chars, n, |);
     23 		if (a->used < c->used)
     24 			zmemcpy_range(a->chars, c->chars, n, m);
     25 	} else if (unlikely(a == c)) {
     26 		ZMEM_2OP_PRECISE(a->chars, a->chars, b->chars, n, |);
     27 		if (a->used < b->used)
     28 			zmemcpy_range(a->chars, b->chars, n, m);
     29 	} else  if (m == b->used) {
     30 		ZMEM_2OP(a->chars, c->chars, b->chars, n, |);
     31 		zmemcpy_range(a->chars, b->chars, n, m);
     32 	} else {
     33 		ZMEM_2OP(a->chars, b->chars, c->chars, n, |);
     34 		zmemcpy_range(a->chars, c->chars, n, m);
     35 	}
     36 
     37 	a->used = m;
     38 	SET_SIGNUM(a, zpositive2(b, c) * 2 - 1);
     39 }