From owner-freebsd-questions@FreeBSD.ORG Wed Mar 3 13:07:36 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BE29F16A4CE for ; Wed, 3 Mar 2004 13:07:36 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7AC5643D2D for ; Wed, 3 Mar 2004 13:07:36 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i23L7WjR033559; Wed, 3 Mar 2004 15:07:32 -0600 (CST) (envelope-from dan) Date: Wed, 3 Mar 2004 15:07:32 -0600 From: Dan Nelson To: Wayne Sierke Message-ID: <20040303210731.GE79860@dan.emsphone.com> References: <1078286126.666.11.camel@ovirt.dyndns.ws> <20040303080359.GB79860@dan.emsphone.com> <1078304560.666.157.camel@ovirt.dyndns.ws> <20040303161840.GD79860@dan.emsphone.com> <1078334144.666.179.camel@ovirt.dyndns.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1078334144.666.179.camel@ovirt.dyndns.ws> X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: freebsd-questions@freebsd.org Subject: Re: Size of variables in awk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2004 21:07:36 -0000 In the last episode (Mar 04), Wayne Sierke said: > On Thu, 2004-03-04 at 02:48, Dan Nelson wrote: > > In the last episode (Mar 03), Wayne Sierke said: > > > I'm using the printf function in awk but something ain't right: > > > > > > # jot 4 30 | awk '{ printf("%u\n", 2^$1-1) }' > > > 2147483648 > > > > > > # jot 4 30 | awk '{ printf("%lu\n", 2^$1-1) }' > > > 2147483648 > > > > > > # jot 4 30 | awk '{ printf("%llu\n", 2^$1-1) }' > > > 35186519572480 > > > > I see nothing wrong here. %u is an unsigned int, and on x86 systems, > > an int is 32 bits. %llu is a long long unsigned int, and they are 64 > > bits. Since there is no way for C to print a number larger than 64 > > bits, you won't be able to use the numeric specifiers to print large > > numbers. You can use %s though. See > > /usr/src/contrib/one-true-awk/run.c, the format() function. > > When you say "they are 64 bits" you're referring to a long > (signed/unsigned) int (not long long unsigned int)? > > In which case aren't there two problems with the results shown? > > 1 - %u should print values up to 2^32-1 > > 2 - %lu should print values up to 2^64-1 > > whereas they're both hitting a limit at 2^31. It's definitely weird. See run.c, line 865: case 'o': case 'x': case 'X': case 'u': flag = *(s-1) == 'l' ? 'd' : 'u'; break; and line 897: case 'd': sprintf(p, fmt, (long) getfval(x)); break; case 'u': sprintf(p, fmt, (int) getfval(x)); break; in which case I have no idea how the %llu output is working at all :) -- Dan Nelson dnelson@allantgroup.com