Re: [Haskell-cafe] abs on Float/Doubles

2013-04-10 Thread Levent Erkok
It was pointed out to me that the precise issue came up before in the libraries list in January 2011 as well: http://www.haskell.org/pipermail/libraries/2011-January/015761.html From the archives; it appears that proposal didn't generate much discussion either. I think everyone is agreed on the

[Haskell-cafe] abs on Float/Doubles

2013-04-07 Thread Levent Erkok
Hello all, I definitely do not want to create a yet another thread on handling of floating-point values in Haskell. My intention is only to see what can be done to make it more compilant with IEEE754. (Also, my interest is not a theoretical one, but rather entirely practical: I'm interested in

Re: [Haskell-cafe] abs on Float/Doubles

2013-04-07 Thread Richard A. O'Keefe
On 8/04/2013, at 11:21 AM, Levent Erkok wrote: It appears that the consensus is that this is a historical definition dating back to the times when IEEE754 itself wasn't quite clear on the topic itself, and so nobody thought that hard about negative zeroes. (The quote is from a comment from

[GHC] #7198: New codegen more than doubles compile time of T3294

2012-08-29 Thread GHC
#7198: New codegen more than doubles compile time of T3294 -+-- Reporter: simonmar | Owner: simonmar Type: bug | Status: new Priority: high

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Christian Maeder
Andy Gimblett schrieb: Hi Christian, [...] It may make sense to use something like readMaybe (which is missing in the Prelude) instead of read to allow the parser to fail more nicely. It seems to be kicking up reasonable errors as it is, e.g.: *Main parse aFloat 2e-h Left (line 1,

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Evan Laforge
real :: Parser String real = do  d - decimal  f - option $ do    p - char '.'    n - many1 digit    return $ p : n Just to throw two bits in here, this is the only style that doesn't require leaning on the space bar and squinting to line things up, doesn't require any fancy editor

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-25 Thread Andy Gimblett
Hi Christian, On 24 Feb 2010, at 13:24, Christian Maeder wrote: I hope you don't mind if I make some style comments to your final version. Not at all - thanks! 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) I'm not

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-25 Thread Neil Brown
Andy Gimblett wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) I'm not convinced by this; perhaps while editing the code it's useful, but those changes don't happen very often, and when they do, any half-decent

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Christian Maeder
Andy Gimblett schrieb: For the record, here's the final improved version: Hi Andy, I hope you don't mind if I make some style comments to your final version. 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) 2. The t ::

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Ben Millwood
On Wed, Feb 24, 2010 at 1:24 PM, Christian Maeder christian.mae...@dfki.de wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) You can also break it immediately before do, which I think is sometimes more clear.

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-24 Thread Christian Maeder
Ben Millwood schrieb: On Wed, Feb 24, 2010 at 1:24 PM, Christian Maeder christian.mae...@dfki.de wrote: 1. break the line after do (to avoid a layout change when change name or arguments of float' or rename the variable e) You can also break it immediately before do, which I think is

[Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett
-with-quickcheck/ That is, each syntactic category gets a pretty-printer and a parser and an Arbitrary instance, and QuickCheck checks that (parse . prettyPrint) == id, basically. Somewhat unsurprisingly, this sometimes fails for floating point values (I'm using Doubles). Now, I know

Re: [Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Daniel Fischer
point values (I'm using Doubles). Now, I know that floats are in some sense imprecise, and comparing for equality is fraught with peril, but it seems that if x==x then it ought to be at least _possible_ to arrange matters such that (parse . prettyPrint x) == x as well. At worst, pretty

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Christian Maeder
category gets a pretty-printer and a parser and an Arbitrary instance, and QuickCheck checks that (parse . prettyPrint) == id, basically. Somewhat unsurprisingly, this sometimes fails for floating point values (I'm using Doubles). Now, I know that floats are in some sense imprecise, and comparing

[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett
Short version: How can I pretty print and parse values of type Double such that those operations are each other's inverse? Maybe you have more luck with show and read (without Parsec.Token). Your example: x = 9.91165677454629 fails because the computation performed by the parser 9.0 +

Re: [Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Lennart Augustsson
gets a pretty-printer and a parser and an Arbitrary instance, and QuickCheck checks that (parse . prettyPrint) == id, basically.  Somewhat unsurprisingly, this sometimes fails for floating point values (I'm using Doubles). Now, I know that floats are in some sense imprecise, and comparing

Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett
For the record, here's the final improved version: float' :: TokenParser st - GenParser Char st Double float' t = do n - liftCtoS '-' w - many1 digit char '.' f - many1 digit e - option $ do char 'e' n' -

[Haskell-cafe] Data.Binary and serialising doubles in IEEE format

2008-01-09 Thread allan
Dear all I have what I think should be a relatively simple problem: I have a C program which reads in data from a binary file, it is a specific format so it knows that there are 3 integers followed by three doubles or whatever. So I'm trying to serialise the data from within a Haskell program

Re: [Haskell-cafe] Data.Binary and serialising doubles in IEEE format

2008-01-09 Thread Adam Langley
On Jan 9, 2008 5:18 AM, allan [EMAIL PROTECTED] wrote: Essentially then, is there anyone that can write my 'putDouble' function or give some hint as to how I might do it. For the moment assume that I'm not really concerned with portability across platforms at least for the time being (I

Re: [GHC] #1239: compare on exceptional Doubles and Floats should raise an error

2007-03-21 Thread GHC
#1239: compare on exceptional Doubles and Floats should raise an error +--- Reporter: igloo | Owner: Type: proposal| Status: closed Priority: normal

[GHC] #1239: compare on exceptional Doubles and Floats should raise an error

2007-03-20 Thread GHC
#1239: compare on exceptional Doubles and Floats should raise an error ---+ Reporter: igloo | Owner: Type: proposal| Status: new Priority: normal

Re: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-15 Thread Roberto Zunino
Bayley, Alistair wrote: I've built a small test case. When I compile with: ghc Main.hs test.c -o Main.exe ... the (correct) output from Main.exe is: 123.0 5678901234567890 And when I compile with: ghc -prof Main.hs test.c -o Main.exe ... the (incorrect) output from Main.exe is: 1.0 986516178 I

RE: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-15 Thread Simon Marlow
On 15 September 2004 00:33, Roberto Zunino wrote: However, compiling with ghc -prof Main.hs test.c -#include test.h or s/-prof/-fvia-C/, works fine, provided test.h contains the correct function prototypes. -- test.h long long myInt64(void); double myDouble(void); --

RE: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-14 Thread Bayley, Alistair
I've built a small test case. When I compile with: ghc Main.hs test.c -o Main.exe ... the (correct) output from Main.exe is: 123.0 5678901234567890 And when I compile with: ghc -prof Main.hs test.c -o Main.exe ... the (incorrect) output from Main.exe is: 1.0 986516178 -- Main.hs: {-#

Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-13 Thread Bayley, Alistair
(using GHC 6.2.1 under Windows XP) I'm trying to use the Sqlite (version 3) dll - see http://www.sqlite.org/ . Marshalling of 32-bit ints and Strings works well, but 64-bit Ints and Doubles fail (I get garbage back from the FF calls) when I compile with -prof -auto-all. If I compile without

Re: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-13 Thread Krasimir Angelov
--- Bayley, Alistair [EMAIL PROTECTED] wrote: (using GHC 6.2.1 under Windows XP) I'm trying to use the Sqlite (version 3) dll - see http://www.sqlite.org/ . Hi Alistair, HSQL already provides binding to sqlite. I don't know whether you will have the same problem with profiling version of

RE: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-13 Thread Bayley, Alistair
, just to make sure the problem isn't with the Sqlite dll. -Original Message- From: Krasimir Angelov [mailto:[EMAIL PROTECTED] Sent: 13 September 2004 10:53 To: Bayley, Alistair; [EMAIL PROTECTED] Subject: Re: Profiling makes FFI Marshalling of Doubles and Int64s fail --- Bayley

RE: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-13 Thread Krasimir Angelov
--- Bayley, Alistair [EMAIL PROTECTED] wrote: Thanks Krasimir. I did have a look at your code, but I don't see any foreign types other than CString and Int, which work OK for me regardless of profiling option. (BTW, you tend to use Int rather than CInt - is this safe?) Good suggestion.

RE: Profiling makes FFI Marshalling of Doubles and Int64s fail

2004-09-13 Thread Bayley, Alistair
: 13 September 2004 12:28 To: Bayley, Alistair; [EMAIL PROTECTED] Subject: RE: Profiling makes FFI Marshalling of Doubles and Int64s fail --- Bayley, Alistair [EMAIL PROTECTED] wrote: Thanks Krasimir. I did have a look at your code, but I don't see any foreign types other than

Number conversions, like floats to doubles

2003-11-08 Thread Ben Escoto
Quick and probably stupid question: If I want to convert a Float to a Double, should I use fromRational . toRational ? It seems to work, but isn't this a bit weird? It took a while for me to figure this out. I suppose they are rationals because of the finite precision of Floats and Doubles

Re: Number conversions, like floats to doubles

2003-11-08 Thread Hal Daume III
to figure this out. I suppose they are rationals because of the finite precision of Floats and Doubles? And similarly, (fromInteger . toInteger) is the right way to convert the integral types? Why not just have a function like: convertIntegral :: (Integral a, Integral b) = a - b

Re: Number conversions, like floats to doubles

2003-11-08 Thread Marcin 'Qrczak' Kowalczyk
W licie z sob, 08-11-2003, godz. 22:41, Ben Escoto pisze: If I want to convert a Float to a Double, should I use fromRational . toRational realToFrac :: (Fractional b, Real a) = a - b It is actually defined as fromRational . toRational but GHC knows to generate specialized code for

Re: Number conversions, like floats to doubles

2003-11-08 Thread Marcin 'Qrczak' Kowalczyk
W licie z sob, 08-11-2003, godz. 22:59, Hal Daume III pisze: In NumExts, there's floatToDouble and doubleToFloat. It's a GHC extension, while realToFrac is Haskell 98. -- __( Marcin Kowalczyk \__/ [EMAIL PROTECTED] ^^ http://qrnik.knm.org.pl/~qrczak/

Re: Number conversions, like floats to doubles

2003-11-08 Thread Ben Escoto
On Sun, 09 Nov 2003 01:11:09 +0100 Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] wrote: realToFrac :: (Fractional b, Real a) = a - b It is actually defined as fromRational . toRational but GHC knows to generate specialized code for particular types. Oops, I was looking through the prelude but

Re: Floats and Doubles

2002-11-13 Thread Jan Kort
Juan Ignacio Garcia Garcia wrote: *P2 (fromRational ((toRational 4) - ( toRational 5.2 ))) -1.2002 I can't explain this one, how would fromRational know that it has to create a Double ? Jan ___ Glasgow-haskell-users mailing list [EMAIL

Re: Floats and Doubles

2002-11-13 Thread Josef Svenningsson
On Wed, 13 Nov 2002, Jan Kort wrote: Juan Ignacio Garcia Garcia wrote: *P2 (fromRational ((toRational 4) - ( toRational 5.2 ))) -1.2002 I can't explain this one, how would fromRational know that it has to create a Double ? It's the defaulting mechanism that kicks in. The

RE: Floats and Doubles

2002-11-13 Thread Simon Marlow
But this brings up a strange thing in GHCi. Suppose I load the following module into GHCi: \begin{code} module Foo where kalle = (fromRational ((toRational 4) - ( toRational 5.2 ))) default (Rational) \end{code} What happens is the following: Prelude :l Foo.hs Compiling Foo

Floats and Doubles

2002-11-12 Thread Juan Ignacio Garcia Garcia
hello, I have been using some of the functions of the classes Real and Fractional and I have observed that with the funcion toRational we can obtain the fraction that represents a given number. For instance: *P2 toRational (5.2::Float) 5452595 % 1048576 Why we obtain this numbers instead of 52 %

RE: Floats and Doubles

2002-11-12 Thread Simon Marlow
I have been using some of the functions of the classes Real and Fractional and I have observed that with the funcion toRational we can obtain the fraction that represents a given number. For instance: *P2 toRational (5.2::Float) 5452595 % 1048576 Why we obtain this numbers instead of 52

Re: Floats and Doubles

2002-11-12 Thread Lennart Augustsson
Yes, they all seem to be right. You get these funny effects because numbers like 5.2 do not have an exact representation with floating point numbers in base to (like Float and Double most likely have on your machine). The number 5.2 is stored as a slightly different number as a Float, but the

Re: Floats and Doubles

2002-11-12 Thread Jerzy Karczmarczuk
Lennart Augustsson wrote: The number 5.2 is stored as a slightly different number as a Float, but the toRational function is exact so it gives you the number corresponding to the internal representation. Take a course on numerical analysis. :) Nope. Take a course entitled: Why all you

RE: doubles

2000-08-11 Thread Julian Seward (Intl Vendor)
| -Original Message- | From: Jan Skibinski [mailto:[EMAIL PROTECTED]] | Sent: Thursday, August 10, 2000 3:11 PM | To: [EMAIL PROTECTED] | Cc: [EMAIL PROTECTED] | Subject: Re: doubles | | | | | Aha . And how many digits will GHC offer me? | | I would think that you will get

doubles

2000-08-10 Thread Sebastian Schulz
Hi! How can I use Doubles which are more exact than six digits? For example HUGS gives me : 1,23456789 1.23457 I want to rotate coordinates with eulerian matrizes and I'm using the pi from the Prelude ( 6 digits). After about 1000 360°-rotations I have an error of about 0.1% ; but I want

Re: doubles

2000-08-10 Thread Jan Skibinski
On Thu, 10 Aug 2000, Sebastian Schulz wrote: Hi! How can I use Doubles which are more exact than six digits? For example HUGS gives me : 1,23456789 1.23457 1. What you see printed and what is used in internal computations are two different things. 2

Re: doubles

2000-08-10 Thread John Peterson
Or you can just set USE_DOUBLE_PRECISION in options.h if you want to rebuild hugs. John

Re: doubles

2000-08-10 Thread Sebastian Schulz
Jan Skibinski wrote: 1. What you see printed and what is used in internal computations are two different things. In HUGS I can see 6 digits. How many are used in the intrnal computation? 2. But Hugs'es Double is the same as Float, anyway. This used to

Re: doubles

2000-08-10 Thread Jan Skibinski
Aha . And how many digits will GHC offer me? I would think that you will get the same number of digits as is available for C - unless some bits are reserved for something special, which I am not aware of. For example, in some implementations of Smalltalk the

Re: doubles

2000-08-10 Thread Ralf Muschall
Sebastian Schulz [EMAIL PROTECTED] writes: John Peterson wrote: Or you can just set USE_DOUBLE_PRECISION in options.h if you want to I did that (to be precise, I had to do it every time when building hugs :-( ). pi::Double is defined by the prelude as primPiDouble, and this seems to be

Formatting doubles

2000-08-03 Thread Timothy Docker
Is there a means of formatting doubles in Haskell with the precision flexibilty of printf? The show method seems to only print the first few decimal places, and showGFloat in the numeric module seems to only display a similar number For example, in hugs... import Numeric x

First Bug in 4.08 - NCG handles floats as doubles in FFI

2000-07-08 Thread Manuel M. T. Chakravarty
It seems, as if I have the questionable pleasure of reporting the first bug in GHC 4.08: The NCG passes floats as doubles in foreign exports. If the appended code is compiled with the NCG (ie, without optimisation), the programs prints 0.0 instead of 101.0. If the C code is changed to use

Re: doubles-troubles

1998-05-12 Thread Simon L Peyton Jones
rigid and I belong to the small legion of amateurs who implemented their own math. domain system, Rings, Fields, Modules, etc. This apparently has no chance to be included into the Haskell standard, nobody cares. Standards develop because people who care about particular aspects of them push