Precision of `Double's in Hugs

Hi, (I'm just a new convertee to the ways of Functional Programming, so please go easy on me! ^_^;;) Why is it that `Double's in Hugs only seem to have the same precision as a `Float'? I've some code here that only iterates a few hundred times, and the amount of accuracy lost is getting a bit ridiculous ... Exactly[0] the same code produces the much more accurate results in GHCi. I'd switch over, but at the very least I'd like to know why this is happening. BTW: From the description at http://haskell.cs.yale.edu/communities/ , I seem to get the impression that haskell@haskell.org should only be used for announcements, yet the archive shows quite a bit of general discussion going on. Should I have posted this to the aforementioned list as well / instead? /Liyang [0] Minus the non-Haskell 98 compliant bits, like the missing fromInt ... -_- Took me a while to figure that one out. -- .--| Liyang Hu |--| http://nerv.cx/ |--| Caius@Cam |--| ICQ: 39391385 |--. | A [programming] language that doesn't affect the way you think | | about programming is not worth knowing. |

On Saturday 12 January 2002 17:35, you wrote:
(I'm just a new convertee to the ways of Functional Programming, so please go easy on me! ^_^;;)
Welcome. Hope you find it as fun and useful as I.
Why is it that `Double's in Hugs only seem to have the same precision as a `Float'? I've some code here that only iterates a few hundred times, and the amount of accuracy lost is getting a bit ridiculous ...
As the Hugs manual says in 9.1, The Double type is implemented as a single precision float (this isn't forbidden by the standard but it is unusual). But if you build Hugs yourself, there's a line in options.h /* Define if you want to use double precision floating point arithmetic */ #define USE_DOUBLE_PRECISION 0
From a bit of browsing the code, it appears that setting USE_DOUBLE_PRECISION will increase the precision of both Float and Double types.
BTW: From the description at http://haskell.cs.yale.edu/communities/ , I seem to get the impression that haskell@haskell.org should only be used for announcements, yet the archive shows quite a bit of general discussion going on. Should I have posted this to the aforementioned list as well / instead?
Haskell-cafe is fine for your question. For a description of the way the mailing lists are split, I'd recommend http://www.haskell.org/mailinglist.html.

Evening, Thanks for the near-instantaneous reply! On Sat, Jan 12, 2002 at 05:59:02PM -0500, Scott Turner wrote:
Welcome. Hope you find it as fun and useful as I.
I'm sure I will! My wee adventure into the world of functional programming has been nothing short of delightful so far, and there's so much more to figure out ...
Why is it that `Double's in Hugs only seem to have the same precision as a `Float'? As the Hugs manual says in 9.1, The Double type is implemented as a single precision float (this isn't forbidden by the standard but it is unusual).
Ah. They don't seem to give any justification for doing this either! ;_;
But if you build Hugs yourself, there's a line in options.h
'fraid I've been too spoilt by Debian, haven't built anything from source in ages ... I'll notify Hugs' package maintainer and see if I can convince him/her to apply this ...
From a bit of browsing the code, it appears that setting USE_DOUBLE_PRECISION will increase the precision of both Float and Double types.
Don't suppose the Haskell spec put a maximum precision level on Floats? (Or I take it it's the standard Double >= Float?) mata ne, /Liyang -- .--| Liyang Hu |--| http://nerv.cx/ |--| Caius@Cam |--| ICQ: 39391385 |--. | A [programming] language that doesn't affect the way you think | | about programming is not worth knowing. |

On Sun, Jan 13, 2002 at 01:43:32AM +0000, Liyang Hu wrote:
'fraid I've been too spoilt by Debian, haven't built anything from source in ages ... I'll notify Hugs' package maintainer and see if I can convince him/her to apply this ...
No trouble at all; I feel this should be the default as well, and I'll set it when I find the other packaging bugfix that was sent to me recently. By the way, where is the person who sent me the other bugfix? Can you resend? Thanks, Bill

On Sun, 13 Jan 2002, Liyang Hu wrote:
From a bit of browsing the code, it appears that setting USE_DOUBLE_PRECISION will increase the precision of both Float and Double types.
Note that I'd recommend getting some clarification about this from either the current hugs team or Mark Jones (who are probably reading this list), as I can vaguely recall a couple of times over the last few years where Mark Jone has said `Hugs should not be used for serious numerical work' without saying whether this is fixed just by that #define. I could imagine that there might be several other, deeper assumptions about using float's for both Float and Double in the source, e.g., if you pass a double to a Prelude math fn it does get passed in directly to an appropriate one and not cast to a float before being passed, etc. Hopefully there aren't any problems like this, but the worst thing would be to end up in the worst of both worlds where you pay the storage space for doubles and yet don't _reliably_ get more than float precision. ___cheers,_dave_________________________________________________________ www.cs.bris.ac.uk/~tweed/|`...heat generated by its microprocessors will email:tweed@cs.bris.ac.uk|slope upward exponentially, reaching the power work tel:(0117) 954-5250 |density of a nuclear reactor before 2010'-Intel

Hi Dave, | Note that I'd recommend getting some clarification about this from either | the current hugs team or Mark Jones (who are probably reading this list), | as I can vaguely recall a couple of times over the last few years where | Mark Jone has said `Hugs should not be used for serious numerical work' | without saying whether this is fixed just by that #define. There are two issues. First, Gofer (from which Hugs was later derived) was not written with numerical work in mind: I am wise enough to know that great care must be taken in numerical work to obtain accurate results, but I was not (nor am I still) wise enough to know exactly what is required. Frankly, numerical computation was never a priority in the development of Gofer; fitting it onto an old 8086 seemed challenge enough. Second, Hugs uses single precision by default because the implementation using double precision relies on a hack whose behavior is not assured in any way by the C language in which it is implemented. It does work just fine on many machines, but I would be wary about depending on it, and hence I wouldn't encourage its use as the default. Hope this helps! All the best, Mark

Hi, On Mon, Jan 14, 2002 at 12:39:48AM -0800, Mark P Jones wrote:
Hugs uses single precision by default because the implementation using double precision relies on a hack whose behavior is not assured in any way by the C language in which it is implemented.
I found this in src/unix/configure.in: (all commented out) dnl Disabled for now because the plugin-code can't handle the change. dnl If you're not using plugins, you could turn this on manually dnl by setting "USE_DOUBLE_PRECISION" in options.h.in (before running dnl the configure script). dnl AC_ARG_ENABLE(double-precision, [ --enable-double-precision use double precision arithmetic], AC_DEFINE(USE_DOUBLE_PRECISION)) Could you clarify if this is the `hack' you were referring to? (And are there any more? I can live with it if this is the only disadvantage in enabling double precision support ...) Thanks, /Liyang -- .--| Liyang HU |--| http://nerv.cx/ |--| Caius@Cam |--| ICQ: 39391385 |--. | HELLO KITTY gang terrorizes town, family STICKERED to death! |
participants (5)
-
D. Tweed
-
Liyang Hu
-
Mark P Jones
-
Scott Turner
-
William Lee Irwin III