From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id A7F8EBC6B for ; Sat, 17 Feb 2007 01:30:30 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1H0USOE027594 for ; Sat, 17 Feb 2007 01:30:29 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l1H0UPZD000943; Sat, 17 Feb 2007 09:30:26 +0900 (JST) Date: Sat, 17 Feb 2007 09:30:18 +0900 (JST) Message-Id: <20070217.093018.48529252.garrigue@math.nagoya-u.ac.jp> To: matthieu.dubuget@laposte.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] CAMLreturn does not work for floats between 0 and 1 ? From: Jacques Garrigue In-Reply-To: <45D5C3AD.2000606@laposte.net> References: <45D5C3AD.2000606@laposte.net> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45D64CA4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlreturn:01 matthieu:01 dubuget:01 matthieu:01 dubuget:01 camlreturn:01 camlparam:01 val:01 val:01 printf:01 camlparam:01 callbacks:01 initialized:01 caml-list:01 macros:01 From: Matthieu Dubuget > > I'm sure I'm doing something bad. But I can't find out where? > > The problem is that when I CAMLreturn float : r with 0. < r < 1., > I get 0.00000000. > > double f (int i){ > CAMLparam0 (); > double r; > static value *cr = NULL; > if (cr == NULL) cr = caml_named_value("f"); > r = Double_val(caml_callback(*cr, Val_int(i))); > printf("f: r(%d)=%.5f\n", i, r); > CAMLreturn(r); > } As pointed by others, CAMLreturn can only be used for values of type "value" (i.e. long int). In this specific case, you need register no root with the GC, so there is no point in using CAMLparam0/CAMLreturn. If you need to register roots with the GC in such a function (because you're calling two caml callbacks with an allocation in between, for instance) then you must use different macros. In 3.10, there is a new macro CAMLreturnT for this kind of situations. Before that, you can also use the older interface Begin_roots/End_roots. value v1 = 0, v2 = 0; // v1 and v2 must be initialized Begin_roots2(v1, v2); ... v1 and v2 are registered ... End_roots(); // pop v1 and v2 return r; Jacques Garrigue