<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/ef4a5558eeba1a0b9901b9af7a62d4cf"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-10-20T13:29:23"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max"
  prev="2003/10/cfa911e3b712c43b2fc866b72cf72620"
  next="2003/10/ae21027a037cf89c74ed354226a8cb16"
  prev-in-thread="2003/10/2547e7d7d785deed112b4caad2e8f5c2"
  next-in-thread="2003/10/ae21027a037cf89c74ed354226a8cb16"
  prev-thread="2003/10/bb6652d3ee0174ff91bc648fa5125d46"
  next-thread="2003/10/6638aad0140dc99b2349c854da4948c3"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/686468535e6100213e2e85bca8be51f1"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-14T14:37:18"
  subject="[Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/3133ffc353d5d33e5386f5e4c73b858f"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-14T14:56:56"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/48561de698e6c05397123c5888cc4dc1"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-14T20:52:17"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/22b8f0ac4fb38072f78facd4bf9434a7"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-10-14T23:45:32"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/242867c4c7ffbfa1014a17fb343b34a9"
  from="Hendrik Tews &lt;tews@t...&gt;"
  author="Hendrik Tews"
  date="2003-10-16T17:29:55"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/10/0b43b6a621394f9ecc76084111d3253d"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-10-16T13:17:07"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/896e4961fd3e3f4a71d469b298ebc60e"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-16T14:01:29"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/0eef11bc0ed3dcaefa1de6d2feea29a3"
  from="Christophe TROESTLER &lt;debian00@t...&gt;"
  author="Christophe TROESTLER"
  date="2003-10-17T09:25:50"
  subject="[Caml-list] Test nan (was: Weird behavior with nan&apos;s and min/max)">
</msg>
</msg>
<msg 
  url="2003/10/a832440f4488e9cf40654b2ad77a5c76"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-16T21:40:46"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/dc6b874ec397bff1e2016e7a813019ca"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-16T21:50:35"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
</msg>
<msg 
  url="2003/10/c1eb0f38b646fdaf599a7528eb9c4ee6"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-10-16T22:52:06"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
</msg>
</msg>
<msg 
  url="2003/10/84ed68a791de5fdc1f6098100bd856e4"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-10-17T14:56:33"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/dd582ea4978aa94ec44762de52be023d"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-17T15:14:06"
  subject="Floating point exceptions (Was Re: [Caml-list] Weird behavior with  nan&apos;s and min/max)">
</msg>
<msg 
  url="2003/10/2547e7d7d785deed112b4caad2e8f5c2"
  from="Yaron M. Minsky &lt;yminsky@c...&gt;"
  author="Yaron M. Minsky"
  date="2003-10-17T23:56:05"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/ef4a5558eeba1a0b9901b9af7a62d4cf"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-10-20T13:29:23"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/ae21027a037cf89c74ed354226a8cb16"
  from="Yaron Minsky &lt;yminsky@c...&gt;"
  author="Yaron Minsky"
  date="2003-10-20T13:43:13"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
<msg 
  url="2003/10/3ed5948ec142822cf10a8e406fdc428b"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-10-20T14:24:47"
  subject="Re: [Caml-list] Weird behavior with nan&apos;s and min/max">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/10/84b26be77ae760b6c6d2291d12cde704"
  from="Jed Davis &lt;jdev@p...&gt;"
  author="Jed Davis"
  date="2003-10-17T15:54:27"
  subject="[Caml-list] Re: Weird behavior with nan&apos;s and min/max">
</msg>
</msg>
</thread>

<contents>
&gt; &gt; Doesn't the polymorphic comparison have to be a total order?

Pervasive.compare must be a total order, so it would need to throw an
exception if its arguments are unordered (e.g. one is "nan").
The other comparisons (=, &lt;, etc) could implement a partial order,
returning "false" in the "unordered" case (except for &lt;&gt;, which should
return "true" in this case).

&gt; This kind of wigs me out too.  For example, do the set and map data
&gt; structures depend on this total order property?  What happens when I
&gt; stick in a data structure which contains some floats somewhere in it,
&gt; and some of those floats are nan's?  Does the data structure continue to
&gt; work at all?  It totally wigs me out.

Sets and maps require a total order, so, yes, in the current
implementation, strange things can happen with "nan" used as set
elements or map keys.  Again, throwing an "unordered" exception in
Pervasives.compare would avoid the problem.  

Note, however, that it doesn't make much sense to use floats as set
elements or map keys, due to the inherently approximate nature of floats.
E.g. does the set {1.0; 1.0+.epsilon} have 1 or 2 elements?

&gt; I wish there was some sensible way around it.  Probably the thing I
&gt; would like best is for calculations that produce nans to throw
&gt; exceptions.  But from what I've heard so far, this doesn't appear to be
&gt; possible.

The IEEE standard specifies both behaviors: return nan or cause a
floating-point trap, and says that there should be an API to choose
the desired behavior.  Most processors implement the two behaviors,
controlled by some status bit somewhere.

The first problem is that there is no standard C API to select the
desired behavior (even ISO C 99 isn't terribly clear on this).  So,
everyone stays in the "nans, no traps" mode.

&gt; Here's another question:  is it possible to catch floating point
&gt; exceptions such as division by zero?  It seems like that might be another
&gt; way of dealing with this.  I thought catching SIGFPE would do it, but I
&gt; tried and I couldn't seem to get it triggered.  Is it possible to convert
&gt; floating point exceptions to ocaml exceptions?

That's the second problem.  Trapping a synchronous signal (such as
SIGFPE) and turning it into a Caml exception is quite hard and
non-portable.  Caml manages to deal with asynchronous signals by
delaying their delivery until a safe point is reached, but obviously
this doesn't work for synchronous, program-generated signals.  
E.g. what to do if the SIGFPE comes from C code running in "blocking
section" mode?

- Xavier Leroy

-------------------
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

</contents>

</message>

