Re: unsafeCoerce# between integral and floating point types

2010-07-09 Thread John Meacham
On Fri, Jul 09, 2010 at 07:14:58AM -1000, Lennart Augustsson wrote: > That might not work if the alignment constraints differ between the two types. Easy enough to fix, just compare the alignments and alloca with the greater of the two. the optimizer should be able to optimize out the test. of c

Re: unsafeCoerce# between integral and floating point types

2010-07-09 Thread Simon Marlow
On 08/07/2010 17:56, Daniel Fischer wrote: On Thursday 08 July 2010 18:15:44, Ian Lynagh wrote: On Thu, Jul 08, 2010 at 04:49:00PM +0200, Daniel Fischer wrote: unsafeCoerce# :: Word64# -> Double# ? By the docs, that isn't supposed to work. Is it not supposed to work only because it's not valu

Re: unsafeCoerce# between integral and floating point types

2010-07-08 Thread John Meacham
On Thu, Jul 08, 2010 at 04:49:00PM +0200, Daniel Fischer wrote: > If there are more pitfalls, is there any chance of getting a function which > reinterprets the bit-patterns? Hi, you can do something like this (untested): castWordToFloat :: Word32 -> Float castWordToFloat w = unsafePerformIO $ d

Re: unsafeCoerce# between integral and floating point types

2010-07-08 Thread Daniel Fischer
On Thursday 08 July 2010 18:15:44, Ian Lynagh wrote: > On Thu, Jul 08, 2010 at 04:49:00PM +0200, Daniel Fischer wrote: > > unsafeCoerce# :: Word64# -> Double# ? > > > > By the docs, that isn't supposed to work. Is it not supposed to work > > only because it's not value-preserving (unsafeCoerce# 1##

Re: unsafeCoerce# between integral and floating point types

2010-07-08 Thread Ian Lynagh
On Thu, Jul 08, 2010 at 04:49:00PM +0200, Daniel Fischer wrote: > > unsafeCoerce# :: Word64# -> Double# ? > > By the docs, that isn't supposed to work. Is it not supposed to work only > because it's not value-preserving (unsafeCoerce# 1## /=## 1.0##) or are > there more pitfalls? It can fail t

unsafeCoerce# between integral and floating point types

2010-07-08 Thread Daniel Fischer
The docs for unsafeCoerce# say: "The following uses of unsafeCoerce# are supposed to work (i.e. not lead to spurious compile-time or run-time crashes): # Casting any lifted type to Any # Casting Any back to the real type # Casting an unboxed type to another unboxed type of the same size (but not