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
[Caml-list] Finding the sign of a float
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-02-01 (09:08)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] Finding the sign of a float

>I'm looking for a way, in pure ocaml without having to bail out to C, to
>tell if a float is negative or not.
>Just using x < 0.0 won't work, as I need to be able to tell the difference
>between -0.0 and +0.0. This is for ocaml versions of the C copysign and
>signbit functions. Any suggestions?

let is_neg v =
(Int64.shift_right_logical (Int64.bits_of_float v) 63) = Int64.one


PS.  My kingdom for overloaded arithmetic operators and Int32/64 constants.

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners