[gambit-list] Big number Bug?

dillo gimp dillogimp at gmail.com
Thu Apr 26 00:36:06 EDT 2007


On 4/26/07, Bradley Lucier <lucier at math.purdue.edu> wrote:
>
> On Apr 25, 2007, at 10:25 PM, dillo gimp wrote:
>
> >
> > On 4/26/07, Bradley Lucier <lucier at math.purdue.edu> wrote:
> >> I hope you don' t mind me CC'ing my reply to th list.
> >>
> >> On Apr 25, 2007, at 9:05 PM, dillo gimp wrote:
> >>
> >> >
> >> >
> >> > On 4/26/07, Bradley Lucier <lucier at math.purdue.edu> wrote:
> >> > On Apr 25, 2007, at 7:43 PM, dillo gimp wrote:
> >> >
> >> > > There might be a bug in big number handling,
> >> > > the same code runs fine under mzscheme and petite, but crashes
> >> with
> >> > > gambit :
> >> > > *** ERROR IN ##ratnum.* -- Divide by zero
> >> > > (quotient 0 0)
> >> > >
> >> > > I don't even use "quotient" in my code.
> >> >
> >> > We'd need to see a bit of your code to figure out what you *are*
> >> > using.
> >> >
> >> >
> >> > I don't know how to make gambit to report exactly where the code
> >> > has crashed.
> >> > The program is not exactly small either.
> >> > Can you tell me how to make gambit report "crash point"?
> >> > This is my compilation steps:
> >> >
> >> > cat /lfs/script/gambit.sh
> >> > #!/bin/bash
> >> > /usr/4.0b22/bin/gsc -prelude '(define (display x) (write x
> >> (current-
> >> > output-port)))' -link $1
> >> > prog=${1%.sc}
> >> > gcc -O2 -fomit-frame-pointer -freg-struct-return \
> >> >      -I/usr/4.0b22/include -L/usr/4.0b22/lib \
> >> >      -D___SINGLE_HOST -o $prog $prog.c ${prog}_.c -lgambc -lm -
> >> ldl -
> >> > lutil
> >>
> >> OK, well I still don't know what you're trying to do, but gambit
> >> requires gcc to use certain flags for to correctly compile gambit-
> >> generated code.  See the options in /usr/4.0b22/bin/
> >>
> >
> > I don't understand. I am following the exact steps from:
> > http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html
> > http://www.iro.umontreal.ca/~gambit/doc/gambit-c_toc.html#TOC17
>
> The documentation is in error.
>
> You are compiling your code with the options
>
> >> > gcc -O2 -fomit-frame-pointer -freg-struct-return \
> >> >      -I/usr/4.0b22/include -L/usr/4.0b22/lib \
> >> >      -D___SINGLE_HOST -o $prog $prog.c ${prog}_.c -lgambc -lm -
> >> ldl -
>
> These options are incorrect.  You can find the correct options on
> your machine in
>
> /usr/4.0b22/bin/gsc-cc-o
>
> which is in the same directory in which you installed gsi and gsc.
>
> This may be causing your specific problem, but I don't know for sure.
>
> > The program only reports:
> > *** ERROR IN ##ratnum.* -- Divide by zero
> > (quotient 0 0)
> >
> > Without a more accurate location, I can't guess what's wrong.
>
> The code for numeric operations is in gambc-4.0b22/lib/_num.scm.
> There you will find
>
> (define-prim (##ratnum.* x y)
>    (let ((p (macro-ratnum-numerator x))
>          (q (macro-ratnum-denominator x))
>          (r (macro-ratnum-numerator y))
>          (s (macro-ratnum-denominator y)))
>      (if (##eq? x y)
>        (macro-ratnum-make (##* p p) (##* q q))     ; already in
> lowest form
>        (let* ((gcd-ps (##gcd p s))
>               (gcd-rq (##gcd r q))
>               (num (##* (##quotient p gcd-ps) (##quotient r gcd-rq)))
>               (den (##* (##quotient q gcd-rq) (##quotient s gcd-ps))))
>          (if (##eq? den 1)
>            num
>            (macro-ratnum-make num den))))))
>
> So, somehow, gcd-ps or gcd-rq is zero.  ##ratnum.* is called only
> from ##*, which is the library primitive for multiplication, and
> ##ratnum.* is only called when one of the arguments of * is a ratnum.
>
> > The program is not big, but not small either, I can't cut and paste.
> >
> > Most importantly: I don't use quotient in my code.
> > There shoudn't have any "divide by zero" code, else it would have
> > crashed with other scheme implementations.

I've followed your instructions:
cat /usr/4.0b22/bin/gsc-cc-o
gcc  -Wall -W -Wno-unused -O1 -fno-math-errno -fschedule-insns2
-fno-trapping-math -fno-strict-aliasing -fwrapv
-fexpensive-optimizations -fforce-addr -fpeephole2 -falign-jumps
-falign-functions -fno-function-cse -fregmove -fgcse-las
-freorder-functions -fcaller-saves -fno-if-conversion2
-foptimize-sibling-calls -fcse-skip-blocks -funit-at-a-time
-finline-functions -fomit-frame-pointer -fPIC -fno-common -mieee-fp
-rdynamic -shared -I${GSC_CC_O_ARG1}include -D___DYNAMIC
-D___SINGLE_HOST -o ${GSC_CC_O_ARG2} $* ${GSC_CC_O_ARG3}
...
I had to modify the options a little bit because there is no shared
library in my installation,
and I don't know why. I simply follow the simplest installation steps.
Anyway, the program is compiled as static and still crashes exactly.
...
gcc  -Wall -W -Wno-unused -O1 -fno-math-errno -fschedule-insns2
-fno-trapping-math \
 -fno-strict-aliasing -fwrapv -fexpensive-optimizations -fforce-addr
-fpeephole2 \
 -falign-jumps -falign-functions -fno-function-cse -fregmove
-fgcse-las -freorder-functions \
 -fcaller-saves -fno-if-conversion2 -foptimize-sibling-calls -fcse-skip-blocks \
 -funit-at-a-time -finline-functions -fomit-frame-pointer -fno-common
-mieee-fp \
 -I/usr/4.0b22/include -L/usr/4.0b22/lib -D___SINGLE_HOST \
 -o $prog $prog.c ${prog}_.c -lgambc -lm -ldl -lutil

The program still carshes without any trace info besides:
*** ERROR IN ##ratnum.* -- Divide by zero
(quotient 0 0)

I've checked the entire program and the only possible divide by zero is
(/ (caar a))
which is the same as (/ 1 something) and can't possibly produce (/ 0 0).
so, I am out of idea to how debug this program.

>
>
>



More information about the Gambit-list mailing list