From: Matthieu Dubuget <matthieu.dubuget@laposte.net>
To: caml-list@inria.fr
Subject: CAMLreturn does not work for floats between 0 and 1 ?
Date: Fri, 16 Feb 2007 15:46:05 +0100 [thread overview]
Message-ID: <45D5C3AD.2000606@laposte.net> (raw)
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 <stdio.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/callback.h>
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);
}
-----------------------------------------------------
next reply other threads:[~2007-02-16 14:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-16 14:46 Matthieu Dubuget [this message]
2007-02-16 15:09 ` [Caml-list] " Daniel Bünzli
2007-02-16 16:20 ` Matthieu Dubuget
2007-02-16 17:02 ` Mathias Kende
2007-02-16 17:07 ` Daniel Bünzli
2007-02-16 19:19 ` Matthieu Dubuget
2007-02-16 22:28 ` Daniel Bünzli
2007-02-17 0:30 ` Jacques Garrigue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45D5C3AD.2000606@laposte.net \
--to=matthieu.dubuget@laposte.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox