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 AAA01966; Fri, 17 Oct 2003 00:52:06 +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 AAA12623 for ; Fri, 17 Oct 2003 00:52:05 +0200 (MET DST) Received: from mallaury.noc.nerim.net (smtp-104-thursday.noc.nerim.net [62.4.17.104]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9GMq4112830 for ; Fri, 17 Oct 2003 00:52:05 +0200 (MET DST) Received: from inria.fr (planar.net0.nerim.net [213.41.168.102]) by mallaury.noc.nerim.net (Postfix) with ESMTP id CE41E62D39; Fri, 17 Oct 2003 00:51:58 +0200 (CEST) Date: Fri, 17 Oct 2003 00:52:02 +0200 Subject: Re: [Caml-list] Weird behavior with nan's and min/max Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) Cc: caml-list@inria.fr To: "Yaron Minsky" From: Damien Doligez In-Reply-To: <15352.141.155.88.179.1066340443.squirrel@minsky-primus.homeip.net> Message-Id: <5B3DCF94-002B-11D8-BC86-00039310CAE8@inria.fr> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.552) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 damien:01 damien:01 yaron:01 minsky:01 segfault:01 bug:01 jacques:01 arrays:01 ints:01 int:01 int:01 doligez:01 doligez:01 lazy:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday, October 16, 2003, at 11:40 PM, Yaron Minsky wrote: > let is_obj_nan x = > Obj.tag (Obj.repr x) = Obj.double_tag && > (let f = (Obj.magic x : float) in not (f = f)) [...] > The resulting code segfaulted on me, and the segfault went away when I > went back to the ordinary min and max. Does anyone have a thought on > this? Is this use of Obj safe or not? The problem is that the argument of Obj.tag must be a pointer value that lives in the heap. A pointer value answers false to Obj.is_int, but you have no way to test for heap-allocated values. This is going to change soon because I am fixing the bug found by Jacques with float lazy arrays, and in the process I will extend Obj.tag to give meaningful answers for ints and non-heap-allocated values. In the meantime, you can use the following code, but it might still fail in some rare cases when applied to non-heap-allocated values (I/O channels for example): let is_obj_nan x = not (Obj.is_int (Obj.repr x)) && Obj.tag (Obj.repr x) = Obj.double_tag && (let f = (Obj.magic x : float) in not (f = f)) ;; -- Damien ------------------- 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