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: | Daniel_Bünzli <daniel.buenzli@e...> |
| Subject: | Re: [Caml-list] CAMLreturn does not work for floats between 0 and 1 ? |
Le 16 févr. 07 à 20:19, Matthieu Dubuget a écrit : > At the first place, except the fact that I misused the macros, I still > do not understand why CAMLreturn(0.05) would return 0.? Because CAMLreturn assumes its parameter is a value of the C type 'value' which represent a value of the ocaml runtime system and can be either (from the doc) : > an unboxed integer; > a pointer to a block inside the heap (such as the blocks allocated > through one of the caml_alloc_* functions below); > a pointer to an object outside the heap (e.g., a pointer to a block > allocated by malloc, or to a C variable). Its something the caml runtime wants not your C code. On a 32 bit platform the type 'value' is a 32 bit integer so when your return your double with CAMLreturn it is cast to a 32 bit integer [1] and then after that cast again to a double. Hence you lose the fractional part. It doesn't make sense to use CAMLreturn with anything but a caml value. Best, Daniel [1] Have a look at the definition of CAMLreturn in <caml/memory.h>.