On May 5, 2009, at 7:03 AM, William Stein wrote: > On Tue, May 5, 2009 at 7:00 AM, Christophe Oosterlynck > <tif...@gmail.com> wrote: >> >> Hi, >> >> I'm writin a Cython module for Sage and at some point I want to >> construct a random matrix with a certain density. But supplying the >> density as a float to the random_matrix function will always become >> 0... >> >> for example >> >> %cython >> from sage.all import random_matrix,GF >> cdef float d >> d = <float>1/562 > > That 1/562 I think is just 0, since integer division is floor division > in C=Cython. > Instead write > > %cython > from sage.all import random_matrix,GF,QQ > cdef float d > d = QQ((1,562))
Or even 1.0/562 will give you what you want. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---