summaryrefslogtreecommitdiff
path: root/man/igcd.3mpu
blob: bb34af24f0e6c58f39bd0a217a964ce0dd923bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.\" Copyright 2026 Andrew V.Kosteltsev (kx@radix-linux.su)
.\"
.\"
.TH igcd 3  "September 14, 2026" "libmpu" "LibMPU Programmer's Manual"
.SH NAME
\fBigcd\fP \- greatest common divisor of unsigned integers
.SH SYNOPSIS
.nf
.B #include <libmpu.h>
.PP
.BI "void igcd( mpu_int *" c ", mpu_int *" a ", mpu_int *" b ", int " nb " );"
.fi
.SH DESCRIPTION
The \fBigcd()\fP function computes the greatest common divisor (GCD) of the unsigned integers
located at addresses \fBa\fP and \fBb\fP and places the result at address \fBc\fP. The
Euclidean algorithm is used. The memory contents at addresses \fBa\fP and \fBb\fP are not
changed. The \fBnb\fP parameter determines the size of all operands, in bytes.
.PP
The following zero-operand semantics are used:
.nf
.sp
        gcd(0, b) = b
        gcd(a, 0) = a
        gcd(0, 0) = 0
.fi
.PP
The operation clears the integer flags before execution. The \fBZ\fP flag is set when the
result is zero.
.sp
.SH EXAMPLES
.nf
.sp
#include <libmpu.h>
#include <stdio.h>

int main( void )
{
  mpu_int1024_t  c, a, b;
  int            nb = NB_I1024;
  __mpu_char8_t  s[4096];

  __mpu_init();

  iatoui( a, "56", nb );
  iatoui( b, "32", nb );

  igcd( c, a, b, nb );
  iuitoa( s, c, RADIX_DEC, LOWERCASE, nb );
  printf( "c = %s;\\n", s ); /* c = 8; */

  __mpu_free_context();

  return( 0 );
}
.fi
.sp
.SH SEE ALSO
.BR iadd(3),
.BR isub(3),
.BR iadc(3),
.BR isbb(3),
.BR ineg(3),
.BR inot(3),
.BR iand(3),
.BR itest(3),
.BR icmp(3),
.BR ior(3),
.BR ixor(3),
.BR iinc(3),
.BR idec(3),
.BR ixchg(3),
.BR icpy(3),
.BR icvt(3),
.BR imul(3),
.BR ismul(3),
.BR idiv(3),
.BR isdiv(3),
.BR iatoi(3),
.BR iatoui(3),
.BR iitoa(3),
.BR iuitoa(3),
.BR _int_digs(3),
.BR ibits_len(3),
.BR ilcm(3),
.BR imod(3),
.BR imul_mod(3),
.BR ipow_mod(3),
.BR ipowm1_mod(3),
.BR shifts(3),
.BR shifts\-n(3),
.BR circular\-shifts(3),
.BR circular\-shifts\-n(3),
.BR integer\-flags(3),
.BR real\-flags(3),
.BR libmpu(7).