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 PAA18824; Mon, 20 Oct 2003 15:29:23 +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 PAA04294 for ; Mon, 20 Oct 2003 15:29:22 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9KDTF124173; Mon, 20 Oct 2003 15:29:15 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA04006; Mon, 20 Oct 2003 15:29:14 +0200 (MET DST) Date: Mon, 20 Oct 2003 15:29:14 +0200 From: Xavier Leroy To: "Yaron M. Minsky" Cc: Caml List Subject: Re: [Caml-list] Weird behavior with nan's and min/max Message-ID: <20031020152914.C13138@pauillac.inria.fr> References: <51792.141.155.88.179.1066142234.squirrel@minsky-primus.homeip.net> <20031016151658.A5633@pauillac.inria.fr> <1066402553.4570.65.camel@pelican> <1066434942.2933.70.camel@dragonfly.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <1066434942.2933.70.camel@dragonfly.localdomain>; from yminsky@cs.cornell.edu on Fri, Oct 17, 2003 at 07:55:43PM -0400 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 pervasive:01 floats:01 floats:01 pervasives:01 inherently:01 nans:01 api:01 api:01 nans:01 sigfpe:01 sigfpe:01 non-portable:01 asynchronous:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > Doesn't the polymorphic comparison have to be a total order? Pervasive.compare must be a total order, so it would need to throw an exception if its arguments are unordered (e.g. one is "nan"). The other comparisons (=, <, etc) could implement a partial order, returning "false" in the "unordered" case (except for <>, which should return "true" in this case). > This kind of wigs me out too. For example, do the set and map data > structures depend on this total order property? What happens when I > stick in a data structure which contains some floats somewhere in it, > and some of those floats are nan's? Does the data structure continue to > work at all? It totally wigs me out. Sets and maps require a total order, so, yes, in the current implementation, strange things can happen with "nan" used as set elements or map keys. Again, throwing an "unordered" exception in Pervasives.compare would avoid the problem. Note, however, that it doesn't make much sense to use floats as set elements or map keys, due to the inherently approximate nature of floats. E.g. does the set {1.0; 1.0+.epsilon} have 1 or 2 elements? > I wish there was some sensible way around it. Probably the thing I > would like best is for calculations that produce nans to throw > exceptions. But from what I've heard so far, this doesn't appear to be > possible. The IEEE standard specifies both behaviors: return nan or cause a floating-point trap, and says that there should be an API to choose the desired behavior. Most processors implement the two behaviors, controlled by some status bit somewhere. The first problem is that there is no standard C API to select the desired behavior (even ISO C 99 isn't terribly clear on this). So, everyone stays in the "nans, no traps" mode. > Here's another question: is it possible to catch floating point > exceptions such as division by zero? It seems like that might be another > way of dealing with this. I thought catching SIGFPE would do it, but I > tried and I couldn't seem to get it triggered. Is it possible to convert > floating point exceptions to ocaml exceptions? That's the second problem. Trapping a synchronous signal (such as SIGFPE) and turning it into a Caml exception is quite hard and non-portable. Caml manages to deal with asynchronous signals by delaying their delivery until a safe point is reached, but obviously this doesn't work for synchronous, program-generated signals. E.g. what to do if the SIGFPE comes from C code running in "blocking section" mode? - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners