Haskell - Java and floats

2001-09-30 Thread pachinko

Has anyone ever tried to pass/receive a float to/from a Java app? If so, how did you 
manage it?

I need an algorithm for converting an IEEE 754 format float to a 32 bit integer?

I want something that can convert a haskell float into a int that can be stored to 
disk for later input to a Java app that converts it back to a float with the Java 
floatToIntBits function.

I think I'm OK in the reverse direction, converting an int into a float (as 
implemented by the Java intBitsToFloat function). The following link to the Java docs 
gives the bit masks and expression required to convert an int to a float.

http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Float.html

Unfortunately, although the page gives a brief description of the the floatToIntBits 
function, specfically how to place the components of the floating point number into a 
32 bit int, it doesn't describe how to extract those components. Things seem to be 
complicated a bit by things such as the hidden bit, and Java interpreting the floating 
point to the far left of the mantissa, instead of the far right.

I found the following page describing how the floatToIntBits function works, but I 
think it's wrong, since when I try to run this function it gives a different integer 
that when I use the standard Java floatToIntBits function. Maybe the page describes a 
different version of the IEEE format?

http://www.jos.org/redist/kore-0.0.7/java.lang.Float.src.html

I'm not an expert on any of this - so any algorithm, in any language (including 
english), would be much appreciated.

BTW - all of the above applies double (64 bit integer, 
doubleToIntBits/intBitsToDouble).


_
Global Virtual Desktop
http://www.magicaldesk.com


___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Machine bit representations

2001-07-24 Thread pachinko

Hello,

Is it possible in Haskell to access the underlying machine bit representation of a 
Float or Double value?

I need to be able to be able to send this bit representation as a list of bytes in 
network byte order to a process running on a different platform (with a different host 
byte order to my platform).

For reference, I run Haskell under Linux on Intel. The processes I want to communicate 
with run under Sun Solaris, Hitachi HPUX and Java everywhere.

Any suggestions, for any Haskell translator much appreciated.

Thanks.


_
Global Virtual Desktop
http://www.magicaldesk.com


___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell