Version française
Home     About     Download     Resources     Contact us    
Browse thread
Floating exception
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dmitry Bely <dmitry.bely@g...>
Subject: Re: [Caml-list] Floating exception
On Nov 26, 2007 8:25 PM, Sebastien Ferre <Sebastien.Ferre@irisa.fr> wrote:

> I've got the same problem with the simplest program,
> the "hello world" :
>
> let _ = print_string "Hello world!\n"
>
>
> * Machine where compiled (in native code):
>
> Linux version 2.6.20-1.2952.fc6
> (brewbuilder@ls20-bc1-14.build.redhat.com) (gcc
> version 4.1.1 20070105 (Red Hat 4.1.1-51)) #1 SMP Wed May 16 18:59:18
> EDT 2007
> Intel(R) Core(TM) Duo CPU      U2500  @ 1.20GHz
>
>
> * Machine where execution produces "Floating exception"

It could be Ocaml runtime initialization. I've faced it under Windows
then loaded Ocaml DLL from Borland C-compiled program. The problem was
that Pervasives.infinity

let infinity =
  float_of_bits 0x7F_F0_00_00_00_00_00_00L

expects (due to float_of_bits) FP control word to be set some specific
way otherwise floating-point exception will occur. I worked around it
as follows:

      const unsigned newState =_EM_DENORMAL|
          _EM_INEXACT|_EM_UNDERFLOW|_EM_OVERFLOW|EM_ZERODIVIDE|_EM_INVALID;
      unsigned oldState = _control87(newState, _MCW_EM);
      caml_startup(argv);
      _control87(oldState, _MCW_EM);

(Don't remember which flags are really necessary - I just duplicated
the default MSVC compiler state that worked)

Probably this is Ocaml bug as its runtime should not depend on the
default state of FP control word and should set in explicitly.

- Dmitry Bely