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
Typing problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-02-25 (17:05)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Some questions about floatting point issues
> The problem is that, to write a correct interval library, you have to
> use some processor specific features regarding rounding mode (you have
> to turn it to rounding towards minus infinity when computing lower
> bounds, towards plus infinity when computing upper bound, etc).
> I wrote the assembly language routines to do the trick, but I have a few
> questions:
> 1) What is the default mode turned on by ocaml (I suppose it is rounding
> towards nearest?)

Caml doesn't change the rounding mode, it leaves whatever mode the C
run-time system sets before starting the Caml program.

(Not quite: on buggy libc's, e.g. libc 5 under Linux, Caml used to
change the mode at start-up to enable NaNs and other IEEE features,
but this is no longer necessary with Linux libc 6.)

> 2) Is this mode often reinforced (before each floatting point operation)
> or is it only set once?

It is never reinforced.  On the x86, float->int conversion changes the
rounding mode temporarily, but restores the original mode on exit.

> 3) Is it possible to tell ocamlopt to inline a few lines of assembly
> code? Changing the FPU mode is very fast (two "mov", one "and" and one
> "or") and it is a pity to suffer the overhead of one function call each
> time.

I agree that an inline asm facility would sometimes be useful, but
there is currently no such thing in Caml.

One little trick: assuming your C function to change mode doesn't
allocate and doesn't raise exceptions, you could declare it as

        external changemode : unit -> unit = "changemode" "noalloc"

The "noalloc" qualifier allows ocamlopt to generate a faster call to
the C routine.

- Xavier Leroy