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 UAA08443; Wed, 15 Oct 2003 20:59: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 UAA24121 for ; Wed, 15 Oct 2003 20:59:17 +0200 (MET DST) Received: from mwinf0502.wanadoo.fr (smtp5.wanadoo.fr [193.252.22.26]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9FIxG129224 for ; Wed, 15 Oct 2003 20:59:17 +0200 (MET DST) Received: from debian (ca-bordeaux-12-69.w80-8.abo.wanadoo.fr [80.8.84.69]) by mwinf0502.wanadoo.fr (SMTP Server) with ESMTP id BBA87E8014BE for ; Wed, 15 Oct 2003 20:59:16 +0200 (CEST) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 1A9qrk-0004Ku-00 for ; Wed, 15 Oct 2003 20:59:24 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] NaN-safe min and max References: <18220.141.155.88.179.1066229526.squirrel@minsky-primus.homeip.net> <87u16a77rr.dlv@wanadoo.fr> From: Remi Vanicat Mail-Copy-To: never Date: Wed, 15 Oct 2003 20:59:23 +0200 In-Reply-To: <87u16a77rr.dlv@wanadoo.fr> (Remi Vanicat's message of "Wed, 15 Oct 2003 19:03:36 +0200") Message-ID: <87ismq72es.dlv@wanadoo.fr> User-Agent: Gnus/5.090024 (Oort Gnus v0.24) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 yaron:01 minsky:01 yminsky:01 cornell:01 andrieu:01 pervasives:01 val:01 0.0:01 val:01 abstr:01 abstr:01 bool:01 bool:01 unsafe:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Remi Vanicat writes: > "Yaron Minsky" writes: > >> Olivier Andrieu proposed the following code for doing a safe min/max. >> Does anyone have any thoughts about this code snippet, and whether it is >> or is not a safe use of Obj.magic? >> >> let min a b = >> let o = Obj.repr a in >> if Obj.is_block o && Obj.tag o = Obj.double_tag >> then Obj.magic (fmin (Obj.magic a) (Obj.magic b)) >> else Pervasives.min a b > > this one is unsafe : the fact that a is a block with a tag > Obj.double_tag doesn't proof that the same is true for b even if a and > b have the same type : > > # let i1 = Lazy.lazy_from_val 0.0;; > val i1 : float Lazy.t = lazy 0. > # let o1 = Obj.repr i1;; > val o1 : Obj.t = > # Obj.is_block o1;; > - : bool = true > # Obj.tag o1 = Obj.double_tag;; > - : bool = true > # let i2 = lazy 3;; > val i2 : int lazy_t = > # let o2 = Obj.repr i2;; > val o2 : Obj.t = > # Obj.is_block o2;; > - : bool = true > # Obj.tag o2 = Obj.double_tag;; > - : bool = false > both i1 and i2 have the same type, but only the first one is a block of > tag Obj.double_tag. A verification have to be done for both > argument. If you replace let i2 = lazy 3;; by let i2 = lazy 3.;; then what I've said became true. [...] -- Rémi Vanicat remi.vanicat@laposte.net ------------------- 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