File: cmpbignum.awk

package info (click to toggle)
apt-move 4.2.26-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 256 kB
  • ctags: 79
  • sloc: sh: 1,569; awk: 257; cpp: 116; perl: 85; makefile: 27
file content (35 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (8)
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
# cmpbignum --- compare two arbitrarily long integers.
#	The function returns:
#		< 0 if a < b
#		== 0 if a == b
#		> 0 if a > b
#	The idea came from Anthony Towns in http://bugs.debian.org/92839.
#
# Copyright (c) 2001 Herbert Xu <herbert@debian.org>
# $Id: cmpbignum.awk,v 1.1 2002/01/25 08:47:24 herbert Exp $

function cmpbignum(a, b, i, j, k, l, d) {
	i = match(a, /[^0]/)
	j = match(b, /[^0]/)
	if (!i || !j) {
		return !!i - !!j
	}

	k = length(a)
	l = length(b)
	d = (k - i) - (l - j)
	if (d) {
		return d
	}

	do {
		d = substr(a, i, 1) - substr(b, j, 1)
		if (d) {
			return d
		}
		i++
		j++
	} while (i <= k)

	return 0
}