From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA19496; Fri, 12 Oct 2001 16:27:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA19143 for ; Fri, 12 Oct 2001 16:27:53 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f9CENlj29092; Fri, 12 Oct 2001 16:23:47 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA19312; Fri, 12 Oct 2001 16:23:47 +0200 (MET DST) Date: Fri, 12 Oct 2001 16:23:47 +0200 From: Xavier Leroy To: Thorsten Ohl Cc: caml-list@inria.fr Subject: Re: [Caml-list] Printf: variable field width/precision Message-ID: <20011012162347.D18676@pauillac.inria.fr> References: <200110081609.f98G9T131189@heplix4.ikp.physik.tu-darmstadt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200110081609.f98G9T131189@heplix4.ikp.physik.tu-darmstadt.de>; from ohl@hep.tu-darmstadt.de on Mon, Oct 08, 2001 at 06:09:29PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > In the C library, printf(3) supports variable field widths and > precisions with the `*' specifier. > Unfortunately, neither the O'Caml library nor the compiler accept `*'. > If the `*' form is available, the `*m$' form is hardly needed, but I > couldn't find a way to hack around the missing `*' (handling every > conceivable width/precision pair as a special case doesn't count ...). > > Is there are chance that variable field widths for the benefit of > numerical programs will be supported in the future? I've never needed the '*' specifier so far, but I agree this should be supported at some point. As far as I can say, this requires a bit of work, though. > [It would be easy > to hack the library, but since the compiler must perform its own magic > for type safety, I couldn't distribute the code without asking users > to patch the compiler.] Well, you could always donate us the code, which would then end up in the standard distribution, making life really easy for users :-) > Or does anybody know a nice workaround? You could write a wrapper around the low-level "format_float" primitive, i.e. external format_float: string -> float -> string = "format_float" let format_float_variable width prec f = format_float (Printf.sprintf "%%%d.%de" width prec) f Not terribly nice, I agree. Concerning your other request: > The C library header file contains (among others) the > following useful macros: > /* Number of decimal digits of precision in a double */ > #define DBL_DIG 15 > /* Difference between 1.0 and the minimum double greater than 1.0 */ > #define DBL_EPSILON 2.2204460492503131e-16 > /* Minimum normalised double */ > #define DBL_MIN 2.2250738585072014e-308 > /* Minimum int x such that 10**x is a normalised double */ > #define DBL_MIN_10_EXP (-307) > /* Maximum double */ > #define DBL_MAX 1.7976931348623157e+308 > /* Maximum int x such that 10**x is a representable double */ > #define DBL_MAX_10_EXP 308 > It would be great if these values were accessible from O'Caml in a > future version so that numerical code could be made to work on > different machines. This is very reasonable indeed. Thanks for the suggestion. - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr