From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 18 02:40:25 2013 Received: (at submit) by debbugs.gnu.org; 18 Jun 2013 06:40:25 +0000 Received: from localhost ([127.0.0.1]:52141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uopaa-0003lI-Dk for submit@debbugs.gnu.org; Tue, 18 Jun 2013 02:40:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39379) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UopaW-0003kl-6W for submit@debbugs.gnu.org; Tue, 18 Jun 2013 02:40:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UopaQ-0005W6-1v for submit@debbugs.gnu.org; Tue, 18 Jun 2013 02:40:15 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-99.2 required=5.0 tests=BAYES_50,USER_IN_WHITELIST autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:34704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UopaP-0005W0-Vk for submit@debbugs.gnu.org; Tue, 18 Jun 2013 02:40:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UopaO-0003fL-KQ for bug-coreutils@gnu.org; Tue, 18 Jun 2013 02:40:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UopaN-0005US-C3 for bug-coreutils@gnu.org; Tue, 18 Jun 2013 02:40:12 -0400 Received: from 216-12-86-13.cv.mvl.ntelos.net ([216.12.86.13]:59037 helo=brightrain.aerifal.cx) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UopaN-0005U6-7f for bug-coreutils@gnu.org; Tue, 18 Jun 2013 02:40:11 -0400 Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1Uop7V-0006id-00 for bug-coreutils@gnu.org; Tue, 18 Jun 2013 06:10:21 +0000 Date: Tue, 18 Jun 2013 02:10:21 -0400 From: bugdal@aerifal.cx To: bug-coreutils@gnu.org Subject: coreutils' getlimits fails to represent float limits correctly Message-ID: <20130618061021.GA25746@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) I noticed a bug in the getlimits utility's printing of DBL_MAX, etc. The precision at which the limits are printed is grossly insufficient to represent the actual limits; if the output is converted back to a floating point number of the appropriate type, the result will differ greatly from the actual limit. The format specifier used for printing these values is is %Le, which gives 7 decimal digits. The number of digits needed to faithfully represent the limits varies by type, but a safe fix would be replacing printf (#TYPE"_MIN=%Le\n", (long double)TYPE##_MIN); \ printf (#TYPE"_MAX=%Le\n", (long double)TYPE##_MAX); with: printf (#TYPE"_MIN=%.*Le\n", DECIMAL_DIG, (long double)TYPE##_MIN); \ printf (#TYPE"_MAX=%.*Le\n", DECIMAL_DIG, (long double)TYPE##_MAX); It would be possible to use appropriate precisions for each type, but unfortunately I'm not aware of a convenient way to compute the number of digits needed based on other properties of the type. FLT_DIG and DBL_DIG are not the correct values for this; they deal with the opposite round-trip. One solution would be to simply hard-code the number of digits for float and double when they're IEEE types, and otherwise use DECIMAL_DIG for all three types (for obscure systems where float/double are not IEEE single/double). I believe the correct number of digits for IEEE single or double would be 10 and 17, respectively. Rich From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 18 03:47:18 2013 Received: (at 14650) by debbugs.gnu.org; 18 Jun 2013 07:47:18 +0000 Received: from localhost ([127.0.0.1]:52227 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UoqdJ-0006QH-W5 for submit@debbugs.gnu.org; Tue, 18 Jun 2013 03:47:18 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:35493) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UoqdG-0006PT-KD for 14650@debbugs.gnu.org; Tue, 18 Jun 2013 03:47:15 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id C228839E8106; Tue, 18 Jun 2013 00:47:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ykRYuPnstOfj; Tue, 18 Jun 2013 00:47:07 -0700 (PDT) Received: from [192.168.1.9] (pool-71-108-49-126.lsanca.fios.verizon.net [71.108.49.126]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id C12A939E8008; Tue, 18 Jun 2013 00:47:07 -0700 (PDT) Message-ID: <51C01077.1090906@cs.ucla.edu> Date: Tue, 18 Jun 2013 00:47:03 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: bugdal@aerifal.cx Subject: Re: bug#14650: coreutils' getlimits fails to represent float limits correctly References: <20130618061021.GA25746@brightrain.aerifal.cx> In-Reply-To: <20130618061021.GA25746@brightrain.aerifal.cx> X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.4 (---) X-Debbugs-Envelope-To: 14650 Cc: 14650@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.4 (---) On 06/17/2013 11:10 PM, bugdal@aerifal.cx wrote: > I'm not aware of a convenient way to compute the number > of digits coreutils already can do that; see lib/ftoastr.h. Presumably coreutils should use the ftoastr module hear. From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 18 05:29:42 2013 Received: (at 14650-done) by debbugs.gnu.org; 18 Jun 2013 09:29:42 +0000 Received: from localhost ([127.0.0.1]:52345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UosEP-0003Ah-LN for submit@debbugs.gnu.org; Tue, 18 Jun 2013 05:29:42 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:28583) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UosEN-0003AB-Jj for 14650-done@debbugs.gnu.org; Tue, 18 Jun 2013 05:29:40 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgDAEEnwFFda1ms/2dsb2JhbAANTA6GdrwDAwGBFIMXAQEBBCMPAUYQCw0LAgIFFgsCAgkDAgECAUUGDQEFAgEBsBxzkUyBJo1AXweCTIEUA54EjVE/ Received: from unknown (HELO [192.168.1.79]) ([93.107.89.172]) by mail2.vodafone.ie with ESMTP; 18 Jun 2013 10:29:33 +0100 Message-ID: <51C0287C.4000406@draigBrady.com> Date: Tue, 18 Jun 2013 10:29:32 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#14650: coreutils' getlimits fails to represent float limits correctly References: <20130618061021.GA25746@brightrain.aerifal.cx> <51C01077.1090906@cs.ucla.edu> In-Reply-To: <51C01077.1090906@cs.ucla.edu> X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 14650-done Cc: 14650-done@debbugs.gnu.org, bugdal@aerifal.cx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 06/18/2013 08:47 AM, Paul Eggert wrote: > On 06/17/2013 11:10 PM, bugdal@aerifal.cx wrote: >> I'm not aware of a convenient way to compute the number >> of digits > > coreutils already can do that; see lib/ftoastr.h. > Presumably coreutils should use the ftoastr module hear. Something like the patch below? which changes the output from: FLT_MIN=1.175494e-38 FLT_MAX=3.402823e+38 DBL_MIN=2.225074e-308 DBL_MAX=1.797693e+308 LDBL_MIN=3.362103e-4932 LDBL_MAX=1.189731e+4932 to... FLT_MIN=1.1754944e-38 FLT_MAX=3.4028235e+38 DBL_MIN=2.2250738585072014e-308 DBL_MAX=1.7976931348623157e+308 LDBL_MIN=3.3621031431120935063e-4932 LDBL_MAX=1.189731495357231765e+4932 Note the difference lengths of LDBL_MIN and LDBL_MAX. cheers, Pádraig. diff --git a/src/getlimits.c b/src/getlimits.c index 7c1fbe2..dfc4b12 100644 --- a/src/getlimits.c +++ b/src/getlimits.c @@ -21,6 +21,7 @@ #include #include +#include "ftoastr.h" #include "system.h" #include "long-options.h" @@ -97,6 +98,19 @@ decimal_absval_add_one (char *buf) return result; } +#define PRINT_FLOATTYPE(N, T, FTOASTR, BUFSIZE) \ +static void \ +N (T x) \ +{ \ + char buf[BUFSIZE]; \ + FTOASTR (buf, sizeof buf, FTOASTR_LEFT_JUSTIFY, 0, x); \ + puts (buf); \ +} + +PRINT_FLOATTYPE (print_FLT, float, ftoastr, FLT_BUFSIZE_BOUND) +PRINT_FLOATTYPE (print_DBL, double, dtoastr, DBL_BUFSIZE_BOUND) +PRINT_FLOATTYPE (print_LDBL, long double, ldtoastr, LDBL_BUFSIZE_BOUND) + int main (int argc, char **argv) { @@ -127,8 +141,8 @@ main (int argc, char **argv) } #define print_float(TYPE) \ - printf (#TYPE"_MIN=%Le\n", (long double)TYPE##_MIN); \ - printf (#TYPE"_MAX=%Le\n", (long double)TYPE##_MAX); + printf (#TYPE"_MIN="); print_##TYPE(TYPE##_MIN); \ + printf (#TYPE"_MAX="); print_##TYPE(TYPE##_MAX); /* Variable sized ints */ print_int (CHAR); From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 18 11:02:31 2013 Received: (at 14650-done) by debbugs.gnu.org; 18 Jun 2013 15:02:32 +0000 Received: from localhost ([127.0.0.1]:53243 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UoxQV-0004n9-GS for submit@debbugs.gnu.org; Tue, 18 Jun 2013 11:02:31 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:50950) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UoxQT-0004mr-3w for 14650-done@debbugs.gnu.org; Tue, 18 Jun 2013 11:02:29 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 1911AA60003; Tue, 18 Jun 2013 08:02:23 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yQUK51NKvCFu; Tue, 18 Jun 2013 08:02:22 -0700 (PDT) Received: from [192.168.1.9] (pool-71-108-49-126.lsanca.fios.verizon.net [71.108.49.126]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id B6732A60001; Tue, 18 Jun 2013 08:02:22 -0700 (PDT) Message-ID: <51C0761E.4080708@cs.ucla.edu> Date: Tue, 18 Jun 2013 08:00:46 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#14650: coreutils' getlimits fails to represent float limits correctly References: <20130618061021.GA25746@brightrain.aerifal.cx> <51C01077.1090906@cs.ucla.edu> <51C0287C.4000406@draigBrady.com> In-Reply-To: <51C0287C.4000406@draigBrady.com> X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -3.5 (---) X-Debbugs-Envelope-To: 14650-done Cc: 14650-done@debbugs.gnu.org, bugdal@aerifal.cx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.5 (---) On 06/18/2013 02:29 AM, Pádraig Brady wrote: > Something like the patch below? Yes, thanks, that was fast and looks good. Did you forget to push it? From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 18 11:21:38 2013 Received: (at 14650) by debbugs.gnu.org; 18 Jun 2013 15:21:38 +0000 Received: from localhost ([127.0.0.1]:53278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uoxj0-0005UP-CI for submit@debbugs.gnu.org; Tue, 18 Jun 2013 11:21:38 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:64779) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uoxiy-0005Ty-Jm for 14650@debbugs.gnu.org; Tue, 18 Jun 2013 11:21:37 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An0DAJp5wFFda1ms/2dsb2JhbAANTA6GdrkbgmUEAQMBgReDFwEBAQQjDwFGEAsNCwICBRYLAgIJAwIBAgFFBg0BBwEBsElzkU2BJo02XweCTYEUA54EjVE/ Received: from unknown (HELO [192.168.1.79]) ([93.107.89.172]) by mail2.vodafone.ie with ESMTP; 18 Jun 2013 16:21:30 +0100 Message-ID: <51C07AF9.5000604@draigBrady.com> Date: Tue, 18 Jun 2013 16:21:29 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#14650: coreutils' getlimits fails to represent float limits correctly References: <20130618061021.GA25746@brightrain.aerifal.cx> <51C01077.1090906@cs.ucla.edu> <51C0287C.4000406@draigBrady.com> <51C0761E.4080708@cs.ucla.edu> In-Reply-To: <51C0761E.4080708@cs.ucla.edu> X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 14650 Cc: 14650@debbugs.gnu.org, bugdal@aerifal.cx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 06/18/2013 04:00 PM, Paul Eggert wrote: > On 06/18/2013 02:29 AM, Pádraig Brady wrote: >> Something like the patch below? > > Yes, thanks, that was fast and looks good. > > Did you forget to push it? Adjusted to pass make syntax-check and now pushed. thanks for the review! Pádraig. From unknown Sun Jun 22 11:42:44 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 17 Jul 2013 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator