RE: Double - CDouble, realToFrac doesn't work
| Hmmm, this is a little bit of a dark corner in the H98 report, but there are | probably other people on this list who know better than me. :-] The problem | is that 'realToFrac' is defined as 'fromRational . toRational', so the first | question is: How is 'toRational' supposed to handle NaN? One thing coming to | my mind is '0 :% 0', but this is normally a value which can't be constructed. | So the next question is: Would this be allowed? +Infinity and -Infinity could | be represented similarly then ('1 :% 0' and '(-1) :% 0'), and 'fromRational' | could handle these values specially. But I can't believe that this has been | discussed for the first time. SPJ? Malcolm? I don't recall a discussion about this, and a quick search in my mail archive didn't turn up anything except the enclosed from George Russell. I'm pretty ignorant about the dark corners of numerics, but it does seem bad that passing through Rational loses information. Perhaps the Report should specify normalised representations for +Inf, -Inf and NaN as Rationals (1:%0, -1:%0, and 0:%0 seem like plausible candidates). If someone wants to try this out, and send us a patch for the Rational library, we could incorporate it. And so far as the report goes, perhaps the Errata could contain a note identifying the issue, and suggesting a solution. It's a bit late to *specify* a solution unless we are really sure about it. Simon -Original Message- From: George Russell [mailto:[EMAIL PROTECTED] Sent: 25 February 2000 10:19 To: [EMAIL PROTECTED] Subject: Floating-point nitpicking: floor(Inf) and floor(NaN) floor(Inf) and floor(NaN) do not appear to be defined in Standard Haskell. (They both come down to properFraction which is only defined for Ratio.) This differs from (for example) the Standard ML Basis Library, where it is specified that floor(Int) should raise Overflow and floor(NaN) should raise Domain. Hence Hugs and GHC do different things. Hugs returns floor(Inf) = 0 and floor(NaN) = 0 GHC returns floor(Inf) = very very large integer and floor(NaN) = even larger integer. (This is because the GHC implementation of properFraction simply ignores the case of Inf/NaN and treats the artificially high exponent encoded in those floating-point numbers as if it were a real one.) My own opinion is that Standard ML is right here and that floor(x) should raise an exception (In Haskell terms, fail) when x does not correspond to a real number. | -Original Message- | From: [EMAIL PROTECTED] [mailto:glasgow-haskell-users- | [EMAIL PROTECTED] On Behalf Of Sven Panne | Sent: 08 August 2004 17:02 | To: Hal Daume III | Cc: GHC Users Mailing List; Malcom Wallace | Subject: Re: Double - CDouble, realToFrac doesn't work | | Hal Daume III wrote: | [...] | Prelude Foreign.C (0 :: CDouble) / 0 | NaN | Prelude Foreign.C (0 :: Double) / 0 | NaN | Prelude Foreign.C realToFrac ((0 :: Double) / 0) :: CDouble | -Infinity | | yikes! the NaN got turned into a -Infinity!!! | | aside from manually checking for 'strange' Double/CDouble values and | wrapping realToFrac, is there a better way? also, does this count as a | bug? | | Hmmm, this is a little bit of a dark corner in the H98 report, but there are | probably other people on this list who know better than me. :-] The problem | is that 'realToFrac' is defined as 'fromRational . toRational', so the first | question is: How is 'toRational' supposed to handle NaN? One thing coming to | my mind is '0 :% 0', but this is normally a value which can't be constructed. | So the next question is: Would this be allowed? +Infinity and -Infinity could | be represented similarly then ('1 :% 0' and '(-1) :% 0'), and 'fromRational' | could handle these values specially. But I can't believe that this has been | discussed for the first time. SPJ? Malcolm? | | When you compile the stuff above with optimizations on, you get what you've | expected, thanks to RULES which shortcut the route via Rational completely. | | Cheers, | S. | | ___ | Glasgow-haskell-users mailing list | [EMAIL PROTECTED] | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
GHCI/FFI/GMP/Me madness
Hi all, I recently tried to create a ffi-binding to gmp in ghc, and failed miserably. After a few days of debugging, simplifying the code and tearing my hear out, I'm slightly completely stumped, and crying for help ;) In short: calling gmp-functions from GHCI *with a prompt between* them seems to do Really Bad Things. (read: memory corruption) The long story: --- mpz_t p; str_test() { gmp_printf(%Zd\n, p); } void mpz_new() { mpz_init_set_si(p, 1); } foreign import ccall mpz_new:: IO () foreign import ccall str_test :: IO () Prelude Main mpz_new Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 1 Prelude Main str_test 142833060 Prelude Main str_test 142833060 Using other flags, importing extra modules, using CVS 6.3 (a few weeks old) or not compiling it before loading it in GHCI slightly changes the symptoms (other wrong numbers or make it happen later/earlier) but copypasting the code from main some 10 to 20 times seems to be a sure way to reproduce it. Simply running main doesn't seem to expose the problem. Now of course, GHCI uses Integer-ops during it's REPL, which I suspect is exactly what causes/exposes the problem. Am I doing (Un)Officially Forbidden Things? Is it time for a bug-report? Do I finally have to learn drinking coffee? ;) I'd be delighted to know. The full code is attached. TIA, Remi -- Nobody can be exactly like me. Even I have trouble doing it. .PHONY: clean ghci CC=gcc CFLAGS=-Wall -g GHCFLAGS=util.o -\#include util.h main_src=PrimMpz.hs ghci: util.o ghci $(GHCFLAGS) $(main_src) exe: util.o ghc --make $(GHCFLAGS) $(main_src) util.o: util.c $(CC) $(CFLAGS) -c $ clean: rm -f a.out *.o *.hi {-# OPTIONS -fffi #-} module Main where foreign import ccall mpz_new:: IO () foreign import ccall str_test :: IO () main= do mpz_new str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test str_test #include stdio.h #include util.h mpz_t p; void str_test() { gmp_printf(%Zd\n, p); } void mpz_new() { mpz_init_set_si(p, 1); } #ifndef _UTIL_H #define _UTIL_H #include gmp.h void str_test(); void mpz_new(); #endif /* _UTIL_H */ ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: ghci: catching up with hugs?-)
On 29 July 2004 17:48, Claus Reinke wrote: - especially when working with gui libs, I often find myself wanting to know which instances some type belongs to (as that determines the attributes/properties/etc one may use with that type). Absolutely. This is on my ToDo list, but I haven't got around to it yet. - since ghc now keeps better source location info, how about :find name? Yes, another good suggestion. I don't have the time to tackle these right now, but they're good small projects for anyone looking for something to contribute to GHC. - the :set something command in ghci feeds the ghc command line, but how can I figure out the current settings (especially paths and packages)? This is really a bug - and it's another thing that's been lurking on my ToDo list for a long time. Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: FFI, Ghc and Libs
Title: Nachricht GHCi supports loading .o and .DLL files only, I'm afriad. Although I believe it might be possible to link against .LIB files when linking a standalone binary. Cheers, Simon From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dominik OesterreichSent: 02 August 2004 16:22To: [EMAIL PROTECTED]Subject: FFI, Ghc and Libs Hello, i haveone Problem with ghc (and FFI). I wrote some functions in C and compiled that file. After that I typed: ghci -fffi komplett.obj test.lhs -l apr.lib and got the followingerror meassage: Loading package base ... linking ... done Warning: ignoring unrecognised input 'apr.lib' Loading object (static) kompett.obj ... done Loading object (dynamic) ... failed. Dynamic Linker error message was: addDLL: unknown error Whilst trying to load (dynamic) Directories to search are: C:\ghc\ghc-6.2.1\binghc.exe: user specified .o/.so/.DLL could not be loaded I have to use different Libraries from Subversion (subversion.tigris.org = http://subversion.tigris.org/files/documents/15/14892/svn-win32-1.0.6_dev.zip). Dominik ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: GHCI/FFI/GMP/Me madness
On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. So, in the code below, the global variable 'p' will end up having components pointing into the heap. Which is fine, until a GC occurs and the pointed-to GMP allocated value is eventually stomped on by the storage manager for some other purpose. I'm _guessing_ that's the reason for the behaviour you're seeing. Hm, I _was_ aware of mp_set_memory_functions being used by the RTS. I've seen it often enough in ltrace's ;) It does indeed sound rather plausible (and making big allocations and such does indeed cause it to happen earlier). At which point my next question is: what now? I don't feel really confident about my GHC-hacking skills (huh? skills? where? ;) so does that mean I'm out of luck? *looks* Am I correct that I'd have to copy any GMP-allocated memory to my own memory before returning from C and vice-versa? I hope not :( Happy hacking, Remi 3212th unfinished project Turk -- Nobody can be exactly like me. Even I have trouble doing it. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: GHCI/FFI/GMP/Me madness
On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. What about linking Haskell programs with C libraries that use GMP internally? Can it cause similar problems? Best regards, Tom -- .signature: Too many levels of symbolic links ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: GHCI/FFI/GMP/Me madness
FWIW, I couldn't reproduce this problem on my system (i.e. str_test always printed 1). GHC 6.2.1, libgmp 4.1.3, debian unstable Abe On Mon, 9 Aug 2004 17:57:14 +0200, Remi Turk [EMAIL PROTECTED] wrote: On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote: Hi, please be aware that the RTS uses GMP as well, and upon initialisation it sets GMP's 'memory functions' to allocate memory from the RTS' heap. So, in the code below, the global variable 'p' will end up having components pointing into the heap. Which is fine, until a GC occurs and the pointed-to GMP allocated value is eventually stomped on by the storage manager for some other purpose. I'm _guessing_ that's the reason for the behaviour you're seeing. Hm, I _was_ aware of mp_set_memory_functions being used by the RTS. I've seen it often enough in ltrace's ;) It does indeed sound rather plausible (and making big allocations and such does indeed cause it to happen earlier). At which point my next question is: what now? I don't feel really confident about my GHC-hacking skills (huh? skills? where? ;) so does that mean I'm out of luck? *looks* Am I correct that I'd have to copy any GMP-allocated memory to my own memory before returning from C and vice-versa? I hope not :( Happy hacking, Remi 3212th unfinished project Turk -- Nobody can be exactly like me. Even I have trouble doing it. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: GHCI/FFI/GMP/Me madness
On Mon, Aug 09, 2004 at 01:09:40PM -0400, Abraham Egnor wrote: FWIW, I couldn't reproduce this problem on my system (i.e. str_test always printed 1). GHC 6.2.1, libgmp 4.1.3, debian unstable Abe Same versions here, on an old heavily-patched/FUBAR rock linux 1.4 system. Does the following make any difference? (trying to cause GCing) Haskell/Mpz/weird% make ghci util.o -#include util.h PrimMpz.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.2.1, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help. Loading package base ... linking ... done. Loading object (static) util.o ... done final link ... done Compiling Main ( PrimMpz.hs, interpreted ) Ok, modules loaded: Main. *Main mpz_new *Main sum (replicate (200*1000) 0) 0 *Main str_test 1076535944 *Main Groeten, Remi -- Nobody can be exactly like me. Even I have trouble doing it. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users