From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA07299 for caml-red; Sat, 14 Oct 2000 14:40:01 +0200 (MET DST) 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 OAA07149 for ; Sat, 14 Oct 2000 14:19:23 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e9ECJF906555; Sat, 14 Oct 2000 14:19:15 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA07188; Sat, 14 Oct 2000 14:19:15 +0200 (MET DST) Message-ID: <20001014141915.60643@pauillac.inria.fr> Date: Sat, 14 Oct 2000 14:19:15 +0200 From: Xavier Leroy To: David McClain , caml-list@inria.fr Subject: Re: OCaml and C math routines References: <003a01c03537$3e67fe50$210148bf@dylan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <003a01c03537$3e67fe50$210148bf@dylan>; from David McClain on Fri, Oct 13, 2000 at 10:01:33AM -0700 Sender: weis@pauillac.inria.fr > OCaml'ers... I would be very interested to hear your response to this! Here is a copy of the response I posted on comp.lang.ml: Zhong Shao writes: > From what I know, for the floating-point intensive benchmarks, Ocaml > is faster than SML/NJ mainly because Ocaml directly calls the native, > C-based math library (which in turn is fine-tuned for the actual > processor). SML/NJ, on the other hand, implements all of the math > library functions (e.g., cos, sin, tan) in ML itself (as part of the > SML basis). Thanks, Zhong, for this interesting piece of information. I had no idea that the SML Basis Library took such a "bare-bone" approach... > Members of the SML basis committee and the Ocaml group probably can > tell us the pros and cons of calling the native math library vs. having > it written in ML itself. Short answer: the idea of writing the math functions in ML itself never even crossed my mind, and I can see absolutely no reason why one would want to do so. Longer answer: here are a bunch of reasons why calling the native math library makes much more sense. 1- Availability: any Unix system, and any C compiler for other OS, come with a math library conforming to ANSI (for the API) and IEEE (for the semantics of the math operations). So there are no portability issues in using the native math library. 2- Correctness: floating-point arithmetic is surprisingly tricky. These native math libraries are widely used, in C and Fortran, by demanding numerical users, so chances are that they are more correct than anything we can write ourselves. (And if they are not correct, someone else gets to fix them, not us.) Some of these libraries were written by leading experts in the field (I'm thinking of Apple's SANE library, which I believe was originally written by Prof. Kahan, one of the biggest names in the area.) So, I trust those libraries to be more correct than anything I could write myself. 3- Speed: we can safely expect the native math library to be nearly optimal in terms of performances, including processor-specific optimizations, e.g. critical parts are written in assembly, exploiting all resources of the target processor. Sometimes, these libraries are even written by the same people that designed the processor (I'm thinking of Motorola's library for the Power PC). So, I trust those libraries to be faster than anything I could write myself. 4- Economy of means: implementors of ML have very limited human resources, so it makes much more sense to interface with good existing C libraries rather than redo everything from scratch. In many areas, it's not obvious to find good C libraries that do what we want, so reimplementation in ML might be justified; but in the case of floating-point math functions, I really don't see anything to hold against the existing math libraries. So, reimplementing exp() or sin() myself would just be a waste of my time (and rather boring, in addition). Now, I'd really love to hear from the SML Basis Library designers and see what reason they can come up with to justify implementing the math functions in ML. - Xavier Leroy -- Valid e-mail address (without the underscores): Xavier.Leroy@i_n_r_i_a.f_r This is a protection against junk mail. Apologies for the inconvenience. Home page: http://pauillac.inria.fr/~xleroy/