Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
From: John Carr <jfc@M...>
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?

x < 0.0 || (x = 0.0 && 1.0/.x < 0.0)

may be faster than converting the bits to integer, or slower,
depending on platform and context, and how often you encounter -0.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: