From: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
To: matthieu.dubuget@laposte.net
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] CAMLreturn does not work for floats between 0 and 1 ?
Date: Fri, 16 Feb 2007 23:28:21 +0100 [thread overview]
Message-ID: <094AF8BA-F1B1-4C06-B9AF-E215842649A5@epfl.ch> (raw)
In-Reply-To: <45D603A4.7080500@laposte.net>
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>.
next prev parent reply other threads:[~2007-02-16 22:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-16 14:46 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 [this message]
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=094AF8BA-F1B1-4C06-B9AF-E215842649A5@epfl.ch \
--to=daniel.buenzli@epfl.ch \
--cc=caml-list@inria.fr \
--cc=matthieu.dubuget@laposte.net \
/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