Re: [Haskell-cafe] floating point operations and representation

2008-03-17 Thread David Roundy
On Wed, Mar 12, 2008 at 9:27 PM, Don Stewart [EMAIL PROTECTED] wrote: You could consider binding directly to the C functions, if needed, {-# OPTIONS -fffi -#include math.h #-} import Foreign.C.Types foreign import ccall unsafe math.h log10 c_log10 :: CDouble - CDouble

Re[2]: [Haskell-cafe] floating point operations and representation

2008-03-17 Thread Bulat Ziganshin
Hello David, Monday, March 17, 2008, 7:59:09 PM, you wrote: foreign import ccall unsafe math.h log10 c_log10 :: CDouble - CDouble log10 :: Double - Double log10 x = realToFrac (c_log10 (realToFrac x)) It's a bit sloppier, but shouldn't cause any trouble. And I've no

Re: [Haskell-cafe] floating point operations and representation

2008-03-17 Thread Jed Brown
On 17 Mar 2008, [EMAIL PROTECTED] wrote: Hello David, Monday, March 17, 2008, 7:59:09 PM, you wrote: foreign import ccall unsafe math.h log10 c_log10 :: CDouble - CDouble log10 :: Double - Double log10 x = realToFrac (c_log10 (realToFrac x)) It's a bit sloppier, but shouldn't cause any

Re: [Haskell-cafe] floating point operations and representation

2008-03-17 Thread Don Stewart
daveroundy: On Wed, Mar 12, 2008 at 9:27 PM, Don Stewart [EMAIL PROTECTED] wrote: You could consider binding directly to the C functions, if needed, {-# OPTIONS -fffi -#include math.h #-} import Foreign.C.Types foreign import ccall unsafe math.h log10 c_log10

Re: [Haskell-cafe] floating point operations and representation

2008-03-17 Thread John Meacham
On Mon, Mar 17, 2008 at 12:59:09PM -0400, David Roundy wrote: foreign import ccall unsafe math.h log10 log10 :: Double - Double since in ghc CDouble and Double are identical. It's a bit sloppier, but shouldn't cause any trouble. And I've no idea how realToFrac is implemented, but would

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Henning Thielemann
On Wed, 12 Mar 2008, Don Stewart wrote: I am under the restriction that I need to write Haskell programs using Double which mimic existing C/C++ programs or generated data sets, and get the same answers. (It's silly, but take it as a given requirement.) If the C programs are using log2, then

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Ketil Malde
Jacob Schwartz [EMAIL PROTECTED] writes: A test on IEEE computers (x86 and x86-64), shows that for a range of 64-bit double values, the answers in C do differ (in the last bit) if you use log2(x) and log10(x) versus log (x) / log(2) and log(x) / log(10). I think this may also depend on C

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Lennart Augustsson
Wow, you have a tough mission if you want to replicate the bit level answers for double (btw, hi Jacob). Libraries differ for transcendental function, and even worse, CPUs differ. You may get different answers on an Intel and and AMD. That said, I think your best bet is to import log2 and log10

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Jan-Willem Maessen
On Mar 12, 2008, at 8:35 PM, Jacob Schwartz wrote: My second question is how to get at the IEEE bit representation for a Double. My (rhetorical) question on this front isn't how do I get the representation, but why is it so hard and non-portable to get the representation sensibly? A

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Henning Thielemann
On Thu, 13 Mar 2008, Lennart Augustsson wrote: Wow, you have a tough mission if you want to replicate the bit level answers for double (btw, hi Jacob). Libraries differ for transcendental function, and even worse, CPUs differ. You may get different answers on an Intel and and AMD. That

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Alfonso Acosta
On Thu, Mar 13, 2008 at 1:35 AM, Jacob Schwartz [EMAIL PROTECTED] wrote: I have two questions about using the Double data type and the operations in the Floating typeclass on a computer that uses IEEE floating point numbers. I notice that the Floating class only provides log (presumably

Re: [Haskell-cafe] floating point operations and representation

2008-03-13 Thread Brandon S. Allbery KF8NH
On Mar 13, 2008, at 5:12 , Ketil Malde wrote: Perhaps now everybody uses SSE to do math, but earlier Intel FPU architectures did floating point with 80-bit registers, so the accuracy of the result could depend on whether an intermediate result was flushed to memory (by a context switch).

[Haskell-cafe] floating point operations and representation

2008-03-12 Thread Jacob Schwartz
I have two questions about using the Double data type and the operations in the Floating typeclass on a computer that uses IEEE floating point numbers. I notice that the Floating class only provides log (presumably log base 'e') and logBase (which, in the latest source that I see for GHC is

Re: [Haskell-cafe] floating point operations and representation

2008-03-12 Thread Don Stewart
quark: I have two questions about using the Double data type and the operations in the Floating typeclass on a computer that uses IEEE floating point numbers. I notice that the Floating class only provides log (presumably log base 'e') and logBase (which, in the latest source that I see for

[Haskell-cafe] floating point operations and representation

2008-03-12 Thread Don Stewart
I am under the restriction that I need to write Haskell programs using Double which mimic existing C/C++ programs or generated data sets, and get the same answers. (It's silly, but take it as a given requirement.) If the C programs are using log2, then I need log2 in the Haskell, or else I