Browse thread
[Caml-list] Weird behavior with nan's and min/max
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Doligez <damien.doligez@i...> |
| Subject: | Re: [Caml-list] Weird behavior with nan's and min/max |
On Thursday, October 16, 2003, at 11:40 PM, Yaron Minsky wrote: > let is_obj_nan x = > Obj.tag (Obj.repr x) = Obj.double_tag && > (let f = (Obj.magic x : float) in not (f = f)) [...] > The resulting code segfaulted on me, and the segfault went away when I > went back to the ordinary min and max. Does anyone have a thought on > this? Is this use of Obj safe or not? The problem is that the argument of Obj.tag must be a pointer value that lives in the heap. A pointer value answers false to Obj.is_int, but you have no way to test for heap-allocated values. This is going to change soon because I am fixing the bug found by Jacques with float lazy arrays, and in the process I will extend Obj.tag to give meaningful answers for ints and non-heap-allocated values. In the meantime, you can use the following code, but it might still fail in some rare cases when applied to non-heap-allocated values (I/O channels for example): let is_obj_nan x = not (Obj.is_int (Obj.repr x)) && Obj.tag (Obj.repr x) = Obj.double_tag && (let f = (Obj.magic x : float) in not (f = f)) ;; -- Damien ------------------- 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