English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
float rounding
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-10-03 (19:59)
From: Christophe Raffalli <Christophe.Raffalli@u...>
Subject: Re: [Caml-list] float rounding
Sean McLaughlin a écrit :
> Hello,
>   I'm using Ocaml for an interval arithmetic application.  I"m curious 
> about
> what the Ocaml parser/compiler does to float constants.  May I assume
> that for any constant I enter, eg. 3.1415... (for N digits of pi), that
> the compiler will give me a closest machine representable number?
> i.e., if I bound a constant by the previous and next floating point 
> value to
> that given me by the compiler,
> will it always be the case that my original (mathematical) constant 
> lies in that interval?

By the way, float constants need to be written in hexadecimal and this 
is missing to
the printf/scanf functions (it is what man printf says at least) ... 
just compute how many decimals you need to write the exact value of 
2^{-n} as a decimal float constant (0,5 0,25 0,125 0,625e-1 0,3125e-1 ...).

Then, I am not sure  the algorithm used to parse the constant will give 
you the correct value and you will never know how many decimals you need 
to write your constant.

The only problem with float and hexadecimal is to learn the hexadecimals 
of pi, e, ln 2, sqrt 2, ... ;-)

Christophe Raffalli