Browse thread
CAMLreturn does not work for floats between 0 and 1 ?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Matthieu Dubuget <matthieu.dubuget@l...> |
| Subject: | CAMLreturn does not work for floats between 0 and 1 ? |
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);
}
-----------------------------------------------------