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.5 required=5.0 tests=AWL 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 E6304BC6B for ; Fri, 16 Feb 2007 15:46:06 +0100 (CET) Received: from smtp24.orange.fr (smtp24.orange.fr [193.252.22.26]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1GEk6nF008759 for ; Fri, 16 Feb 2007 15:46:06 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2416.orange.fr (SMTP Server) with ESMTP id 732E11C00095 for ; Fri, 16 Feb 2007 15:46:06 +0100 (CET) Received: from drakar.stremy.local (ADijon-258-1-112-64.w90-13.abo.wanadoo.fr [90.13.111.64]) by mwinf2416.orange.fr (SMTP Server) with ESMTP id 3853F1C00090 for ; Fri, 16 Feb 2007 15:46:06 +0100 (CET) X-ME-UUID: 20070216144606230.3853F1C00090@mwinf2416.orange.fr Received: from [192.168.0.25] (helo=[192.168.0.25]) by drakar.stremy.local with esmtp (Exim 3.36 #1 (Debian)) id 1HI4NQ-0003Wt-00 for ; Fri, 16 Feb 2007 15:47:56 +0100 Message-ID: <45D5C3AD.2000606@laposte.net> Date: Fri, 16 Feb 2007 15:46:05 +0100 From: Matthieu Dubuget Reply-To: matthieu.dubuget@laposte.net User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: caml-list@inria.fr Subject: CAMLreturn does not work for floats between 0 and 1 ? X-Enigmail-Version: 0.94.1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-j-chkmail-Score: MSGID : 45D5C3AE.003 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45D5C3AE.003 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; matthieu:01 dubuget:01 matthieu:01 dubuget:01 camlreturn:01 camlreturn:01 ocaml:01 ocaml:01 cygwin:01 stdio:01 mlvalues:01 alloc:01 camlparam:01 val:01 val:01 Hello list! 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. The OCaml functions are in testdouble. The main test is in testd.c. It prints (ses main function at the end) : I=5: f: r(5)=0.00500 <--------- values just returned from OCaml f2: r(5)=5.00000 r1: f(5)=0.00000 <-------------- WHY? r2: f2(5)=5.00000 I reproduced this with version 3.09.3 of cygwin OCaml and godi (Ubuntu) ocaml. Really I do not understand what is going on? Salutations Matt ----------------------- testdouble.ml --------------------- let f i = float i /. 1000. let f2 i = float i let _ = Callback.register "f" f and _ = Callback.register "f2" f2 ----------------------------------------------------------- ---------------- testd.c ------------------------------------- #include #include #include #include #include static int ms_visus_init_done = 0; void ms_visus_init (void) { char *vide[2]; vide[0] = "bof"; vide[1] = NULL; if (!ms_visus_init_done) { caml_startup (vide); ms_visus_init_done = 1; } } 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); } double f2(int i){ CAMLparam0 (); double r; static value *cr = NULL; if (cr == NULL) cr = caml_named_value("f2"); r = Double_val(caml_callback(*cr, Val_int(i))); printf("f2: r(%d)=%.5f\n", i, r); CAMLreturn(r); } int main(){ int i; double r1, r2; ms_visus_init(); i=5; printf("I=%d:\n",i); r1 = f(i); r2 = f2(i); printf("r1: f(%d)=%.5f\n", i, r1); printf("r2: f2(%d)=%.5f\n", i, r2); exit (0); } -----------------------------------------------------