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 QAA11534; Tue, 14 Oct 2003 16:37:18 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA24125 for ; Tue, 14 Oct 2003 16:37:17 +0200 (MET DST) Received: from smtp10.atl.mindspring.net (smtp10.atl.mindspring.net [207.69.200.246]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9EEbF100833 for ; Tue, 14 Oct 2003 16:37:16 +0200 (MET DST) Received: from user-0ccekej.cable.mindspring.com ([24.199.81.211] helo=minsky-primus.homeip.net) by smtp10.atl.mindspring.net with smtp (Exim 3.33 #1) id 1A9QIU-0001p7-00 for caml-list@inria.fr; Tue, 14 Oct 2003 10:37:14 -0400 Received: from 141.155.88.179 (SquirrelMail authenticated user yminsky) by minsky-primus.homeip.net with HTTP; Tue, 14 Oct 2003 10:37:14 -0400 (EDT) Message-ID: <51792.141.155.88.179.1066142234.squirrel@minsky-primus.homeip.net> Date: Tue, 14 Oct 2003 10:37:14 -0400 (EDT) Subject: [Caml-list] Weird behavior with nan's and min/max From: "Yaron Minsky" To: caml-list@inria.fr User-Agent: SquirrelMail/1.4.2-1 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Loop: caml-list@inria.fr X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 cornell:01 val:01 val:01 bug:01 yaron:01 equality:01 polymorphic:01 polymorphic:01 float:02 float:02 harder:02 comparison:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk min and max have pretty strange behavior when it comes to nan's. Here's an example: # min 3. nan;; - : float = 3. # min nan 3.;; - : float = nan When you think about it, the reason for this is clear. comparisons involving nan's always return false, so if you simply implement min as follows: if x < y then x else y the the result will depend on the order. Now here's the weird bit. I decided I wanted a polymorphic comparison that wouldn't have this problem. But this is a little harder than it seems, since it turns out that specialized float version of equality is different from the polymorphic version. Here's the example: # let raw_min = min val raw_min : 'a -> 'a -> 'a = # let min x y = if not (y = y) then y else if not (x = x) then x else raw_min x y ;; val min : 'a -> 'a -> 'a = # let fmin (x:float) y = if not (y = y) then y else if not (x = x) then x else raw_min x y ;; val fmin : float -> float -> float = # fmin 3. nan;; - : float = nan # fmin nan 3.;; - : float = nan # min nan 3.;; - : float = nan # min 3. nan;; - : float = 3. So, does this count as a bug? Any ideas about how to fix this behavior in a reasonably efficient way? Yaron ------------------- 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