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 QAA26092; Tue, 14 Oct 2003 16:56:56 +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 QAA27103 for ; Tue, 14 Oct 2003 16:56:55 +0200 (MET DST) Received: from mclean.mail.mindspring.net (mclean.mail.mindspring.net [207.69.200.57]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9EEus107529 for ; Tue, 14 Oct 2003 16:56:54 +0200 (MET DST) Received: from user-0ccekej.cable.mindspring.com ([24.199.81.211] helo=minsky-primus.homeip.net) by mclean.mail.mindspring.net with smtp (Exim 3.33 #1) id 1A9QbV-0001gD-00 for caml-list@inria.fr; Tue, 14 Oct 2003 10:56:53 -0400 Received: from 141.155.88.179 (SquirrelMail authenticated user yminsky) by minsky-primus.homeip.net with HTTP; Tue, 14 Oct 2003 10:56:53 -0400 (EDT) Message-ID: <54490.141.155.88.179.1066143413.squirrel@minsky-primus.homeip.net> In-Reply-To: <51792.141.155.88.179.1066142234.squirrel@minsky-primus.homeip.net> References: <51792.141.155.88.179.1066142234.squirrel@minsky-primus.homeip.net> Date: Tue, 14 Oct 2003 10:56:53 -0400 (EDT) Subject: Re: [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; caml-list:01 yaron:01 minsky:01 yminsky:01 cornell:01 val:01 val:01 bug:01 yaron:01 bug:01 faq:01 faq:01 beginner's:01 beginners:01 bin:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Here's a working solution, I think. let raw_min = min let raw_max = max let nan_or_equal x y = not (x < y) && not (x > y) (** min and max that choose nan if its there *) let min x y = if x = y then x else if nan_or_equal x y then nan else raw_min x y let max x y = if x = y then x else if nan_or_equal x y then nan else raw_max x y > 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 > ------------------- 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