From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 7 17:09:38 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3924237B401 for ; Mon, 7 Apr 2003 17:09:38 -0700 (PDT) Received: from snark.ratmir.ru (snark.ratmir.ru [213.24.248.177]) by mx1.FreeBSD.org (Postfix) with ESMTP id DBFA243FBF for ; Mon, 7 Apr 2003 17:09:36 -0700 (PDT) (envelope-from freebsd@snark.ratmir.ru) Received: from snark.ratmir.ru (freebsd@localhost [127.0.0.1]) by snark.ratmir.ru (8.12.9/8.12.9) with ESMTP id h3809YDR018217; Tue, 8 Apr 2003 04:09:35 +0400 (MSD) (envelope-from freebsd@snark.ratmir.ru) Received: (from freebsd@localhost) by snark.ratmir.ru (8.12.9/8.12.9/Submit) id h3809YgY018216; Tue, 8 Apr 2003 04:09:34 +0400 (MSD) Date: Tue, 8 Apr 2003 04:09:34 +0400 From: Alex Semenyaka To: Peter Pentchev , Alex Semenyaka , freebsd-hackers@freebsd.org Message-ID: <20030408000934.GB14719@snark.ratmir.ru> References: <20030405030629.GA2669@snark.ratmir.ru> <20030406032450.GC4130@gothmog.gr> <20030407085309.GC527@straylight.oblivion.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20030407085309.GC527@straylight.oblivion.bg> User-Agent: Mutt/1.5.4i Subject: Re: /bin/sh and BIG NUMBERS X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Apr 2003 00:09:38 -0000 On Mon, Apr 07, 2003 at 11:53:09AM +0300, Peter Pentchev wrote: > >> -int arith(char *); > >> +long long arith(char *); > >> [snip rest of long-long using patch] >> Nice idea, but we should probably ask the -standards people if we >> can/should make this use uint64_t and %jd instead of `long long' > intmax_t might be a better choice, if %jd is used :) Ok, and then one more issue: what is The Right Way to estimate the maximal length of the resulting number? Since there is the replacement of fmtstr(p, 12, "%qd", result); with fmtstr(p, 21, "%qd", result); in my patch. If we are going to handle the max integer type automatically as with intmax= _t and %jd we need to fix that part as well :) 1) Sure I can replace if with #define ARITH_LEN (int)(2+log10(UMAXINT_MAX)) =2E.. fmtstr(p, ARITH_LEN, "%jd", result); but then we will need to link libm.so library that does not look like good idea. 2) Also we can make a some number of the nested #if's like this: #if UMAXINT_MAX <=3D UINT_MAX #define ARITH_LEN 10 #elif UMAXINT_MAX <=3D ULONGLONG_MAX #define ARITH_LEN 19 =2E.. That's far from ideal as well. 3) I can allocate a LARGE buffer there but it just the stupid waste of memo= ry. 4) Also we can have special file to be compiled and run during in the build= ing sh time such as arith_len.c: ---------->------------>----------- #include #include #include int main(int ac, char *av[]) { printf("#ifndef ARITH_LEN\n#define ARITH_LEN %d\n#endif\n", (int)(log10(UI= NT_MA X))); exit(0); } ----------<------------<----------- and generate file arith_len.h on-the-fly. OR, 5) we can add corresponding constants to the machine/_stdint.h or machine/_inttypes.h. The last way looks like the smartest one for me. Also Stefan E=F1er wrote me that he did the same job for /bin/expr 3 years ago and suggested to take a look on his job. He added=20 64-bit support to expr as well as overflow checks. I do think that it will be nice to have optional overflow control but optional but nice to have. Have any objections if I will add new switch for /bin/sh like -O which will makes /bin/sh to complain to stderr about overflows? I will prepare the final patch as soon as those two questions will be resol= ved. Thank you all for the participating in this discussion, it is very useful f= or me! SY, Alex