caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* CAMLreturn does not work for floats between 0 and 1 ?
@ 2007-02-16 14:46 Matthieu Dubuget
  2007-02-16 15:09 ` [Caml-list] " Daniel Bünzli
  2007-02-17  0:30 ` Jacques Garrigue
  0 siblings, 2 replies; 8+ messages in thread
From: Matthieu Dubuget @ 2007-02-16 14:46 UTC (permalink / raw)
  To: caml-list

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);
}
-----------------------------------------------------





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-02-17  0:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-16 14:46 CAMLreturn does not work for floats between 0 and 1 ? Matthieu Dubuget
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).